Beispiel #1
0
        public static void Game_Over()
        {
            Wait1 = DateTime.Now;
            while (true)
            {
                Wait2 = DateTime.Now;
                if (Wait2.Subtract(Wait1).TotalSeconds > 3)
                {
                    break;
                }
            }
            Console.Clear();
            Console.SetCursorPosition((ScreenWidth) / 2 - 8, (ScreenHeight) / 2 - 10);
            Console.WriteLine("GAME OVER");
            Console.SetCursorPosition((ScreenWidth) / 2 - 8, ((ScreenHeight) / 2) - 9);
            Console.WriteLine($"Final score: {Score}");
            Console.SetCursorPosition((ScreenWidth) / 2 - 8, ((ScreenHeight) / 2) - 8);
            Console.WriteLine($"Total snake length: {Score+StartingSize+1}");


            SnakeBody.Clear();
            Score            = 0;
            GameOver         = false;
            curent_direction = Moving_directions.None;
            SoloGO.SoloGameOver();
        }
Beispiel #2
0
        private static void GetMovementDirection()
        {
            Timer1 = DateTime.Now;

            while (true)
            {
                Timer2 = DateTime.Now;
                if (Timer2.Subtract(Timer1).TotalMilliseconds > timestep)
                {
                    break;
                }
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo keyInfo = Console.ReadKey(true);
                    if (keyInfo.Key.Equals(ConsoleKey.UpArrow) && curent_directionP1 != Moving_directions.Down)
                    {
                        curent_directionP1 = Moving_directions.Up;
                    }
                    else if (keyInfo.Key.Equals(ConsoleKey.RightArrow) && curent_directionP1 != Moving_directions.Left)
                    {
                        curent_directionP1 = Moving_directions.Right;
                    }
                    else if (keyInfo.Key.Equals(ConsoleKey.DownArrow) && curent_directionP1 != Moving_directions.Up)
                    {
                        curent_directionP1 = Moving_directions.Down;
                    }
                    else if (keyInfo.Key.Equals(ConsoleKey.LeftArrow) && curent_directionP1 != Moving_directions.Right)
                    {
                        curent_directionP1 = Moving_directions.Left;
                    }
                    else if (keyInfo.Key.Equals(ConsoleKey.W) && curent_directionP2 != Moving_directions.Down)
                    {
                        curent_directionP2 = Moving_directions.Up;
                    }
                    else if (keyInfo.Key.Equals(ConsoleKey.A) && curent_directionP2 != Moving_directions.Right)
                    {
                        curent_directionP2 = Moving_directions.Left;
                    }
                    else if (keyInfo.Key.Equals(ConsoleKey.S) && curent_directionP2 != Moving_directions.Up)
                    {
                        curent_directionP2 = Moving_directions.Down;
                    }
                    else if (keyInfo.Key.Equals(ConsoleKey.D) && curent_directionP2 != Moving_directions.Left)
                    {
                        curent_directionP2 = Moving_directions.Right;
                    }
                }
            }
        }
Beispiel #3
0
        public static void Game_Over()
        {
            Wait1 = DateTime.Now;
            while (true)
            {
                Wait2 = DateTime.Now;
                if (Wait2.Subtract(Wait1).TotalSeconds > 3)
                {
                    break;
                }
            }
            Console.Clear();
            Console.SetCursorPosition((ScreenWidth) / 2 - 8, (ScreenHeight) / 2 - 10);
            switch (winner)
            {
            case Winner.P1:
                Console.WriteLine("P1 Wins");
                break;

            case Winner.P2:
                Console.WriteLine("P2 Wins");
                break;

            case Winner.Draw:
                Console.WriteLine("It's a DRAW");
                break;
            }
            Console.WriteLine();
            Console.SetCursorPosition((ScreenWidth) / 2 - 28, ((ScreenHeight) / 2) - 9);
            Console.WriteLine(String.Format("{0,-24} | {1,24}", $"P1 final score: {ScoreP1}", $"P2 final score: {ScoreP2}"));
            Console.SetCursorPosition((ScreenWidth) / 2 - 28, ((ScreenHeight) / 2) - 8);
            Console.WriteLine(String.Format("{0,-10} | {1,10}", $"P1 total snake length: {ScoreP1 + StartingSize + 1}", $"P2 total snake length: {ScoreP2 + StartingSize + 1}"));


            SnakeBodyP1.Clear();
            ScoreP1 = 0;
            SnakeBodyP2.Clear();
            ScoreP2            = 0;
            GameOver           = false;
            curent_directionP1 = Moving_directions.Left;
            curent_directionP2 = Moving_directions.Right;
            winner             = Winner.None;
            MultGO.MultiplayerGameOver();
        }
Beispiel #4
0
 private static void GetMovementDirection()
 {
     Timer1     = DateTime.Now;
     KeyPressed = false;
     while (true)
     {
         Timer2 = DateTime.Now;
         if (Timer2.Subtract(Timer1).TotalMilliseconds > timestep)
         {
             break;
         }
         if (Console.KeyAvailable)
         {
             ConsoleKeyInfo keyInfo = Console.ReadKey(true);
             if (keyInfo.Key.Equals(ConsoleKey.UpArrow) && curent_direction != Moving_directions.Down && KeyPressed == false)
             {
                 curent_direction = Moving_directions.Up;
                 KeyPressed       = true;
             }
             else if (keyInfo.Key.Equals(ConsoleKey.RightArrow) && curent_direction != Moving_directions.Left && KeyPressed == false)
             {
                 curent_direction = Moving_directions.Right;
                 KeyPressed       = true;
             }
             else if (keyInfo.Key.Equals(ConsoleKey.DownArrow) && curent_direction != Moving_directions.Up && KeyPressed == false)
             {
                 curent_direction = Moving_directions.Down;
                 KeyPressed       = true;
             }
             else if (keyInfo.Key.Equals(ConsoleKey.LeftArrow) && curent_direction != Moving_directions.Right && KeyPressed == false)
             {
                 curent_direction = Moving_directions.Left;
                 KeyPressed       = true;
             }
         }
     }
 }