Ejemplo n.º 1
0
        public void Play()
        {
            if (settings.AggressiveNPCs)
            {
                validateProvocate += ProvocateNPC;
                validateProvocate += ValidateDirection;
            }
            else
            {
                validateProvocate += ValidateDirection;
            }

            CreateField();
            DrawFiled();

            do
            {
                if (settings.RealTime == false)
                {
                    GetUserInput();
                }
                else
                {
                    Thread.Sleep(1000);
                }

                if (gameFinished == true) // Проверка выхода по Esc
                {
                    CheckGameState();
                    return;
                }

                NextTurn();
                Console.Clear();
                DrawFiled();
                CheckGameState();
            } while (gameFinished == false);
        }
Ejemplo n.º 2
0
        private void GetUserInput()
        {
            ConsoleKeyInfo choice;

            do
            {
                do
                {
                    choice = Console.ReadKey();

                    switch (choice.Key)
                    {
                    case ConsoleKey.DownArrow:
                        player.Direction = DOWN;
                        break;

                    case ConsoleKey.LeftArrow:
                        player.Direction = LEFT;
                        break;

                    case ConsoleKey.RightArrow:
                        player.Direction = RIGHT;
                        break;

                    case ConsoleKey.UpArrow:
                        player.Direction = UP;
                        break;

                    case ConsoleKey.Tab:
                        settings.FogOfWar = !settings.FogOfWar;
                        Console.Clear();
                        DrawFiled();
                        break;

                    case ConsoleKey.F1:
                        if (settings.AggressiveNPCs)
                        {
                            validateProvocate -= ProvocateNPC;
                        }
                        else
                        {
                            validateProvocate -= ValidateDirection;
                            validateProvocate += ProvocateNPC;
                            validateProvocate += ValidateDirection;
                        }
                        settings.AggressiveNPCs = !settings.AggressiveNPCs;
                        break;

                    case ConsoleKey.F2:
                        if (settings.RealTime == false)
                        {
                            getUserInput = new Thread(GetUserInput);
                            getUserInput.Start();
                        }
                        settings.RealTime = !settings.RealTime;
                        return;

                    case ConsoleKey.Escape:
                        gameEnding   = 2;
                        gameFinished = true;
                        break;

                    default:
                        break;
                    }
                } while (choice.Key == ConsoleKey.Tab || choice.Key == ConsoleKey.F1);
            } while (settings.RealTime == true && gameFinished == false);
        }