Example #1
0
 public static void DeleteRow(TetrisGame game, int row)
 {
     for (int i = row; i > 0; i--)
     {
         for (int j = game.deltaX + 1; j < 10 + game.deltaX + 1; j++)
         {
             game.gameField[i, j] = game.gameField[i - 1, j];
             game.colorData[i, j] = game.colorData[i - 1, j];
         }
     }
 }
Example #2
0
        static void Main(string[] args)
        {
            Console.CursorVisible = false;
            TetrisGame game = new TetrisGame();

            game.RePrintGame();
            FigurePosKeyPressed += game.SetNewDirection;
            RotateFigureEvent   += game.RotateFigure;
            Thread keyReader = new Thread(new ThreadStart(KeyReader))
            {
                Name = "KeyPressRegister"
            };

            keyReader.Start();
            game.CreateNextFigure();
            while (true)
            {
                Tick(delay, game);
            }
        }
        public static void Rotate(Figure figure, Rotation direction, TetrisGame game)
        {
            lock (figure)
            {
                Block[,] copy      = (Block[, ])figure.FigureMap.Clone();
                Block[,] futurePos = (Block[, ])figure.FigureMap.Clone();
                switch (direction)
                {
                case Rotation.left:
                {
                    for (int i = 0; i < figure.Size; i++)
                    {
                        for (int j = 0; j < figure.Size; j++)
                        {
                            futurePos[i, j] = copy[figure.Size - 1 - j, i];
                        }
                    }
                    break;
                }

                case Rotation.right:
                {
                    for (int i = figure.Size - 1; i >= 0; i--)
                    {
                        for (int j = figure.Size - 1; j >= 0; j--)
                        {
                            futurePos[i, j] = copy[j, figure.Size - 1 - i];
                        }
                    }
                    break;
                }
                }

                if (!game.HasColision(new Figure(futurePos, figure.Coord, figure.Size)))
                {
                    Printer.PaintFigureBlack(figure);
                    figure.FigureMap = (Block[, ])futurePos.Clone();
                    Printer.PrintFigure(figure);
                }
            }
        }
Example #4
0
        public static void MoveTo(Figure figure, Rotation direction, TetrisGame game)
        {
            lock (figure)
            {
                Figure futurePos = new Figure();
                switch (direction)
                {
                case Rotation.left:
                {
                    futurePos = new Figure(figure.FigureMap, new Point(figure.Coord.X - 1, figure.Coord.Y), figure.Size);
                    break;
                }

                case Rotation.right:
                {
                    futurePos = new Figure(figure.FigureMap, new Point(figure.Coord.X + 1, figure.Coord.Y), figure.Size);
                    break;
                }

                case Rotation.down:
                {
                    futurePos = new Figure(figure.FigureMap, new Point(figure.Coord.X, figure.Coord.Y + 1), figure.Size);
                    break;
                }
                }
                if (!game.HasColision(futurePos))
                {
                    Printer.PaintFigureBlack(figure);
                    figure.Coord = futurePos.Coord;
                    Printer.PrintFigure(figure);
                }
                else if (direction == Rotation.down && game.HasColision(futurePos))
                {
                    game.landed = true;
                }
            }
        }
Example #5
0
        public static void CheckRows(TetrisGame game)
        {
            int multyplayer  = 0;
            int blockcounter = 0;

            for (int i = 0; i < 20; i++)
            {
                blockcounter = 0;
                for (int j = game.deltaX + 1; j < 10 + game.deltaX + 1; j++)
                {
                    if (game.gameField[i, j] == Block.block)
                    {
                        blockcounter++;
                    }
                }
                if (blockcounter == 10)
                {
                    multyplayer += 1;
                    RowHandler.DeleteRow(game, i);
                }
            }
            game.score += game.scoreDelta * multyplayer;
            game.RePrintGame();
        }
Example #6
0
 static void Tick(int delay, TetrisGame game)
 {
     game.NextTick();
     Thread.Sleep(delay);
 }