Exemplo n.º 1
0
        /// <summary>
        /// This method reads a line from screen and pass it to engine to process
        /// </summary>
        /// <param name="line"></param>
        private static void Operate(string line)
        {
            List <string>   commandsInText = new List <string>();
            IEngine         engine         = new PacmanEngine();
            List <ICommand> commands       = new List <ICommand>();

            //Until a report command is not invoked, cursor reads command and adds it to the collection
            while (line.ToUpper() != nameof(Command.REPORT))
            {
                commandsInText.Add(line);
                line = Console.ReadLine();
            }
            //commands collection is passed to parser
            CommandParser commandParser = new ConsoleKeyParser(commandsInText);

            commands.AddRange(commandParser.Parse());

            try
            {
                //Engine performs the manoeuvre and report the final position of Pacman
                Coordinate lastPosition = engine.Manoeuvre(commands);
                Console.WriteLine();
                Console.WriteLine($"Position report: {engine.Report(lastPosition)}", Console.ForegroundColor = ConsoleColor.Green);
                Console.WriteLine();
                Console.ResetColor();
            }
            catch (Exception ex)
            {
                //If an exception occures in the process, it is displayed in the console and user can start over
                Console.WriteLine($"Error :{ex.Message}", Console.ForegroundColor = ConsoleColor.Red);
                Console.WriteLine();
                Console.WriteLine(ex.InnerException);
                Console.ResetColor();
            }
        }
Exemplo n.º 2
0
        public string HandleInput(ConsoleKeyInfo input)
        {
            int number = ConsoleKeyParser.GetIntFromKey(input);

            if (number >= 1 && number <= _availableQuests.Count)
            {
                _data.Player.Quests.Add(_availableQuests[number - 1]);
                _availableQuests.RemoveAt(number - 1);
            }

            if (input.Key == ConsoleKey.C)
            {
                List <Quest> completed = GameStorage.Get().Player.Quests.Where(q => q.IsFinished).ToList();
                if (completed.Count > 0)
                {
                    foreach (Quest q in completed)
                    {
                        GameStorage.Get().Player.TurnInQuest(q);
                    }
                }
                else
                {
                    return("No Completed Quests!");
                }
            }
            return("");
        }
Exemplo n.º 3
0
        public string HandleInput(ConsoleKeyInfo input)
        {
            if (_selectedQuest != null && input.Key == ConsoleKey.X)
            {
                _selectedQuest = null;
            }


            int selection = ConsoleKeyParser.GetIntFromKey(input);

            if (selection >= 1 && selection <= _quests.Count)
            {
                _selectedQuest = _quests[selection - 1];
            }

            return("");
        }