Beispiel #1
0
 internal void InitializeNewGame()
 {
     fallingBlock = FallingBlockGenerator.Generate(RandomEnumGenerator.Generate <BlocksShape>(), new Point(this.GameplayManager.Columns / 2 - 1, -3));
     // The following line is use for debug.
     //fallingBlock = new FallingBlockI(new Point(0, 0), BlockColor.Black);
     MergeBlock = new MergeBlocks();
 }
Beispiel #2
0
 internal void Merge(FallingBlock fallingBlock)
 {
     foreach (Block block in fallingBlock.List)
     {
         this.List.Add(block);
     }
 }
Beispiel #3
0
        public TetrisGame()
        {
            TextureManager  = new TextureManager();
            WindowManager   = new WindowManager();
            GameplayManager = new GameplayManager();
            InputManager    = new InputManager();

            fallingBlock = new FallingBlock();
            MergeBlock   = new MergeBlocks();
        }
Beispiel #4
0
 internal bool Overlapped(FallingBlock fallingBlock)
 {
     foreach (Block block1 in this.List)
     {
         foreach (Block block2 in fallingBlock.List)
         {
             if ((int)block1.Location.X == (int)block2.Location.X && (int)block1.Location.Y == (int)block2.Location.Y)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Beispiel #5
0
        public void Update(KeyboardState keyboardState)
        {
            KeyPress.Update();

            if (this.GameplayManager.GameStarted == true && this.GameplayManager.GamePaused == false)
            {
                if (this.InputManager.SpaceKey.IsPressed())
                {
                    this.GameplayManager.GamePaused = true;
                }
                else if (this.InputManager.LeftKey.IsPressed() && fallingBlock.LeftSideIsFree(MergeBlock))
                {
                    fallingBlock.MoveLeft(1);
                }
                else if (this.InputManager.RightKey.IsPressed() && fallingBlock.RightSideIsFree(MergeBlock))
                {
                    fallingBlock.MoveRight(1);
                }
                else if (this.InputManager.UpKey.IsPressed())
                {
                    fallingBlock.Transform();
                }
                else if (this.InputManager.EnterKey.IsPressed())
                {
                    this.GameplayManager.GameStarted = false;
                }

                fallingBlock.AdjustHorizontalPosition(0, this.GameplayManager.Columns);
                fallingBlock.MoveDown(this.GameplayManager.GameSpeed);


                if (MergeBlock.Overlapped(fallingBlock) || fallingBlock.BelowBottom(GameplayManager.Rows - 1))
                {
                    fallingBlock.MoveBack();
                    MergeBlock.Merge(fallingBlock);
                    fallingBlock = FallingBlockGenerator.Generate(RandomEnumGenerator.Generate <BlocksShape>(), new Point(this.GameplayManager.Columns / 2 - 1, -3));
                    // The following line is use for debug.
                    //fallingBlock = new FallingBlockI(new Point(0, 0), BlockColor.Black);

                    MergeBlock.Collapse(this.GameplayManager.Columns);

                    if (MergeBlock.ReachedLimit())
                    {
                        this.GameplayManager.GameStarted = false;
                    }
                }
            }
            else if (this.GameplayManager.GameStarted == true && this.GameplayManager.GamePaused == true)
            {
                if (this.InputManager.SpaceKey.IsPressed())
                {
                    this.GameplayManager.GamePaused = false;
                }
            }
            else
            {
                if (this.InputManager.EnterKey.IsPressed())
                {
                    this.GameplayManager.GameStarted = true;
                    InitializeNewGame();
                }
            }
        }