Пример #1
0
        private static void Pulse()
        {
            if (Console.KeyAvailable)
            {
                key      = Console.ReadKey();
                keyPulse = true;
            }
            else
            {
                keyPulse = false;
            }

            if (Program.key.Key == ConsoleKey.LeftArrow & !tetrimino.IsSomethLeft() & keyPulse)
            {
                for (int i = 0; i < 4; i++)
                {
                    tetrimino.position[i][1] -= 1;
                }
                Update();
            }
            else if (Program.key.Key == ConsoleKey.RightArrow & !tetrimino.IsSomethRight() & keyPulse)
            {
                for (int i = 0; i < 4; i++)
                {
                    tetrimino.position[i][1] += 1;
                }
                Update();
            }
            if (Program.key.Key == ConsoleKey.DownArrow & keyPulse)
            {
                tetrimino.Solve();
            }
            if (Program.key.Key == ConsoleKey.DownArrow & keyPulse)
            {
                for (; tetrimino.IsSomthBelow() != true;)
                {
                    tetrimino.Solve();
                }
            }
            if (Program.key.Key == ConsoleKey.UpArrow & keyPulse)
            {
                tetrimino.Rotate();
                tetrimino.Update();
            }
        }
Пример #2
0
        public void TryRotate(Tetrimino piece, bool clockwise)
        {
            // Copy Active Piece And Simulate Rotation
            Tetrimino copy = GeneratePiece(piece.GetBlockValue());

            piece.MakeCopy(copy);
            copy.Rotate(clockwise);

            // If Everything Looks Good, Rotate Active Piece
            if (copy.IsInBounds(_tower))
            {
                piece.Rotate(clockwise);
            }
            // If It Doesn't, Try To Apply An Offset To The Rotation
            else
            {
                int rotationOffsetValue = -1;

                while (!copy.IsInBounds(_tower))
                {
                    rotationOffsetValue++;

                    switch (rotationOffsetValue)
                    {
                    case 0:
                        // 1 Space Left
                        copy.MoveLeftRight(-1);
                        break;

                    case 1:
                        // 2 Spaces Left
                        copy.MoveLeftRight(-1);
                        break;

                    case 2:
                        // 1 Space Right
                        copy.MoveLeftRight(3);
                        break;

                    case 3:
                        // 2 Spaces Right
                        copy.MoveLeftRight(1);
                        break;

                    case 4:
                        // 1 Space Down
                        copy.MoveLeftRight(-2);
                        copy.MoveUpDown(1);
                        break;

                    case 5:
                        // 2 Spaces Down
                        copy.MoveUpDown(1);
                        break;

                    default:
                        return;
                    }
                }

                // Rotate And Apply Offset
                piece.Rotate(clockwise);
                switch (rotationOffsetValue)
                {
                case 0:
                    piece.MoveLeftRight(-1);
                    break;

                case 1:
                    piece.MoveLeftRight(-2);
                    break;

                case 2:
                    piece.MoveLeftRight(1);
                    break;

                case 3:
                    piece.MoveLeftRight(2);
                    break;

                case 4:
                    piece.MoveUpDown(1);
                    break;

                case 5:
                    piece.MoveUpDown(2);
                    break;
                }
            }

            _rotateSound.Play();
        }