static void Main(string[] args) { Console.WriteLine("Welcome to Boat Racing!"); Gambler player = new Gambler();//in case user decides to wager money later string userWantsToPlay = "y"; while (userWantsToPlay == "y") { userWantsToPlay = RunTheRace(userWantsToPlay, player); } Console.WriteLine("Okay, thanks for playing!"); }
static string RunTheRace(string userWantsToPlay, Gambler player) { //user selects a boat type to race Console.WriteLine(); string openingPrompt = "\nChoose boats to race:"; string boatChoice = boatChoices[makeSelection.SelectionMenu(boatChoices, openingPrompt) - 1]; /*determines boat selected by calling menu_cli * //sends boatchoices to the menu and returns the index for the boat selected * //string is completed here to set which type of boat is being raced * //actual boats are created below*/ //Create a list to hold boats and their properties /*Build the Boat--right now, builds four boats to race but could be changed to * collect a user input to vary the number of boats to race*/ List <Boat> boatsForRace = CreateTheBoats(boatChoice, boatChoices.Count); //name the boats Console.Write("Would you like to name your boat? (y or n) "); string answer = Console.ReadLine(); if (answer == "y") { boatsForRace[0].Name = makeSelection.UserNamesBoat(); } //name rest of boats NameTheBoats(answer, boatsForRace); //assign horsepower, base movement rate, and captains to engines AssignBoatProperties(boatsForRace); Console.WriteLine("\nBoat Captains improve your boat's speed.\n" + "They are ranked from 1 to 10, 10 being the most experienced"); //show the boat hp, captain, and avg speed Console.WriteLine(DisplayBoatProperties(boatsForRace)); //******************select race course***************************// //choose a course RaceCourse rc = new RaceCourse(); string raceCourseSelectionPrompt = "Choose a race course"; //currently courseSelected is only needed to determine the number of legs and the design of each leg(curve or straight) string courseSelected = rc.RaceCourseChoices()[makeSelection.SelectionMenu(rc.RaceCourseChoices(), raceCourseSelectionPrompt) - 1]; //display the course selected Console.WriteLine("course selected: " + courseSelected); //create race course--changed rc to boatRaceCourse here to read code easier RaceCourse boatRaceCourse = rc; //new RaceCourse(courseSelected);//why create a new object? Try using rc through whole race cycle boatRaceCourse.RaceCourseConditions(); //sets conditions for course displayed below //****************display current conditions on the water******************* DisplayConditionsOnTheWater(boatRaceCourse); //Race Course = leg 1 + leg 2 + leg 3, etc.; number of legs depends on course selected. //build dictionary for holding race simulation results foreach (Boat boat in boatsForRace) { boatRaceCourse.RaceSimResults.Add(boat, 0); } //******************** race simulator ************************************// //needs to call the same process only no results are printed out except the //number of wins each boat has at the end as a percentage boatRaceCourse.RaceSim(boatsForRace, boatRaceCourse, courseSelected, 0, 1000); //ask user who they think will win the race--use the menu_cli object //if user is gambling, they will need to place their wager here. if (player.GambleOnBoats == "y") { player.PlaceWager(); } string simRacePrompt = "\nBased on the results of the simulation, which boat do you think will win the race?"; int boatToWin = makeSelection.SelectionMenu(boatRaceCourse.CreateNamesOfBoatsInRaceList(boatsForRace), simRacePrompt); //handle response from user Console.WriteLine("Ok, " + boatsForRace[boatToWin - 1].Name + " it is. Let's see if you're right."); //initiate race that user picked a winner for boatRaceCourse.RaceSim(boatsForRace, boatRaceCourse, courseSelected, 1, 1); //******************** handle race results *****************************// if (player.GambleOnBoats == "y") { CheckWinnings(boatsForRace, boatRaceCourse, boatToWin, player); } else { CheckRaceResultsForFun(boatsForRace, boatRaceCourse, boatToWin, player); } do { Console.Write("Play Again? (y/n)"); userWantsToPlay = Console.ReadLine().ToLower(); }while (userWantsToPlay != "y" && userWantsToPlay != "n"); return(userWantsToPlay); }
private static void CheckRaceResultsForFun(List <Boat> boatsForRace, RaceCourse boatRaceCourse, int boatToWin, Gambler player) { //check to see if user's boat won if (boatRaceCourse.RaceWinner == boatsForRace[boatToWin - 1].Name) { Console.WriteLine("\nCongratulations! You picked the winner!"); Gambler.StarterWins++; Console.WriteLine("you have " + Gambler.StarterWins + " wins."); if (Gambler.StarterWins == 2) { player.GambleOnBoats = makeSelection.OfferChanceToWager(); if (player.GambleOnBoats == "y") { player.Winnings = 500; Console.WriteLine($"You have ${player.Winnings} to wager on the next race."); } Gambler.StarterWins = 0; } ; } else { Console.WriteLine("\nSorry, the boat you chose, " + boatsForRace[boatToWin - 1].Name + ", lost."); } }
public static void CheckWinnings(List <Boat> boatsForRace, RaceCourse boatRaceCourse, int boatToWin, Gambler player) { Console.WriteLine("\nYou have elected to wager on the boats."); if (boatRaceCourse.RaceWinner == boatsForRace[boatToWin - 1].Name) { player.Payout = (player.Wager * boatsForRace[boatToWin - 1].OddsToWin) - player.Wager; player.Winnings += player.Payout; Console.WriteLine($"\nCongratulations! {boatsForRace[boatToWin - 1].Name} won the race!\n" + $"Your wager of {player.Wager} has won you " + $"{player.Payout}!\nYou now have {player.Winnings}" + " to wager in the next race."); } else { player.Winnings -= player.Wager; Console.WriteLine($"\nSorry, the boat you chose, {boatsForRace[boatToWin - 1].Name}, lost.\n" + $"You lost your wager of {player.Wager}.\nYou now have" + $" {player.Winnings} to wager in the next race"); } }