Example #1
0
        private static void Main(string[] args)
        {
            Debug = args.Contains("debug");
#endif
            Beeper          = new Beeper();
            BackgroundColor = ConsoleColor.Red;
            ForegroundColor = ConsoleColor.Yellow;
            _soundManager   = new SoundManager();
            _soundManager.Init(new Dictionary <string, string>
            {
                { "Intro", "testexetrisathlon.Intro.mp3" },
                { "InGame1", "testexetrisathlon.InGame1.mp3" },
                { "InGame2", "testexetrisathlon.InGame2.mp3" },
                { "GameOver", "testexetrisathlon.GameOver.mp3" }
            });
            SizeSetter.SetWindowSize(42, 29);
            if (Debug)
            {
                SizeSetter.SetWindowSize(50, 40);
            }
            SetCursorPosition(0, 0);
            bool      playing = true;
            GameState state   = GameState.Menu;
            try
            {
                while (playing)
                {
                    switch (state)
                    {
                    case GameState.Menu:
                        Clear();
                        _soundManager.SetCurrent(Intro);
                        DrawSymbol();
                        SetCursorPosition(12, 18);
                        Write("HighScore: " + SettingsMan.HighScore);
                        SetCursorPosition(12, 20);
                        Write("Controls: Space");
                        SetCursorPosition(13, 21);
                        Write("Up, Down, Right");
                        SetCursorPosition(13, 22);
                        Write("Left");
                        SetCursorPosition(12, 24);
                        Write("Press s to start");
                        SetCursorPosition(12, 25);
                        Write("Press x to exit");
                        SetCursorPosition(12, 26);
                        Write("Press v for settings");
                        SetCursorPosition(0, 28);
                        Write("Icon made by Freepik from www.flaticon.com");
                        string tmp = ReadKey(true).KeyChar.ToString().ToLower();
                        switch (tmp)
                        {
                        case "s":
                            state = GameState.Game;
                            Clear();
                            DrawBorder();
                            break;

                        case "x":
                            state = GameState.Exit;
                            break;

                        case "v":
                            SettingsMenu();
                            break;
                        }
                        break;

                    case GameState.Game:
                        _soundManager.SetCurrent(InGame);
                        _dropTimer.Start();
                        SetCursorPosition(25, 0);
                        WriteLine("Level " + _level);
                        SetCursorPosition(25, 1);
                        WriteLine("Score " + _score + "/" + (Math.Pow(_level, 2) * 100));
                        SetCursorPosition(25, 2);
                        WriteLine("LinesCleared " + _linesCleared);
                        SetCursorPosition(25, 4);
                        WriteLine("HighScore " + SettingsMan.HighScore);
                        _nextTet = new Tetrominoe();
                        _tet     = _nextTet;
                        _tet.Spawn();
                        _nextTet = new Tetrominoe();
                        Update();
                        state = GameState.GameOver;
                        break;

                    case GameState.GameOver:
                        SettingsMan.HighScore = _score;
                        _soundManager.SetCurrent(GameOver);
                        string input = "";
                        while (input != "y" && input != "n")
                        {
                            Clear();
                            DrawBorder();
                            Draw();
                            SetCursorPosition(0, 0);
                            WriteLine("┌───────────────────┐");
                            WriteLine("│     Game Over     │");
                            WriteLine("│   Replay? (Y/N)   │");
                            WriteLine("├───────────────────┤");
                            input = ReadKey().KeyChar.ToString().ToLower();
                        }
                        Grid = new int[23, 10];
                        DroppedTetrominoeLocationGrid = new int[23, 10];
                        _dropTimer    = new Stopwatch();
                        _dropRate     = 300;
                        IsDropped     = false;
                        _isKeyPressed = false;
                        _linesCleared = 0;
                        _score        = 0;
                        _level        = 1;
                        GC.Collect();
                        Clear();
                        DrawBorder();
                        state = input == "y" ? GameState.Game : GameState.Menu;
                        break;

                    case GameState.Exit:
                        playing = false;
                        break;

                    default: throw new ArgumentOutOfRangeException();
                    }
                }
            }
            finally
            {
                _soundManager.Dispose();
            }
            BackgroundColor = Colors[0];
            ForegroundColor = Colors[1];
            SetCursorPosition(0, 0);
            Clear();
            Beeper.Dispose();
        }