コード例 #1
0
        /// <summary>
        /// Called when the GameComponent needs to be updated.
        /// Game Board update performs animation on the marbles, checks for cursor
        /// movement. Most of the game logic is here or called from here
        /// </summary>
        /// <param name="gameTime">Current game time</param>
        public override void Update(GameTime gameTime)
        {
            if (gameTime == null)
            {
                return;
            }

            base.Update(gameTime);

            if (!GameOver)
            {
                Marble.UpdateStatic(gameTime);

                foreach (Marble marble in Marbles)
                {
                    if (marble != null)
                    {
                        marble.Update(gameTime);
                    }
                }

                switch (AnimationState)
                {
                case Animation.Breaking:
                {
                    //Fade the score
                    scoreFadeFactor = (float)((gameTime.TotalGameTime -
                                               scoreFadeStart.TotalGameTime).TotalSeconds /
                                              Marble.BreakTime);

                    //Wait until all marbles are broken.
                    bool stillBreaking = false;
                    foreach (Marble marble in Marbles)
                    {
                        if (marble != null)
                        {
                            if (marble.Animation == Animation.Breaking)
                            {
                                stillBreaking = true;
                                break;
                            }
                        }
                    }

                    //Done breaking - do the 'fall' and 'slide'
                    if (!stillBreaking)
                    {
                        FallAndSlide();
                        totalSelected = 0;
                        FindCursorPosition();
                        FindSelectedMarbles();
                        // TODO Sound.Play(SoundEntry.LandMarbles);
                        AnimationState = Animation.None;
                    }
                    break;
                }

                case Animation.None:
                {
                    moveCursor();
                    BreakMarbles(gameTime);
                    break;
                }
                }
            }
        }