示例#1
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();
            }
        }