Exemplo n.º 1
0
            static void InputMonitor(TetrisGame game)
            {
                ConsoleKeyInfo key = Console.ReadKey();

                switch (key.Key)
                {
                case ConsoleKey.DownArrow:
                {
                    game.FallToBottom();
                    break;
                }

                case ConsoleKey.LeftArrow:
                {
                    game.MoveLeft();
                    break;
                }

                case ConsoleKey.RightArrow:
                {
                    game.MoveRight();
                    break;
                }

                case ConsoleKey.Z:
                {
                    game.AntiClockwiseRotate();
                    break;
                }

                case ConsoleKey.X:
                {
                    game.ClockwiseRotate();
                    break;
                }

                case ConsoleKey.UpArrow:
                {
                    game.ClockwiseRotate();
                    break;
                }

                case ConsoleKey.Spacebar:
                {
                    game.Pause();
                    break;
                }

                case ConsoleKey.S:
                {
                    game.Start();
                    break;
                }

                default:
                    break;
                }
            }
Exemplo n.º 2
0
            public static void GameStart()
            {
                Console.WindowHeight = 30;
                TetrisGame game = TetrisGame.Initialize(0);

                while (game.State == TetrisGame.States.Paused && game.State == TetrisGame.States.Playing)
                {
                    InputMonitor(game);
                }
            }
Exemplo n.º 3
0
            static void ConsolePaintBoard(object sender, EventArgs eventArgs)
            {
                TetrisGame game = (TetrisGame)sender;

                Console.Clear();
                StringBuilder builder = new StringBuilder((game.Row * 2) * (game.Column * 2 + 2));

                Color?[,] newBoard       = game.GetBoard();
                Color?[,] nextPieceBoard = game.GetNextPieceBoard();

                builder.Append("┏━");
                for (int X = 0; X < game.Column; X++)
                {
                    builder.Append("━━");
                }
                builder.Append("┓ ");
                builder.Append("Next Piece: ");
                builder.AppendLine();
                for (int Y = game.Row - 1; Y >= 0; Y--)
                {
                    builder.Append("┃ ");
                    for (int X = 0; X < game.Column; X++)
                    {
                        if (newBoard[X, Y] == null)
                        {
                            builder.Append("  ");
                        }
                        else
                        {
                            builder.Append("█");
                        }
                    }
                    builder.Append("┃ ");
                    //PaintEvent Next Piece
                    {
                        if (Y == game.Row - 1)
                        {
                            builder.Append("┏━");
                            for (int X = 0; X < 4; X++)
                            {
                                builder.Append("━━");
                            }
                            builder.Append("┓ ");
                        }
                        else if (game.Row - 1 > Y && Y > game.Row - 6)
                        {
                            builder.Append("┃ ");
                            for (int X = 0; X < 4; X++)
                            {
                                if (nextPieceBoard[X, 5 - game.Row + Y] == null)
                                {
                                    builder.Append("  ");
                                }
                                else
                                {
                                    builder.Append("█");
                                }
                            }
                            builder.Append("┃ ");
                        }
                        else if (Y == game.Row - 6)
                        {
                            builder.Append("┗━");
                            for (int X = 0; X < 4; X++)
                            {
                                builder.Append("━━");
                            }
                            builder.Append("┛ ");
                        }
                        else if (Y == game.Row - 7)
                        {
                            builder.Append($"Scores: {game.Score}");
                        }
                        else if (Y == game.Row - 8)
                        {
                            builder.Append($"Line: {game.EliminatedLine}");
                        }
                        else if (Y == game.Row - 9)
                        {
                            builder.Append($"Mod: {game.Level}");
                        }
                        else if (Y == game.Row - 10)
                        {
                            builder.Append($"Time: {game.PlayingTime}");
                        }
                    }
                    builder.AppendLine();
                }
                builder.Append("┗━");
                for (int X = 0; X < game.Column; X++)
                {
                    builder.Append("━━");
                }
                builder.Append("┛");
                builder.AppendLine();
                Console.WriteLine(builder);
            }