Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- namespace Bandersnatch
- {
- public class Player
- {
- private Stack<int> history;
- private int index;
- private Graph story;
- public Player(Graph story)
- {
- Stack<int> history = new Stack<int>();
- this.story = story;
- this.index = story.GetBegin();
- }
- public void Game()
- {
- int status;
- history.Push(index);
- do
- {
- status = GetNextAction();
- } while (story.GetNode(status).GetType() != NodeType.End);
- Console.WriteLine(story.GetNode(status).GetMessage());
- }
- private int GetInput(ConsoleKeyInfo input, int limit, ref int line)
- {
- if (input.Key == ConsoleKey.UpArrow && line > 1)
- return --line;
- if (input.Key == ConsoleKey.DownArrow && line < limit)
- return ++line;
- if (input.Key == ConsoleKey.Q)
- return -2;
- if (input.Key == ConsoleKey.Enter)
- {
- history.Push(line - 1);
- return line - 1;
- }
- return line;
- }
- private int GetNextAction()
- {
- int i = history.Peek();
- Node actualNode = story.GetNode(i);
- Dictionary<int, string> neighbours = actualNode.GetNeighbours();
- int limit = neighbours.Count;
- int line = 1;
- if (limit == 0)
- return -1;
- ConsoleKeyInfo input;
- do
- {
- Console.WriteLine($"{actualNode.GetMessage()}\n");
- Console.SetCursorPosition(0, line);
- Console.Write('>');
- Console.SetCursorPosition(4, 1);
- foreach (KeyValuePair<int, string> item in neighbours)
- {
- Console.Write(item.Value);
- Console.SetCursorPosition(4, Console.CursorTop + 1);
- }
- input = Console.ReadKey();
- line = GetInput(input, limit, ref line);
- Console.Clear();
- } while (input.Key != ConsoleKey.Q || input.Key != ConsoleKey.Enter);
- return line;
- }
- private void DisplaySave()
- {
- throw new NotImplementedException();
- }
- public bool LoadSave(string save)
- {
- throw new NotImplementedException();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement