Ejemplo n.º 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();
 }
Ejemplo n.º 2
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();
                }
            }
        }