Ejemplo n.º 1
0
        internal void Run()
        {
            GameData.timer.Start();
            Console.Clear();
            TetrisArray.Render();
            MessagesManager.PrintInfoMessages();

            figure.Render();
            figureNext.Render();

            ConsoleKeyInfo pressedChar;

            do
            {
                pressedChar = Console.ReadKey(true);
                switch (pressedChar.Key)
                {
                case ConsoleKey.DownArrow:
                    AfterDownKeyPressed();
                    break;

                case ConsoleKey.LeftArrow:
                    if (figure.CanMoveLeft())
                    {
                        figure.MoveLeft();
                    }
                    break;

                case ConsoleKey.RightArrow:
                    if (figure.CanMoveRight())
                    {
                        figure.MoveRight();
                    }
                    break;

                case ConsoleKey.Spacebar:
                    if (figure.CanRotateRight())
                    {
                        figure.RotateRight();
                    }
                    break;
                }
            } while (pressedChar.Key != ConsoleKey.Escape);

            ShowContinueMenu();
        }
Ejemplo n.º 2
0
        internal bool CanRotateRight(FiguresTypes figureType, FiguresAngle figureAngle, int centerX, int centerY)
        {
            int rowNumber = (int)figureAngle + 1;

            if (rowNumber > 3)
            {
                rowNumber = 0;
            }

            int FigureTypeRowInList = (int)figureType;
            var figure_row          = FigureCoordinates.Coordinates[FigureTypeRowInList][rowNumber];

            int nextX = 88;
            int nextY = 88;

            switch (BoxIndex)
            {
            case 0:
                nextX = centerX + figure_row.Item1.X;
                nextY = centerY + figure_row.Item1.Y;
                break;

            case 1:
                nextX = centerX + figure_row.Item2.X;
                nextY = centerY + figure_row.Item2.Y;
                break;

            case 2:
                nextX = centerX + figure_row.Item3.X;
                nextY = centerY + figure_row.Item3.Y;
                break;

            case 3:
                nextX = centerX + figure_row.Item4.X;
                nextY = centerY + figure_row.Item4.Y;
                break;
            }
            return(TetrisArray.Array2DValue(nextX, nextY) == 0);
        }
Ejemplo n.º 3
0
        internal void AfterDownKeyPressed()
        {
            GameData.timer.Enabled = false;
            while (figure.CanMoveDown())
            {
                figure.MoveDown();
            }
            ;
            figure.MergeWithBottom();
            figure           = new Figure(figureNext.FigureType, figureNext.FigureColor);
            GameData.points += TetrisArray.ClearFilledLines();
            figure.Render();
            figureNext.ClearRender();
            figureNext = new Figure(RandomValue.RandomFigure(), RandomValue.RandomColor(), true);
            figureNext.Render();
            GameData.speed--;
            GameData.points++;
            GameData.figureCount++;
            MessagesManager.PrintInfoMessages();

            GameData.timer.Enabled = true;
        }
Ejemplo n.º 4
0
 internal void TimerTickTock(Object source, System.Timers.ElapsedEventArgs e)
 {
     if (GameData.GameStatus == Status.Play)
     {
         if (figure.CanMoveDown())
         {
             figure.MoveDown();
         }
         else
         {
             if (figure.NotMooved())
             {
                 ShowGameOverMenu();
             }
             figure.MergeWithBottom();
             figure           = new Figure(figureNext.FigureType, figureNext.FigureColor);
             GameData.points += TetrisArray.ClearFilledLines();
             figure.Render();
             figureNext.ClearRender();
             figureNext = new Figure(RandomValue.RandomFigure(), RandomValue.RandomColor(), true);
             figureNext.Render();
             GameData.speed--;
             GameData.points++;
             GameData.figureCount++;
             MessagesManager.PrintInfoMessages();
         }
         if (GameData.figureCount >= GameData.FiguresPerLevel)
         {
             GameData.level++;
             GameData.figureCount = 1;
             GameData.points     += GameData.PointsPerLevel;
         }
         if (GameData.level >= GameData.LevelsCount)
         {
             ShowWinnerMenu();
         }
     }
 }
Ejemplo n.º 5
0
 internal bool CanMoveRight() => TetrisArray.RightArray2DValue(X, Y) == 0;
Ejemplo n.º 6
0
 internal bool CanMoveLeft() => TetrisArray.LeftArray2DValue(X, Y) == 0;
Ejemplo n.º 7
0
 internal bool CanMoveDown() => TetrisArray.DownArray2DValue(X, Y) == 0;
Ejemplo n.º 8
0
 internal void MergeWithBottom()
 {
     TetrisArray.MergeElementWithBottom(X, Y, (int)MyColor);
 }