Пример #1
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;
                }
            }
        }
Пример #2
0
        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);
                }
            }
        }