Esempio n. 1
0
 private bool CanRotate()
 {
     if (TestShape.Shape1 == 'I')
     {
         TestShape.LineRotate();
     }
     else
     {
         TestShape.Rotate();
     }
     for (int i = 0; i < TestShape.ShapeX.Count; i++)
     {
         if ((TestShape.ShapeX[i] > LengthHeight / 2 - 1) || (TestShape.ShapeX[i] < 0) || (TestShape.ShapeY[i] < 0) ||
             (TestShape.ShapeY[i] >= LengthHeight))
         {
             return(false);
         }
         if (board[TestShape.ShapeX[i], TestShape.ShapeY[i]] == CellType.Building)
         {
             return(false);
         }
     }
     TestShape.ShapeX.Clear();
     TestShape.ShapeY.Clear();
     return(true);
 }
Esempio n. 2
0
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if ((e.KeyCode == Keys.A) || (e.KeyCode == Keys.Left))
            {
                xOffset = -1;
                MovingToward();
            }
            if ((e.KeyCode == Keys.D) || (e.KeyCode == Keys.Right))
            {
                xOffset = 1;
                MovingToward();
            }
            xOffset = 0;
            if (e.KeyCode == Keys.S)
            {
                timer1.Interval = 100;
            }

            if (e.KeyCode == Keys.W && (CreatedShape.Shape1 != '.') && (CreatedShape.Shape1 != 'O'))
            {
                CreateTestShape();
                if ((CreatedShape.Shape1 != 'I') && CanRotate())
                {
                    CreatedShape.Rotate();
                }
                if (CreatedShape.Shape1 == 'I' && CanRotate())
                {
                    CreatedShape.LineRotate();
                }
            }

            if (e.KeyCode == Keys.Space)
            {
                timer1.Interval = 10;
            }
            if (e.KeyCode == Keys.Escape)
            {
                if (isPause)
                {
                    timer1.Start();
                    isPause = false;
                }
                else
                {
                    timer1.Stop();
                    isPause = true;
                    for (int j = 0; j < LengthHeight; j++)
                    {
                        Console.WriteLine();
                        for (int i = 0; i < LengthWidth; i++)
                        {
                            if (board[i, j] == CellType.Empty)
                            {
                                Console.Write("0");
                            }
                            if (board[i, j] == CellType.Building)
                            {
                                Console.Write("1");
                            }
                            if (board[i, j] == CellType.Shape)
                            {
                                Console.Write("2");
                            }
                        }
                    }
                }
            }
            canMove = true;
            pictureBox1.Refresh();
        }