예제 #1
0
        public GameOver()
        {
            InitializeComponent();
            IFormatter formatter = new BinaryFormatter();
            Stream     stream    = new FileStream("HighScores.hs", FileMode.Open, FileAccess.Read);

            highScores = (HighScores)formatter.Deserialize(stream);
            stream.Dispose();
            lblScore.Text     += Shapes.score;
            tbxHighScores.Text = highScores.ToString();
        }
        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);
        }
예제 #3
0
        static public void PlayGame()
        {
            Hud.Score = 0;
            level     = 1;
            int dropSpeed = 20;

            isPlaying = true;

            TetrisBlock activeBlock = new TetrisBlock();

            playField = new PlayField();

            Engine.ClearScreen();
            SetCursorPosition(0, 0);

            while (isPlaying)
            {
                tick++;

                KeyInputCheck(activeBlock, playField);

                if (tick % (dropSpeed - level) == 0)
                {
                    activeBlock.YPos++;
                    tick = 0;
                }

                if (playField.CollisionCheck(activeBlock))
                {
                    playField.UpdateField(activeBlock);
                    playField.ScoreCheck();

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

                Hud.DrawHud();
                playField.DrawPlayField(xOffset, yOffset);
                activeBlock.DrawBlock(xOffset + activeBlock.XPos, yOffset + activeBlock.YPos);

                Thread.Sleep(40);
            }

            // remove keyboard input glitch
            Engine.GlitchFix();
        }
예제 #4
0
        static void Main(string[] args)
        {
            bool play = true;

            Console.Title = "Tetris Michiel Van Gasse";
            if (OperatingSystem.IsWindows())             // prevent warning windows only
            {
                Console.SetWindowSize(80, 35);
            }
            Console.CursorVisible = false;             // disable cursor flickering around

            while (play)
            {
                SelectedMenu selectedMenu = MenuSelection();

                switch (selectedMenu)
                {
                case SelectedMenu.StartGame:
                    PlayTetris.PlayGame();
                    break;

                case SelectedMenu.HighScore:
                    HighScores.ShowHighScores();
                    break;

                case SelectedMenu.Controls:
                    Controls.ShowControls();
                    break;

                case SelectedMenu.Credits:
                    Credits.ShowCredits();
                    break;

                case SelectedMenu.Exit:
                    play = false;
                    break;

                default:
                    break;
                }
            }
        }
예제 #5
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;
                    }
                }
            }
        }