// Use this for initialization
 void Start()
 {
     //By checking for null, this only assigns a default if it is not assigned in the inspector. - Moore
     if (currentPlayingState == PlayingStates.Null)
     {
         currentPlayingState = PlayingStates.Playing;
     }
 }
Example #2
0
        /// <summary>
        /// Adds a new card to the hand
        /// Then the hand value is calculated and a Playingstate is set depending on the new hand value
        /// </summary>
        /// <param name="card"></param>
        public void AddCardToHand(Card card)
        {
            hand.Add(card);

            int countHand = GetHandValue();

            if (countHand == PlayingCards.BlackJack)
            {
                PlayingState = PlayingStates.BlackJack;
            }
            else if (countHand > PlayingCards.BlackJack)
            {
                PlayingState = PlayingStates.Thick;
            }
            else
            {
                PlayingState = PlayingStates.Playing;
            }
        }
Example #3
0
        protected override void Update(GameTime gameTime)
        {
            switch (PlayingState)
            {

                case PlayingStates.Playing:

                    timeSinceLastDrop += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    timeSinceLastInput += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    timeSinceLastRotate += (float)gameTime.ElapsedGameTime.TotalSeconds;

                    if (timeSinceLastInput >= minTimeSinceLastInput)
                    {
                        if (Keyboard.GetState().IsKeyDown(Keys.Up))
                        {
                            if (timeSinceLastRotate >= minTimeSinceLastRotate)
                            {
                                gameBoard.currentPiece.rotatePiece();
                                timeSinceLastRotate = 0;
                            }
                        }
                        else if (Keyboard.GetState().IsKeyDown(Keys.Left))
                        {
                            if (gameBoard.currentPiece.CanMove(Directions.Left)) gameBoard.currentPiece.X -= 1;
                        }
                        else if (Keyboard.GetState().IsKeyDown(Keys.Right))
                        {
                            if (gameBoard.currentPiece.CanMove(Directions.Right)) gameBoard.currentPiece.X += 1;
                        }
                        else if (Keyboard.GetState().IsKeyDown(Keys.Down))
                        {
                            while (gameBoard.currentPiece.CanMove(Directions.Down)) { gameBoard.currentPiece.Y += 1; }
                        }
                        timeSinceLastInput = 0f;
                    }

                    if (timeSinceLastDrop >= timeBetweenDrops)
                    {
                        if (gameBoard.currentPiece.CanMove(Directions.Down)) gameBoard.currentPiece.Y += 1;
                        timeSinceLastDrop = 0f;
                    }

                    if (!gameBoard.currentPiece.CanMove(Directions.Down)) lockingTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;

                    if (lockingTimer >= lockingTime)
                    {
                        gameBoard.currentPiece.lockPiece();
                        rowsToRemove = gameBoard.checkRowsForCompleteness();
                        linesCleared += rowsToRemove.Count;
                        if (rowsToRemove.Count > 0)
                        {
                            PlayingState = PlayingStates.Erasing;
                        }
                        else
                        {
                            playerScore += 5 * playerLevel;
                            gameBoard.QueueNextPiece();
                        }
                        lockingTimer = 0;
                    }
                    break;

                case PlayingStates.Erasing:

                    erasingTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;

                    if (erasingTimer >= erasingTime)
                    {
                        rowsToRemove = gameBoard.checkRowsForCompleteness();

                        if (rowsToRemove.Count > 0)
                        {
                            gameBoard.removeRow(rowsToRemove.Dequeue());
                            playerScore += 15 * playerLevel;
                        }
                        else
                        {
                            PlayingState = PlayingStates.Playing;
                            if (linesCleared >= 10)
                            {
                                linesCleared = 0;
                                playerLevel++;
                                timeBetweenDrops -= .05f;
                            }
                            gameBoard.QueueNextPiece();
                        }
                        erasingTimer = 0f;
                    }
                    break;
            }

            base.Update(gameTime);
        }
Example #4
0
        public void Update(float elapsedSeconds)
        {
            switch (PlayingState)
            {

                case PlayingStates.Playing:

                    timeSinceLastDrop += elapsedSeconds;

                    if (timeSinceLastDrop >= timeBetweenDrops)
                    {
                        if (gameBoard.currentPiece.CanMove(Directions.Down)) gameBoard.currentPiece.Y += 1;
                        timeSinceLastDrop = 0f;
                    }

                    if (!gameBoard.currentPiece.CanMove(Directions.Down)) lockingTimer += elapsedSeconds;

                    if (lockingTimer >= lockingTime)
                    {

                        gameBoard.currentPiece.lockPiece();
                        rowsToRemove = gameBoard.checkRowsForCompleteness();
                        linesCleared += rowsToRemove.Count;
                        if (rowsToRemove.Count > 0)
                        {
                            PlayingState = PlayingStates.Erasing;
                        }
                        else
                        {
                            playerScore += 5 * playerLevel;
                            gameBoard.QueueNextPiece();
                        }
                        lockingTimer = 0;
                    }

                    break;

                case PlayingStates.Erasing:

                    erasingTimer += elapsedSeconds;
                    if (erasingTimer >= erasingTime)
                    {
                        rowsToRemove = gameBoard.checkRowsForCompleteness();
                        if (rowsToRemove.Count > 0)
                        {
                            gameBoard.removeRow(rowsToRemove.Dequeue());
                            playerScore += 15 * playerLevel;
                        }
                        else
                        {
                            PlayingState = PlayingStates.Playing;
                            if (linesCleared >= 10)
                            {
                                linesCleared = 0;
                                playerLevel++;
                                timeBetweenDrops -= .05f;
                            }
                            gameBoard.QueueNextPiece();
                        }
                        erasingTimer = 0f;
                    }
                    break;
            }
        }