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."); } }
double ThisLegTime(Boat boat, RaceCourse boatRaceCourse, double currentBoatSpeed, int courseLegType) { double legDistance = courseLegType == 0 ? boatRaceCourse.StraightDistanceOfLeg : CurvedDistanceOfLeg; currentBoatSpeed = courseLegType == 0 ? currentBoatSpeed : currentBoatSpeed += currentBoatSpeed * CurvedLegSpeedEffect(boat); return(Math.Round((legDistance / currentBoatSpeed) / 10, 2)); }
private static void DisplayConditionsOnTheWater(RaceCourse boatRaceCourse) { Console.WriteLine("\nCurrent Conditions on the water"); Console.WriteLine("Current: " + boatRaceCourse.WaterCurrent + "\nChop: " + boatRaceCourse.WaterChop + "\nWind: " + boatRaceCourse.Wind + "\nWind Direction: " + boatRaceCourse.WindDirection + "\nWater Chop: " + boatRaceCourse.WaterChopTextCondition + "\nWater Current Direction: " + boatRaceCourse.WaterCurrentDirection + "\nStarting Direction: " + boatRaceCourse.StartDirection); }
public double CurrentBoatSpeed(RaceCourse boatRaceCourse, int boatDirection, int courseLegType, int i, Boat boat) { double currentBoatSpeed = boat.AverageSpeedInKnots; currentBoatSpeed += Math.Round(boat.AverageSpeedInKnots * (boat.IncreaseBoatSpeed(boat.EngineHorsepower) + boatRaceCourse.CourseLeg(courseLegType, boatDirection, i + 1)), 2); //CourseLeg should be refactored using only necessary varialbles currentBoatSpeed += (currentBoatSpeed * boat.CaptainBonus); //add captain bonus currentBoatSpeed += boat.SpeedAdjustment(currentBoatSpeed, boat.EngineHorsepower); return(currentBoatSpeed); }
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"); } }
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); }
public void RaceSim(List <Boat> boatsForRace, RaceCourse boatRaceCourse, string courseSelected, int simOrActual, int numOfRacesToSim) { for (int a = 0; a < numOfRacesToSim; a++) { RaceWinner = ""; int boatDirection = 0; int x = 0;//how else do I keep conditions for leg from printing only once? //x is a loop counter for each boat; every fourth x = 1 leg //courseLegTypes hold the shape of the course--0 is straight, 1 is a curve/turn List <int> courseLegTypes = new List <int>(); courseLegTypes.AddRange(boatRaceCourse.TypesOfLegsInCourse(courseSelected)); //this list holds the cumulative leg time of the boats List <double> cumulativeLegTimesOfEachBoat = new List <double>(); ClearBoatTimesForNextRace(boatsForRace); for (int i = 0; i < courseLegTypes.Count; i++)//this for loop compiles each leg of the race { if (simOrActual == 1) { Console.WriteLine("\nLeg " + (i + 1) + ": " + (courseLegTypes[i] == 0 ? "straight" : "curve")); } cumulativeLegTimesOfEachBoat.Clear();//needs to be cleared/reset for each leg //boat direction changes with each turn boatDirection = x == 0 ? boatRaceCourse.StartDirection : courseLegTypes[i] == 0?boatDirection : boatRaceCourse.NewLegDirection(boatDirection); foreach (Boat boat in boatsForRace) { double currentBoatSpeed = CurrentBoatSpeed(boatRaceCourse, boatDirection, courseLegTypes[i], i, boat); //time formula for distance traveled in a straight is 100 / currentBoatSpeed //time formula for distance traveled in a curve is 25 / (currentBoatSpeed with adjustment for turn) if (simOrActual == 1 & x % boatsForRace.Count == 0)//prints out wind and water current conditions for each leg { //****condition reports for present leg of race Console.WriteLine("Water Current Report: " + WaterCurrentReport); Console.WriteLine("Wind Report: " + boatRaceCourse.WindReport); //******condition reports //header for leg data Console.WriteLine("\nName\t\tHP\tCapt.\tLg Sp\tLg T\tTot T");//\tPlace\n"); } x++; //leg results double thisLegTime = ThisLegTime(boat, boatRaceCourse, currentBoatSpeed, courseLegTypes[i]); boat.BoatTimeForDistance += thisLegTime; //*******print out results for leg*********************************// //this should be refactored I think; then tests could be run if (simOrActual == 1)//if not a sim { Console.WriteLine(boat.Name + "\t" + boat.EngineHorsepower + "\t" + boat.Captain + "\t" + Math.Round(currentBoatSpeed, 2) + "\t" + thisLegTime + "\t" + Math.Round(boat.BoatTimeForDistance / 10, 2)); //"\t" + boat.AverageSpeedInKnots); } cumulativeLegTimesOfEachBoat.Add(boat.BoatTimeForDistance); }//end of leg List <Boat> boatPositions = new List <Boat>(); boatPositions.AddRange(CalculateBoatPositionsAfterEachLeg(cumulativeLegTimesOfEachBoat, boatsForRace, boatsForRace.Count)); if (simOrActual == 1) { Console.WriteLine("\nPositions after Leg " + (i + 1) + ": 1) " + boatPositions[0].Name + ", 2) " + boatPositions[1].Name + ", 3) " + boatPositions[2].Name + ", 4) " + boatPositions[3].Name); if (i < courseLegTypes.Count - 1) { } } if (i == courseLegTypes.Count - 1) { boatRaceCourse.RaceSimResults[boatPositions[0]] += 1; if (simOrActual == 1) { RaceWinner = boatPositions[0].Name; } } }//end of loop through all legs } if (simOrActual == 0) { Console.WriteLine("\nHere are the results based on a simulation of " + numOfRacesToSim + " races:"); foreach (KeyValuePair <Boat, int> result in boatRaceCourse.RaceSimResults) { double percentageOfVictories = Math.Round(((double)result.Value / numOfRacesToSim) * 100, 0); result.Key.OddsToWin = result.Key.OddsMakingForBoat(percentageOfVictories); Console.WriteLine("\t" + result.Key.Name + ": " + "\t" + result.Value + "\t" + percentageOfVictories + "%" + "\t" + result.Key.OddsToWin + " to 1"); } } }