public string TryTravel(int choice, Ship currentShip, User player, Planet[] planets, WarpSpeed travel) { if (choice == -1) { return("You have decided not to travel."); } int warpSpeed = GetWarpSpeed(currentShip); if (warpSpeed == 0) { return("You have decided not to travel."); } TravelSuccessful(player, currentShip, choice, warpSpeed, planets, travel); return($"You have successfully travelled to {planets[choice].GetPlanetName()}"); }
public UserInterface() { Random rand = new Random(); //create and display story var story = new Story(); //create goods var goods = CreateGoods(); //Create ships var ships = CreateShips(); //Create Planets var planets = CreatePlanets(rand); BuyMenu buyMenu = new BuyMenu(); SellMenu sellMenu = new SellMenu(); BuyShipMenu buyShipMenu = new BuyShipMenu(); TravelMenu travelMenu = new TravelMenu(); travelMenu.CalculateDistanceBetweenPlanets(planets); //Create user Console.Write("\nPlease enter your name: "); var player = new User(Console.ReadLine()); //create warpSpeed var travel = new WarpSpeed(); var currentShip = ships[1]; bool exit; player.SetCurrentPlanet(planets[0]); string exitMessage = ""; do { var goodsQuantity = player.GetCurrentInventoryQuantities(); int choice; Console.Clear(); player.CalculateYears(); exit = CheckExitCondition(player); if (exit) { exitMessage = GetExitMessage(player); break; } if (travelMenu.hasTravelled) { SetRandomGoodsPrice(goods, rand, travelMenu); } do { Console.Clear(); choice = DisplayMainMenu(player, currentShip); } while (choice < -1 || choice > 5 || choice == 0); switch (choice) { case -1: exitMessage = "You have decided to retire."; exit = true; break; case 1: Console.Clear(); buyMenu.DisplayBuyMenu(player, goods); Console.WriteLine(buyMenu.CheckBuy(player, goods)); Console.ReadLine(); break; case 2: Console.Clear(); sellMenu.DisplaySellMenu(player, goods); Console.WriteLine(SellMenu.CheckSell(player, goods, goodsQuantity)); Console.ReadLine(); break; case 3: Console.Clear(); var options = travelMenu.DisplayTravelMenu(player, planets, currentShip); choice = travelMenu.GetPlanetChoice(options); Console.WriteLine(travelMenu.TryTravel(choice, currentShip, player, planets, travel)); Console.ReadLine(); break; case 4: Console.Clear(); buyShipMenu.DisplayBuyShipMenu(player, ships, currentShip); Console.WriteLine(BuyShipMenu.TryBuyShip(player, currentShip, ships)); Console.ReadLine(); break; case 5: Console.Clear(); currentShip.RefuelShip(player, currentShip); break; } } while (exit == false); story.DisplayEnd(player, exitMessage); }
private void TravelSuccessful(User player, Ship currentShip, int choice, int warpSpeed, Planet[] planets, WarpSpeed travel) { player.SetUserTime(travel.GetTimeTravelled( player.GetCurrentPlanet().distanceBetweenPlanets[choice], warpSpeed)); var fuelUsed = (player.GetCurrentPlanet().distanceBetweenPlanets[choice]); currentShip.currentFuelLevel += -fuelUsed; player.SetCurrentPlanet(planets[choice]); hasTravelled = true; }