コード例 #1
0
        private void HandleMissileMovement(Missile missile)
        {
            if (!missile.IsExploded)
            {
                var newLocation = _locationService.GetNewLocation(missile.Location, missile.MoveDirection);

                if (_locationService.IsLocationAvailableForMissile(newLocation) && _field.Bots.All(bot => bot.Location != missile.Location))
                {
                    missile.Location = newLocation;

                    if (!_gameConfig.IsFastMissileModeEnabled || _locationService.IsLocationAvailableForMissile(_locationService.GetNewLocation(newLocation, missile.MoveDirection)))
                    {
                        return;
                    }
                }

                SetExplosion(missile);
            }
        }
コード例 #2
0
ファイル: BotService.cs プロジェクト: kmorcinek/hello_wars
        private RoundPartialHistory PerformMove(TankBlasterBot bot, BotMove move, int roundNumber)
        {
            var actionDescription = move.Direction != null ? "move " + move.Direction.Value : "stay";

            if (move.Action == BotAction.DropBomb)
            {
                _field.Bombs.Add(new Bomb
                {
                    Location            = bot.Location,
                    RoundsUntilExplodes = 5,
                    ExplosionRadius     = CurrentBombBlastRadius(roundNumber)
                });

                actionDescription += " & drop bomb";
            }

            bot.Location      = _locationService.GetNewLocation(bot.Location, move.Direction);
            bot.LastDirection = move.Direction ?? bot.LastDirection;

            if (move.Action == BotAction.FireMissile)
            {
                if (IsMissileAvailable(bot, roundNumber) && _locationService.IsLocationAvailableForMissile(_locationService.GetNewLocation(bot.Location, move.FireDirection)))
                {
                    bot.LastMissileFiredRound = roundNumber;
                    _field.Missiles.Add(new Missile
                    {
                        ExplosionRadius = CurrentMissileBlastRadius(roundNumber),
                        MoveDirection   = move.FireDirection,
                        Location        = _locationService.GetNewLocation(bot.Location, move.FireDirection)
                    });
                    actionDescription += " & fire " + move.FireDirection;
                }
                else
                {
                    actionDescription += " & can't fire " + move.FireDirection;
                }
            }

            return(new RoundPartialHistory
            {
                Caption = string.Format("Round {0} {1}: {2}", roundNumber, bot.Name, actionDescription),
                BoardState = _field.ExportState()
            });
        }