Beispiel #1
0
        public void Update(float elapsedSeconds)
        {
            switch (state)
            {
            case GameState.Ready:
                totalElapsedSeconds += elapsedSeconds;
                if (totalElapsedSeconds > 2)
                {
                    SetState(GameState.Playing);
                }
                break;

            case GameState.Playing:
                switch (substate)
                {
                case GameSubstate.Normal:
                    totalElapsedSeconds += elapsedSeconds;
                    if (player != null)
                    {
                        player.Update(elapsedSeconds);
                    }
                    if (aiPlayer != null)
                    {
                        aiPlayer.Update(elapsedSeconds);
                    }
                    if (food != null)
                    {
                        food.Update(elapsedSeconds);
                    }

                    if (player.IsCollideWith(food))
                    {
                        isPlayerWin = true;
                        SetState(GameState.Finished);
                    }
                    else if (aiPlayer != null && aiPlayer.IsCollideWith(food))
                    {
                        isPlayerWin = false;
                        SetState(GameState.Finished);
                    }

                    if (totalElapsedSeconds > 15.0f)
                    {
                        Random rand = new Random();
                        if (rand.Next(0, 100) % 7 == 0)
                        {
                            Rotate();
                            totalElapsedSeconds = 0;
                        }
                    }
                    break;

                case GameSubstate.Rotating:
                    angle += 5;
                    if (angle >= targetAngle)
                    {
                        angle    = targetAngle;
                        substate = GameSubstate.Normal;
                    }
                    double rad = angle * Math.PI / 180;
                    foreach (UIWall wall in uiWalls)
                    {
                        wall.Rotate(centerPoint, rad, targetAngle, angle >= targetAngle);
                    }
                    uiPlayer.Rotate(centerPoint, rad, targetAngle, angle >= targetAngle);
                    uiAIPlayer.Rotate(centerPoint, rad, targetAngle, angle >= targetAngle);
                    uiFood.Rotate(centerPoint, rad, targetAngle, angle >= targetAngle);
                    if (substate == GameSubstate.Normal)
                    {
                        RotateAll();
                    }
                    break;
                }
                break;

            case GameState.Paused:
                break;

            case GameState.Finished:
                totalElapsedSeconds += elapsedSeconds;
                break;
            }
        }