Beispiel #1
0
        public Board(Grid TetrisGrid)
        {
            Rows = TetrisGrid.RowDefinitions.Count;
            Cols = TetrisGrid.ColumnDefinitions.Count;

            Score       = 0;
            LinesFilled = 0;

            BlockControls = new Label[Cols, Rows];

            for (int i = 0; i < Cols; i++)
            {
                for (int j = 0; j < Rows; j++)
                {
                    BlockControls[i, j]                 = new Label();
                    BlockControls[i, j].Background      = NoBrush;
                    BlockControls[i, j].BorderBrush     = SilverBrush;
                    BlockControls[i, j].BorderThickness = new Thickness(1);
                    Grid.SetRow(BlockControls[i, j], j);
                    Grid.SetColumn(BlockControls[i, j], i);
                    TetrisGrid.Children.Add(BlockControls[i, j]);
                }
            }
            currTetramino = new Tetramino();
            currTetraminoDraw();
        }
Beispiel #2
0
 public void LoadTeramino()
 {
     if (nextTetramino != null)
     {
         currTetramino = nextTetramino;
         currTetraminoDraw();
         nextTetramino = null;
     }
     else
     {
         SpawnTetramino("Random");
         currTetramino = nextTetramino;
         nextTetramino = null;
     }
 }
Beispiel #3
0
        public void CurrTetraminoMovDown()
        {
            Point Position = currTetramino.getCurrPosition();

            Point[] Shape = currTetramino.getCurrShape();
            bool    move  = true;

            currTretaminoErase();

            foreach (Point S in Shape)
            {
                if (((int)(S.Y + Position.Y) + 2 + 1) >= Rows)
                {
                    move = false;
                }

                else if (BlockControls[((int)(S.X + Position.X) + ((Cols / 2) - 1)),
                                       (int)(S.Y + Position.Y) + 2 + 1].Background != NoBrush)
                {
                    move = false;
                }
            }

            if (move)
            {
                currTetramino.movDown();
                currTetraminoDraw();
            }

            else
            {
                currTetraminoDraw();
                CheckRows();

                if ((int)Position.Y == 0)
                {
                    gameOver = true;
                }

                else
                {
                    currTetramino = new Tetramino();
                }
            }
        }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="i">
        /// i is the shape to spawn
        /// 0. I
        /// 1. J
        /// 2. L
        /// 3.[ ]
        /// 4. S
        /// 5. T
        /// 6. Z
        /// </param>
        public void SpawnTetramino(string Shape)
        {
            int i = 0;

            if (Shape == "Random")
            {
                Random rnd = new Random();
                i = rnd.Next(0, 6);
            }
            else
            {
                switch (Shape)
                {
                case "Line":
                    i = 0;
                    break;

                case "J":
                    i = 1;
                    break;

                case "L":
                    i = 2;
                    break;

                case "Square":
                    i = 3;
                    break;

                case "S":
                    i = 4;
                    break;

                case "Tee":
                    i = 5;
                    break;

                case "Z":
                    i = 6;
                    break;
                }
            }
            nextTetramino = new Tetramino(i);
        }