public static void DrawSpaceShipTrajectories(Graphics graphics, GameSession gameSession, SortedDictionary <int, GranularObjectInformation> turnMapInformation, ScreenParameters screenParameters) { var playerSpaceship = gameSession.GetPlayerSpaceShip(); var commands = gameSession.GetSpaceShipCommands(playerSpaceship.Id); foreach (var command in commands) { switch (command.Type) { case CommandTypes.MoveForward: break; case CommandTypes.Fire: break; case CommandTypes.AlignTo: var target = gameSession.GetCelestialObject(command.TargetCelestialObjectId).GetLocation(); var results = Approach.Calculate(playerSpaceship.GetLocation(), target, playerSpaceship.Direction, playerSpaceship.Speed); DrawCurveTrajectory(graphics, results.Trajectory, Color.FromArgb(45, 100, 145), screenParameters); break; case CommandTypes.Orbit: break; } } }
public static void DrawChangeMovementDestination(Graphics graphics, GameSession gameSession, PointF pointInSpace, SortedDictionary <int, GranularObjectInformation> turnMapInformation, int turnStep, ScreenParameters screenParameters) { if (pointInSpace != PointF.Empty) { var playerSpaceship = gameSession.GetPlayerSpaceShip(); var location = GetCurrentLocation(turnMapInformation, playerSpaceship, turnStep, screenParameters.DrawInterval); var results = Approach.Calculate(location, pointInSpace, playerSpaceship.Direction, playerSpaceship.Speed); if (results.IsCorrect) { DrawCurveTrajectory(graphics, results.Trajectory, Color.FromArgb(44, 44, 44), screenParameters, true); } } }
public CommandExecuteResult Execute(GameSession gameSession, Command command) { bool isResume = true; gameSession.AddHistoryMessage($"started.", GetType().Name, true); var spaceShip = gameSession.GetPlayerSpaceShip(); var targetObject = gameSession.GetCelestialObject(command.TargetCelestialObjectId); if (spaceShip == null) { return new CommandExecuteResult { Command = command, IsResume = false } } ; var result = Approach.Calculate(spaceShip.GetLocation(), targetObject.GetLocation(), spaceShip.Direction, spaceShip.Speed, 100); foreach (var mapCelestialObject in gameSession.SpaceMap.CelestialObjects) { if (mapCelestialObject.Id == spaceShip.Id) { if (result.Trajectory.Count > spaceShip.Speed) { mapCelestialObject.Direction = result.Trajectory[spaceShip.Speed].Direction; Logger.Debug($"[{GetType().Name}]\t CommandsExecute AlignTo - {mapCelestialObject.Name} Direction before is {mapCelestialObject.Direction} Direction after {mapCelestialObject.Direction}"); if (result.Trajectory[spaceShip.Speed].Distance < spaceShip.Speed * 2) { isResume = false; Logger.Info($"[{GetType().Name}]\t CommandsExecute AlignTo - {mapCelestialObject.Name} finished. Target location is {targetObject.GetLocation()} current location is {spaceShip.GetLocation()}"); } } } } return(new CommandExecuteResult { Command = command, IsResume = isResume }); } }