Пример #1
0
 private void MoveDown(BlockSlot[,] slots, bool forced)
 {
     for (int i = 0; i < 4; i++)
     {
         for (int j = 0; j < 4; j++)
         {
             if (blocks[i, j] != null)
             {
                 if (position.Y + j == GameArea.HEIGHT - 1)
                 {
                     falling = false;
                     soundControl.PlayTouchGround();
                     if (forced)
                     {
                         soundControl.PlayDropSoft();
                     }
                 }
                 else
                 {
                     if (position.Y + j + 1 >= 0)
                     {
                         if (slots[(int)position.X + i, (int)position.Y + j + 1].Block != null)
                         {
                             if (!slots[(int)position.X + i, (int)position.Y + j + 1].Block.Falling)
                             {
                                 falling = false;
                                 soundControl.PlayTouchGround();
                                 if (forced)
                                 {
                                     soundControl.PlayDropSoft();
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (falling)
     {
         position.Y++;
         if (forced)
         {
             soundControl.PlayMoveTetrimino();
         }
     }
 }
Пример #2
0
        public void Update(GameControl gameControl, GameTime gameTime, KeyboardState keyState, KeyboardState prevKeyState)
        {
            tetrimino.Update(slots, stats, gameTime, keyState, prevKeyState);

            if (!tetrimino.Falling)
            {
                //Game over
                if (tetrimino.Position.Y < 0)
                {
                    gameControl.GameOver();
                }

                //Detach blocks
                foreach (Block block in tetrimino.Blocks)
                {
                    if (block != null)
                    {
                        block.Falling = false;
                    }
                }

                //Clear any complete lines
                int completeLines = 0;
                for (int i = 0; i < HEIGHT; i++)
                {
                    bool completeLine = true;
                    for (int j = 0; j < WIDTH; j++)
                    {
                        if (slots[j, i].Block == null)
                        {
                            completeLine = false;
                            break;
                        }
                    }
                    if (completeLine)
                    {
                        for (int j = 0; j < WIDTH; j++)
                        {
                            slots[j, i].Block = null;
                        }
                        for (int k = 0; k < WIDTH; k++)
                        {
                            for (int l = i - 1; l >= 0; l--)
                            {
                                if (slots[k, l].Block != null)
                                {
                                    if (!slots[k, l].Block.Falling)
                                    {
                                        slots[k, l + 1].Block = slots[k, l].Block;
                                        slots[k, l].Block     = null;
                                    }
                                }
                            }
                        }
                        stats.Goal--;
                        completeLines++;
                    }
                }
                switch (completeLines)
                {
                case 1: { stats.Score += 100; soundControl.PlayClear1(); break; }

                case 2: { stats.Score += 300; soundControl.PlayClear2(); break; }

                case 3: { stats.Score += 500; soundControl.PlayClear3(); break; }

                case 4: { stats.Score += 800; soundControl.PlayClear4(); break; }
                }

                //New tetrimino
                tetrimino = new Tetrimino(next, content, soundControl);
                PrepareNextTetrimino();
                canHold = true;
            }

            //Hold
            if (keyState.IsKeyDown(Keys.LeftShift) && prevKeyState.IsKeyUp(Keys.LeftShift))
            {
                int currentType = tetrimino.Type;
                if (canHold)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        for (int j = 0; j < 4; j++)
                        {
                            if ((int)tetrimino.Position.Y + j >= 0 && (int)tetrimino.Position.X + i >= 0 && (int)tetrimino.Position.X + i < WIDTH && (int)tetrimino.Position.Y + j < HEIGHT)
                            {
                                if (tetrimino.Blocks[i, j] != null)
                                {
                                    slots[(int)tetrimino.Position.X + i, (int)tetrimino.Position.Y + j].Block = null;
                                }
                            }
                        }
                    }
                    if (hold == null)
                    {
                        tetrimino = new Tetrimino(next, content, soundControl);
                        PrepareNextTetrimino();
                    }
                    else
                    {
                        tetrimino = new Tetrimino((int)hold, content, soundControl);
                    }
                    hold = currentType;
                    stats.Hold.Set((int)hold);
                    canHold = false;
                    soundControl.PlayDropSoft();
                }
            }
        }