コード例 #1
0
        public bool Tick()
        {
            _stateMachine.Start();

            _tick.Tick();

            _gameDraw.ClearSprites();
            _scoreAnimation.Tick();
            _invincibleAnimation.Tick();

            Inputs.Invincible.On(() => _invincible = !_invincible);

            Inputs.LevelSkip.On(() => _stateMachine.ChangeState(GameState.Complete));

            _stateMachine
            .OnEntry(GameState.Intro,
                     () => _tick.NextEventAfter(120),
                     StartLevel)
            .During(GameState.Intro,
                    () => _gameDraw.DisplayReadyText(),
                    () => _tick.AtEvent(() => _stateMachine.ChangeState(GameState.StartOfLife))
                    );

            _stateMachine.OnEntry(GameState.StartOfLife, () => _lives--);

            _stateMachine.OnEntry(GameState.NewLevel, StartLevel);

            _stateMachine.During(new [] { GameState.StartOfLife, GameState.NewLevel },
                                 () => _stateMachine.ChangeState(GameState.GetReady));

            _stateMachine.OnEntry(GameState.GetReady,
                                  () => _tick.NextEventAfter(120),
                                  ResetGhostsAndPacMan);

            _stateMachine.During(GameState.GetReady,
                                 () => _gameDraw.ClearReadyText(),
                                 () => _tick.AtEvent(() => _stateMachine.ChangeState(GameState.Playing)),
                                 () => _scatterChase.Reset(_level),
                                 () => _speeds.SetLevel(_level));

            _stateMachine.During(new[] { GameState.Playing, GameState.Frightened },
                                 MainLoop);

            _stateMachine.OnEntry(GameState.Complete,
                                  () => _tick.NextEventAfter(120));

            _stateMachine.During(GameState.Complete,
                                 () => _tick.AtEvent(() => _stateMachine.ChangeState(GameState.Flash)));

            _stateMachine
            .OnEntry(GameState.Flash,
                     () => _tick.NextEventAfter(12),
                     () => { _flashCounter = 0; })
            .During(GameState.Flash,
                    () => _tick.AtEvent(FlashMap));

            _stateMachine
            .OnEntry(GameState.Caught,
                     () => _tick.NextEventAfter(60))
            .During(GameState.Caught,
                    () => _tick.AtEvent(() =>
            {
                _stateMachine.ChangeState(GameState.Dying);
                _pacMan.Die();
            }),
                    () =>
            {
                _powerPillAnimation.Tick();
                DoToGhosts(g => g.Animate());
            }
                    );

            _stateMachine
            .OnEntry(GameState.Dying,
                     () => _tick.NextEventAfter(4 * 60))
            .During(GameState.Dying,
                    () => _pacMan.Animation.Tick(),
                    () => _tick.AtEvent(() =>
            {
                if (_lives > 0)
                {
                    _stateMachine.ChangeState(GameState.StartOfLife);
                    ResetGhostsAndPacMan();
                    _ghostHouse.LifeLost();
                }
                else
                {
                    _stateMachine.ChangeState(GameState.GameOver);
                }
            }));

            _stateMachine
            .OnEntry(GameState.GameOver,
                     () => _tick.NextEventAfter(4 * 60))
            .During(GameState.GameOver,
                    () => _tick.AtEvent(() => { _stateMachine.End(); }));

            Draw();

            return(!_stateMachine.HasEnded);
        }