Skip to content

Commit

Permalink
Merge pull request #49 from mifriis/mifriis/mainmenu
Browse files Browse the repository at this point in the history
bug fix
  • Loading branch information
mifriis authored Sep 13, 2022
2 parents 0cb21dd + 89ec492 commit 9aac630
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 10 deletions.
9 changes: 2 additions & 7 deletions kuiper-game/Services/CaptainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@ public Captain SetupCaptain()
{
ConsoleWriter.Write("Greetings captain, what is your name?");
var name = Console.ReadLine();
var saves = _saveService.LookForSaves(name);
if(saves.Count() > 0)
{
LoadGame(saves.FirstOrDefault());
ConsoleWriter.Write($"Welcome back Captain {_currentCaptain.Name}, you were last seen on {_currentCaptain.LastLoggedIn}!");
return _currentCaptain;
}

_currentCaptain = new Captain(name, DateTime.Now, new Account(100M));
_gameTimeService.RealStartTime = _currentCaptain.StartTime;
_accountService.Account = _currentCaptain.Account;
Expand All @@ -57,6 +51,7 @@ public Captain SetupCaptain()
_currentCaptain.Ship.Modules = new List<IShipModule> { new FuelTank(ModuleSize.Medium),new FuelTank(ModuleSize.Medium) } ;
_currentCaptain.Ship.Refuel(100);
_currentCaptain.Ship.CurrentLocation = _solarSystemService.GetBody("Earth");
_currentCaptain.Ship.Status = ShipStatus.InOrbit;
ConsoleWriter.Write($"Welcome, Captain {name}, you have logged in on {_gameTimeService.Now()}");
return _currentCaptain;
}
Expand Down
10 changes: 7 additions & 3 deletions kuiper-game/Services/ShipService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,15 @@ public SetCourseEvent SetCourse(string destination)
var deltaV = CalculateDeltaVForJourney(celestialBody);
var arrivalTime = _gameTimeService.Now().Add(travelTime);
var gameEvent = new SetCourseEvent() { EventTime = arrivalTime, EventName = "Travel Event", DeltaVSpent = deltaV};
foreach (var currentEvent in _eventService.GameEvents.ToList())

if (_eventService.GameEvents != null)
{
if (currentEvent is SetCourseEvent)
foreach (var currentEvent in _eventService.GameEvents.ToList())
{
_eventService.RemoveEvent(currentEvent);
if (currentEvent is SetCourseEvent)
{
_eventService.RemoveEvent(currentEvent);
}
}
}
_eventService.AddEvent(gameEvent);
Expand Down
2 changes: 2 additions & 0 deletions kuiper-game/Systems/CaptainsConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ private void WriteMainMenu()
{
Console.Clear();
_captainService.SetupCaptain();
shipService.Ship = _captainService.GetCaptain().Ship;

break;
}
Console.Clear();
Expand Down
45 changes: 45 additions & 0 deletions kuiper-tests/Services/ShipServiceShould.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,5 +366,50 @@ public void RemovePreviousDestinationFromGameEventsIfAlreadyEnroute()
eventService.Verify(x => x.RemoveEvent(It.IsAny<IEvent>()), Times.Exactly(1));

}

[Fact]
public void HandleNullGameEventsList()
{
//Arrange
var distance = 245749658; //As calculated by the solarSystemService
var now = DateTime.Now;
var destination = new CelestialBody() { CelestialBodyType = CelestialBodyType.Planet, Name = "Mars" };
var bodies = new List<CelestialBody>() {
destination,
new CelestialBody() { CelestialBodyType = CelestialBodyType.GasGiant, Name = "Jupiter" }
};
var moons = new List<CelestialBody>() {
new CelestialBody() { CelestialBodyType = CelestialBodyType.Moon, Name = "Luna" }
};
var asteroids = new List<Asteroid>()
{

};
var currentLocation = new CelestialBody() { CelestialBodyType = CelestialBodyType.Planet, Name = "Earth" };
var solarSystemService = new Mock<ISolarSystemService>();
var gameTimeService = new Mock<IGameTimeService>();
var eventService = new Mock<IEventService>();

eventService.Setup(x => x.GameEvents).Returns((List<IEvent>)null);
solarSystemService.Setup(x => x.GetBodies()).Returns(bodies);
solarSystemService.Setup(x => x.Asteroids).Returns(asteroids);
solarSystemService.Setup(x => x.GetSatellites(currentLocation)).Returns(moons);
solarSystemService.Setup(x => x.GetBody("Mars")).Returns(destination);
gameTimeService.Setup(u => u.Now()).Returns(now);
solarSystemService.Setup(u => u.GetDistanceInKm(currentLocation, destination)).Returns(distance);
var shipService = new ShipService(solarSystemService.Object, eventService.Object, gameTimeService.Object);
var engine = new ShipEngine(10000,3,1000000,1100000);
var ship = new Ship("The Boolean", engine, 250) { CurrentLocation = currentLocation };
ship.Modules = new List<IShipModule> {new FuelTank(ModuleSize.Medium)};
ship.Refuel(50);
shipService.Ship = ship;
//Act
var gameEvent = shipService.SetCourse(destination.Name);

//Assert
eventService.Verify(x => x.AddEvent(It.IsAny<IEvent>()), Times.Exactly(1));
eventService.Verify(x => x.RemoveEvent(It.IsAny<IEvent>()), Times.Exactly(0));

}
}
}

0 comments on commit 9aac630

Please sign in to comment.