Exemplo n.º 1
0
        public static void PauseGame(Thread GamePlay,
                                     ref bool Quit,
                                     ref Piezas ObPieza)
        {
            ConsoleFunctions.CHAR_INFO[] Buffer     = new ConsoleFunctions.CHAR_INFO[11 * 24];
            ConsoleFunctions.CHAR_INFO[] BufferNext = new ConsoleFunctions.CHAR_INFO[4 * 4];
            GamePlay.Suspend();
            Playground.Pause();
            Buffer        = ConsoleFunctions.ReadConsoleOutput(1, 1, 11, 24);
            BufferNext    = ConsoleFunctions.ReadConsoleOutput(15, 1, 4, 4);
            Console.Title = Console.Title + " (Paused)";
            afliw.Clear(1, 24, 1, 11);
            afliw.Clear(1, 5, 15, 19);
            ConsoleFunctions.WriteConsole(3, 1, (ushort)ConsoleColor.DarkCyan, "Paused");
            for (int i = 0; i < 11; i++)
            {
                Console.MoveBufferArea(3, 1 + i, 6, 1, 3, 2 + i);
                Thread.Sleep(300 / (5 * (i + 1)));
            }
            for (int i = 0; i < 3; i++)
            {
                Console.MoveBufferArea(3, 12 - i, 6, 1, 3, 11 - i);
                Thread.Sleep(30 * (i + 1));
            }
            Thread.Sleep(20);
            for (int i = 0; i < 3; i++)
            {
                Console.MoveBufferArea(3, 9 + i, 6, 1, 3, 10 + i);
                Thread.Sleep(30 * (i + 1));
            }

            int  Option    = 2;
            Menu PauseMenu = new Menu(2, 14, -1, "Gray");

            PauseMenu.AddItem(true, "Continue", "Restart", "Config", "Quit");
            ConsoleFunctions.FlushConsoleInputBuffer();
            do
            {
                Option = PauseMenu.DrawMenu(0);
                switch (Option)
                {
                case 0: UnPauseGame(GamePlay, Buffer, BufferNext); break;

                case 1: UnPauseGame(GamePlay, Buffer, BufferNext); RestartGame(ref ObPieza); break;

                case 2: Options(); break;

                case 3: Quit = true; break;
                }
            }while(Option == 2);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            SetConsoleFont(GetStdHandle(STDOUT_HANDLE), 8);
            bool Quit = false, ShowingScores = false, ShowingAbout = false;

            Console.Title         = "afliw's Tetris";
            Console.CursorVisible = false;
            string[] HighScoresArray = new string[0];
            Sonidos.StopBGM();
            LoadScores(ref HighScoresArray);
            Box    NextPieceBox      = new Box(14, 0, 3, 3);
            bool   Paused            = false;
            Piezas ObPieza           = new Piezas();
            Thread GamePlay          = new Thread(Game);

            Console.Clear();
            Writeafliw();
            WriteInstructions();
            Console.WindowHeight = (int)WindowSize.Regular.Height;
            Console.WindowWidth  = (int)WindowSize.Regular.Width;
            Console.BufferHeight = (int)WindowSize.Regular.Height;
            Console.BufferWidth  = (int)WindowSize.Regular.Width;
            ConsoleFunctions.SetConsoleFont(8);
            Playground.Initialize();
            ObPieza.Initialize();
            NextPieceBox.Draw(0, "Green");

            GamePlay.Start(ObPieza);
            string UserAction = " ";

            do
            {
                if (!Playground.Lose)
                {
                    switch (UserAction = Console.ReadKey(true).Key.ToString())
                    {
                    case "UpArrow": if (ObPieza.Available && !Paused)
                        {
                            ObPieza.RotatePiece();
                        }
                        break;

                    case "DownArrow": if (ObPieza.Available && !Paused)
                        {
                            ObPieza.Fall();
                        }
                        Playground.PointsByFall(); break;

                    case "LeftArrow": if (ObPieza.Available && !Paused)
                        {
                            ObPieza.MoveLeft();
                        }
                        break;

                    case "RightArrow": if (ObPieza.Available && !Paused)
                        {
                            ObPieza.MoveRight();
                        }
                        break;

                    case "Enter": PauseGame(GamePlay, ref Quit, ref ObPieza); break;

                    case "Spacebar":
                        ShowingScores = ShowingScores ? false : true;
                        if (ShowingScores)
                        {
                            ShowScoresTable(HighScoresArray, -1);
                            if (ShowingAbout)
                            {
                                ShowingAbout = false;
                            }
                        }
                        else
                        {
                            SetWindowWidth((int)WindowSize.Regular.Width);
                        }
                        ConsoleFunctions.FlushConsoleInputBuffer();
                        break;

                    case "F1":
                        ShowingAbout = ShowingAbout ? false : true;
                        if (ShowingAbout)
                        {
                            About();
                            if (ShowingScores)
                            {
                                ShowingScores = false;
                            }
                        }
                        else
                        {
                            SetWindowWidth((int)WindowSize.Regular.Width);
                        }
                        ConsoleFunctions.FlushConsoleInputBuffer();
                        break;
                    }
                }
                else
                {
                    int i;
                    for (i = 0; i < HighScoresArray.Length && ConvertScore(HighScoresArray[i]) >= Playground.Score; i++)
                    {
                        ;
                    }
                    if (i < HighScoresArray.Length - 1 || (i == HighScoresArray.Length - 1 && ConvertScore(HighScoresArray[HighScoresArray.Length - 1]) < Playground.Score))
                    {
                        afliw.Clear(0, Console.WindowHeight, 31, Console.WindowWidth);
                        SetWindowWidth((int)WindowSize.SaveScore.Width);
                        string PlayersName;
                        Console.SetCursorPosition(37, 5);
                        Console.ForegroundColor = ConsoleColor.Cyan;
                        Console.Write("CONGRATULATIONS!");
                        Console.ResetColor();
                        Console.SetCursorPosition(35, 6);
                        Console.Write("You've made it in to");
                        Console.SetCursorPosition(34, 7);
                        Console.Write("the top 10 best scores.");
                        InputField getname = new InputField(15, true, true, true, false, false);
                        PlayersName = getname.GetString(33, 9, true, "Name ", true);


                        for (int j = HighScoresArray.Length - 1; j > i; j--)
                        {
                            HighScoresArray[j] = HighScoresArray[j - 1];
                        }
                        HighScoresArray[i] = PlayersName + "|" + Playground.Achivements();
                        SaveScores(ref HighScoresArray);
                        afliw.Clear(0, Console.WindowHeight, 32, Console.WindowWidth);
                        ShowScoresTable(HighScoresArray, i);
                    }
                    Console.SetCursorPosition(4, 8);
                    Console.Write("Play");
                    Console.SetCursorPosition(3, 9);
                    Console.Write("again?");
                    Menu Retry = new Menu(4, 11, -1, "Gray");
                    Retry.AddItem("Yes", "No");
                    if (Retry.DrawMenu(0) == 0)
                    {
                        RestartGame(ref ObPieza);
                    }
                    else
                    {
                        Quit = true;
                    }
                }
            }while(!Quit);
            try
            {
                GamePlay.Abort();
            }
            catch (Exception)
            {
                GamePlay.Resume();
                GamePlay.Abort();
            }
        }