public static SelectedMenu MenuSelection()
        {
            string tetris = @"
  ████████╗|███████╗|████████╗|██████╗ |██╗|███████▓
  ╚▓═██╔░═╝|██╔════╝|╚▓═██╔▒═╝|██╔══██╗|██║|██╔════▒
   ▒ ██║▒  |█████╗  | ▒ ██║░  |██████╔╝|██║|███████░
   ░ ██║░  |██╔══╝  | ░ ██║░  |██╔══██╗|██║|╚════██▒
   ▒ ██║   |███████▓| ▒ ██║   |██║  ██║|██║|███████░
   ░ ╚═╝   |╚▓═════╝| ░ ▓═╝▒  |╚═╝  ╚▓╝|╚░╝|╚═══▓══▒
     ░    ░  | ▒      |   ▒  ░  |      ▒ |   | ▒  ▒  ░  
           |       ░      | ░ ░     | ░    ░ |   |    ░         
           |              |   ░     |        |   |    ░        
                                               
";

            // just add a string to add items to the main menu
            string[] selectMenu = { "Start Game", "High Scores", "Controls", "Credits", "Exit" };
            int      selection  = 0;

            HighScores.GetHighScores();
            ResetColor();
            Engine.ClearScreen();
            Engine.DrawTitle(tetris, 5);

            ConsoleKey keyDown;             // to store the pressed key

            do
            {
                DrawMenu(selection, selectMenu);

                ConsoleKeyInfo keyInfo = ReadKey(true); //get the pressed key
                keyDown = keyInfo.Key;                  //safe the pressed key

                if (keyDown == ConsoleKey.UpArrow || keyDown == ConsoleKey.Z)
                {
                    selection--;
                    if (selection == -1)
                    {
                        selection = selectMenu.Length - 1;
                    }
                }
                if (keyDown == ConsoleKey.DownArrow || keyDown == ConsoleKey.S)
                {
                    selection++;
                    if (selection == selectMenu.Length)
                    {
                        selection = 0;
                    }
                }
            } while (keyDown != ConsoleKey.Enter);

            return((SelectedMenu)selection);
        }
Пример #2
0
        private static void KeyInputCheck(TetrisBlock activeBlock, PlayField playField)
        {
            string pauseText = @"
      ___     |      ___     |      ___     |      ___     |      ___     
     /\--\    |     /\--\    |     /\__\    |     /\--\    |     /\--\    
    /##\--\   |    /##\--\   |    /#/--/    |    /##\--\   |    /##\--\   
   /#/\#\--\  |   /#/\#\--\  |   /#/--/     |   /#/\#\--\  |   /#/\#\--\  
  /##\-\#\--\ |  /##\-\#\--\ |  /#/--/  ___ |  _\#\-\#\--\ |  /##\-\#\--\ 
 /#/\#\-\#\__\| /#/\#\-\#\__\| /#/__/  /\__\| /\-\#\-\#\__\| /#/\#\-\#\__\
 \/__\#\/#/--/| \/__\#\/#/--/| \#\--\ /#/--/| \#\-\#\-\/__/| \#\-\#\-\/__/
      \##/--/ |      \##/--/ |  \#\--/#/--/ |  \#\-\#\__\  |  \#\-\#\__\  
       \/__/  |      /#/--/  |   \#\/#/--/  |   \#\/#/--/  |   \#\-\/__/  
              |     /#/--/   |    \##/--/   |    \##/--/   |    \#\__\    
              |     \/__/    |     \/__/    |     \/__/    |     \/__/    
";

            if (KeyAvailable)
            {
                ConsoleKeyInfo key = ReadKey();

                if (key.Key == ConsoleKey.Escape)
                {
                    isPlaying = false;
                }

                if (key.Key == ConsoleKey.Enter && pauseMenu == false)
                {
                    Engine.ClearScreen();
                    Engine.DrawTitle(pauseText, 10);
                    pauseMenu = true;
                    ReadKey();
                }

                if (key.Key == ConsoleKey.Enter && pauseMenu == true)
                {
                    Engine.ClearScreen();
                    pauseMenu = false;
                }

                if (key.Key == ConsoleKey.RightArrow)
                {
                    if ((activeBlock.XPos < playField.XWith - (activeBlock.Shape.GetLength(1) + 1)))
                    {
                        activeBlock.XPos += 2;
                        if (playField.CollisionCheck(activeBlock))
                        {
                            activeBlock.XPos -= 2;
                        }
                    }
                }

                if (key.Key == ConsoleKey.LeftArrow)
                {
                    if (activeBlock.XPos >= 1)
                    {
                        activeBlock.XPos -= 2;
                        if (playField.CollisionCheck(activeBlock))
                        {
                            activeBlock.XPos += 2;
                        }
                    }
                }

                if (key.Key == ConsoleKey.UpArrow)
                {
                    activeBlock.RotateShape();
                }

                if (key.Key == ConsoleKey.DownArrow)
                {
                    tick = 1;
                    activeBlock.YPos++;
                }

                if (key.Key == ConsoleKey.Spacebar)
                {
                    while (!playField.CollisionCheck(activeBlock))
                    {
                        activeBlock.YPos++;
                        Hud.Score++;
                    }

                    playField.UpdateField(activeBlock);
                    playField.ScoreCheck();

                    // game over
                    if (playField.CollisionCheck(activeBlock))
                    {
                        HighScores.CheckHighScore(Hud.Score);
                        isPlaying = false;
                    }
                }
            }
        }