public void AtBatIN(Player[] players, Pitcher pitcher) { Random rand = new Random(); //print lineup printLineUp(players); //throw pitches until a hit happens while (Outs < 3) { //print scoreboard information PrintOutPut($"Score: {Score}\nOuts: {Outs}\nBalls: {Balls} Strikes: {Strikes}\n{WhoIsOn()}\nBatter: {players[Index].ToString()}"); //get a random number representing pitch power //use the getChances method to return the chances for a strike and a ball based on the pitch power double ballChance; double strikeChance; var pitch = pitcher.Pitch(rand); getChances(pitch, out ballChance, out strikeChance); WriteLine($"Pitch Power = {pitch}\nChance for ball = {ballChance:P}\nChance for Strike = {strikeChance:P}"); //user interaction Write("Swing? (1 = yes/2 = no)"); var swing = char.Parse(ReadLine()); //if the user decided to swing if (swing == '1') { //result of the swing represented by an int variable that will be passed into the swingOutcome Method to determine which actions should execute based on the result var outcome = players[Index].swing(pitch, rand); SwingOutcome(outcome); } //the user did not decide to swing else { //check if the pitch was a ball or a strike //might need to look at this logic in more depth soon if (rand.Next(1, pitch) <= 15) { PrintOutPut("Ball"); Balls++; } else { PrintOutPut("Strike"); Strikes++; } } } PrintOutPut("Inning over"); }
public void atBatSim(Player[] players, Pitcher pitcher) { Random rand = new Random(); while (Outs < 3) { double ballChance; double strikeChance; var pitch = pitcher.Pitch(rand); getChances(pitch, out ballChance, out strikeChance); //logic for if to swing or not here bool swing = strikeChance >= ballChance ? true : false; if (swing) { //result of the swing represented by an int variable that will be passed into the swingOutcome Method to determine which actions should execute based on the result var outcome = players[Index].swing(pitch, rand); SwingOutcomeSim(outcome); } //the user did not decide to swing else { //check if the pitch was a ball or a strike //might need to look at this logic in more depth soon if (rand.Next(1, pitch) <= 15) { Balls++; } else { Strikes++; } } } }