Untitled
unknown
csharp
2 years ago
5.4 kB
1
Indexable
Never
// Written by Derek Wiberg //Section A01 // int pullTotal, negativepullTotal, attempts = 0, ropeInput, totalPullStrength = 0, roundCounter = 0, rightLeprechaunWins = 0, leftLeprechaunWins = 0, neitherLeprechaunWins = 0; string leprechaun1name; string leprechaun2name; string namedRope; const string rope = "~~~~~~~~~~", pit = "1234||7890"; char replay; // logic for first leprechaun string Console.Write("Please enter the string for Leprechaun 1! It must be 3 characters or else! "); leprechaun1name = Console.ReadLine(); while (leprechaun1name.Length != 3) { Console.WriteLine("INVALID ENTRY!!!!!!"); Console.Write("PLease enter a valid length for the poor Leprechaun: "); leprechaun1name = Console.ReadLine(); } //logic for 2nd leprechaun string Console.Write("Thank you! Now for the 2nd Leprechaun, It must be 3 characters or else!: "); leprechaun2name = Console.ReadLine(); while (leprechaun2name.Length != 3) { Console.WriteLine("INVALID ENTRY!!!!!!"); Console.Write("Do you think this is a game!?!?!? Please enter a valid length for the poor second Leprechaun: "); leprechaun2name = Console.ReadLine(); } //logic for string length determination Console.Write("Give me a starting location of leprechaun 2 over 20 or else there shall be no tug of war! "); ropeInput = int.Parse(Console.ReadLine()); while (ropeInput < 20) { Console.WriteLine("Please enter a valid string length "); ropeInput = int.Parse(Console.ReadLine()); } //refresh the screen to move to the game. Console.Clear(); //title screen of the game Console.WriteLine($"PLayer 1: {leprechaun1name}" + $"\nPLayer 2: {leprechaun2name}" + "\n\n\n"); Console.WriteLine(pit.PadLeft(ropeInput)); Console.WriteLine(leprechaun1name.PadLeft(ropeInput-10) + rope + leprechaun2name); Console.WriteLine(pit.PadLeft(ropeInput)); Console.WriteLine("Please Press Enter to Begin"); Console.ReadLine(); // refresh screen for start of real game Console.Clear(); while (attempts <= 10 && totalPullStrength != 5 && totalPullStrength != -5) { /// random gen for lep 1 and 2 /// lep1 is left, lep2 is right /// so minus 2 from 1 should give us the differnce /// from here we use negative integer to mean go to the left, or pull left /// and then positive integer means pull to the right /// tie will mean no movement Console.WriteLine($"PLayer 1: {leprechaun1name}" + $"\nPLayer 2: {leprechaun2name}" + "\n\n\n"); //random number generator logic for the pull strengths Random rnd = new Random(); int lepreachaunAlpha = rnd.Next(1, 5); int lepreachaunOmega = rnd.Next(1, 5); pullTotal = lepreachaunAlpha - lepreachaunOmega; // running counter of the pull strength, if reaches -4 left-chaun wins, if +4 right-chaun wins // also works as the counter for rope animation, totalPullStrength relates to the pit location totalPullStrength = totalPullStrength + pullTotal; Console.WriteLine(totalPullStrength); if (pullTotal < 0) { negativepullTotal = pullTotal * -1; Console.WriteLine($"Leprechaun 1 has pulled {negativepullTotal} to the left! What Majesty! "); } if (pullTotal > 0) { Console.WriteLine($"the leprechaun has pulled {pullTotal} to the right! Splendid!! "); } if (pullTotal == 0) { Console.WriteLine($"It is a tie! They're an even match dont ya see!!!"); } ////some stuff about the rope Console.WriteLine(pit.PadLeft(ropeInput)); Console.WriteLine(leprechaun1name.PadLeft(ropeInput - 10 + totalPullStrength) + rope + leprechaun2name); Console.WriteLine(pit.PadLeft(ropeInput)); /// added button to activate logic Console.WriteLine("Press Enter To pull"); Console.ReadLine(); Console.Clear(); attempts++; ///kill screen controls /* Console.WriteLine($"PLayer 1: {leprechaun1name}" + $"\nPLayer 2: {leprechaun2name}" + "\n\n\n"); Console.WriteLine(pit.PadLeft(ropeInput + totalPullStrength)); Console.WriteLine(rope.PadLeft(ropeInput)); Console.WriteLine(pit.PadLeft(ropeInput + totalPullStrength)); */ if (totalPullStrength == 5) { Console.WriteLine("The Right Leprechaun pulls his brother to his death. what a grim scene. Collect the gold! "); rightLeprechaunWins++; } if (totalPullStrength == -5) { Console.WriteLine("The Left Leprechaun pulls his brother to his death. what a grim scene. Collect the gold! "); leftLeprechaunWins++; } if (attempts == 10 && totalPullStrength > -5 && totalPullStrength < 5) { Console.WriteLine("Neither Leprechaun prevails!"); neitherLeprechaunWins++; } //keeping track of runniNg attempts, clearing screen between each attempt } roundCounter++; Console.WriteLine("Would you like to play again? Y/N"); replay = char.ToUpper(char.Parse(Console.ReadLine())); while (replay == 'Y') { ///loop the game guts again? } if (replay != 'Y') { // prints all the results Console.WriteLine("thanks for playing!" + $" You played {roundCounter} rounds of tug of war"); Console.WriteLine($"Leprechaun 1 won {leftLeprechaunWins} number of times"); Console.WriteLine($"Leprechaun 2 won {rightLeprechaunWins} number of times"); Console.WriteLine($"It was a draw {neitherLeprechaunWins} number of times"); }