Exemple #1
0
        /// <summary>
        /// The in-game loop.
        /// </summary>
        private async Task GameLoopAsync()
        {
            // Score/lives
            Pen = Colors.Blue;
            Print(0, 1, "Score:");
            Print(0, 51, "Lives:");
            Pen = Colors.Cyan;
            Print(0, 8, _score.ToString().PadLeft(5, '0'));
            Print(0, 58, _lives.ToString());

            _forceField.Draw();
            _mothership.Draw();
            _playerShip.Draw();

            // Ground
            Pen = Colors.Yellow;
            for (var c = 0; c < ScreenCols; c++)
            {
                Print(39, c, "¬K");
            }

            if (LastKeyPress == Key.X)
            {
                _state = GameState.PlayerWins;
                _score = -730;
            }

            // Hit test friendly missile, if one is in flight
            if (_playerShip.Missile != null)
            {
                var hitResult = _forceField.HitTest(_playerShip.Missile);
                if (!hitResult.ProjectileStopped)
                {
                    hitResult = _mothership.HitTest(_playerShip.Missile);
                }

                _score += hitResult.Score;
                if (hitResult.ProjectileStopped)
                {
                    _playerShip.StopMissile();
                }

                if (hitResult.HitEnemyReactor)
                {
                    HandlePlayerWins();
                }
            }

            // Hit test enemy bombs
            foreach (var bomb in _mothership.Bombs)
            {
                var hitResult = _playerShip.HitTest(bomb);
                if (hitResult.PlayerHit)
                {
                    await HandlePlayerDeathAsync();

                    break;
                }
            }

            // ************ test - remove **************
            if (LastKeyPress == Key.C)
            {
                HandlePlayerWins();
            }
        }