From 1b1eeb7c18b08f3bd54621816adda40eb467a34a Mon Sep 17 00:00:00 2001 From: Sean Lynch <66145294+MacroScenery@users.noreply.github.com> Date: Sat, 14 May 2022 17:01:20 -0400 Subject: [PATCH 1/8] Removed old 23 program --- 93_23_Matches/csharp/23matches.csproj | 9 - 93_23_Matches/csharp/23matches.sln | 25 --- 93_23_Matches/csharp/Goto.Program.cs | 129 -------------- .../csharp/ObjectOrientedVersion.Program.cs | 161 ------------------ 93_23_Matches/csharp/README.md | 5 - 5 files changed, 329 deletions(-) delete mode 100644 93_23_Matches/csharp/23matches.csproj delete mode 100644 93_23_Matches/csharp/23matches.sln delete mode 100644 93_23_Matches/csharp/Goto.Program.cs delete mode 100644 93_23_Matches/csharp/ObjectOrientedVersion.Program.cs delete mode 100644 93_23_Matches/csharp/README.md diff --git a/93_23_Matches/csharp/23matches.csproj b/93_23_Matches/csharp/23matches.csproj deleted file mode 100644 index 11091f71..00000000 --- a/93_23_Matches/csharp/23matches.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - Exe - netcoreapp3.1 - _23matches - - - diff --git a/93_23_Matches/csharp/23matches.sln b/93_23_Matches/csharp/23matches.sln deleted file mode 100644 index 78fce16e..00000000 --- a/93_23_Matches/csharp/23matches.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.32002.261 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "23matches", "23matches.csproj", "{9DBE7354-0749-4750-9224-5F9F95C64905}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {9DBE7354-0749-4750-9224-5F9F95C64905}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9DBE7354-0749-4750-9224-5F9F95C64905}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9DBE7354-0749-4750-9224-5F9F95C64905}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9DBE7354-0749-4750-9224-5F9F95C64905}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {0A87AE2F-68AC-4354-9C8D-578209D41174} - EndGlobalSection -EndGlobal diff --git a/93_23_Matches/csharp/Goto.Program.cs b/93_23_Matches/csharp/Goto.Program.cs deleted file mode 100644 index e23be8a4..00000000 --- a/93_23_Matches/csharp/Goto.Program.cs +++ /dev/null @@ -1,129 +0,0 @@ -using System; -using System.Threading; - -namespace _23matches -{ - class Program - { - /// - /// Mimics the "goto" version of the original program - /// - /// - static void Main(string[] args) - { - Random random = new Random(); - StartNewGame: - Console.WriteLine("23 MATCHES".PadLeft(31)); - Console.WriteLine("CREATIVE COMPUTING MORRISTOWN, NEW JERSEY".PadLeft(15)); - Console.WriteLine(); - Console.WriteLine(); - Console.WriteLine(); - Console.WriteLine("THIS IS A GAME CALLED '23 MATCHES'."); - Console.WriteLine(); - Console.WriteLine("WHEN IT IS YOUR TURN, YOU MAY TAKE ONE, TWO, OR THREE"); - Console.WriteLine("MATCHES. THE OBJECT OF THE GAME IS NOT TO HAVE TO TAKE"); - Console.WriteLine("THE LAST MATCH."); - Console.WriteLine(); - Console.WriteLine("Input exit to close the program."); - Console.WriteLine("Input cls Screen Clear."); - Console.WriteLine(); - Console.WriteLine(); - Console.WriteLine("LET'S FLIP A COIN TO SEE WHO GOES FIRST."); - Console.WriteLine("IF IT COMES UP HEADS, I WILL WIN THE TOSS."); - Console.WriteLine(); - StartTheGame: - string command; - int N = 23; - int K = 0; - int Q = random.Next(2); - if (Q == 1) - goto ComputerFirst; - else - goto PlayerFirst; - - ComputerFirst: - Console.WriteLine("HEADS! I WIN! HA! HA!"); - Console.WriteLine("PREPARE TO LOSE, MEATBALL-NOSE!!"); - Console.WriteLine(); - int ain = random.Next(1, 3); - Console.WriteLine($"I TAKE {ain} MATCHES"); - N = N - ain; - goto PlayersProceed; - - PlayerFirst: - Console.WriteLine("TAILS! YOU GO FIRST. "); - Console.WriteLine(); - goto PlayersSpeak; - - PlayersProceed: - Console.WriteLine($"THE NUMBER OF MATCHES IS NOW {N}"); - Console.WriteLine(); - Console.WriteLine("YOUR TURN -- YOU MAY TAKE 1, 2 OR 3 MATCHES."); - Console.WriteLine("HOW MANY DO YOU WISH TO REMOVE "); - goto PlayersSpeak; - - PlayersSpeak: - command = Console.ReadLine().ToLower(); - if (command.Equals("exit")) - { - System.Diagnostics.Process tt = System.Diagnostics.Process.GetProcessById(System.Diagnostics.Process.GetCurrentProcess().Id); - tt.Kill(); - } - if (command.Equals("cls")) - { - Console.Clear(); - goto PlayersProceed; - } - try - { - K = Convert.ToInt32(command); - } - catch (System.Exception) - { - goto PlayerInputError; - } - if (K > 3 || K <= 0) - goto PlayerInputError; - N = N - K; - Console.WriteLine($"THERE ARE NOW {N} MATCHES REMAINING."); - if (N == 4 || N == 3 || N == 2) - goto TheComputerSpeaks; - else if (N <= 1) - goto ThePlayerWins; - else - goto TheComputerSpeaks; - - TheComputerSpeaks: - int Z = 4 - K; - Console.WriteLine($"MY TURN ! I REMOVE {Z} MATCHES"); - N = N - Z; - if (N <= 1) - goto TheComputerWins; - else - goto PlayersProceed; - - PlayerInputError: - Console.WriteLine("VERY FUNNY! DUMMY!"); - Console.WriteLine("DO YOU WANT TO PLAY OR GOOF AROUND?"); - Console.WriteLine("NOW, HOW MANY MATCHES DO YOU WANT "); - goto PlayersSpeak; - ThePlayerWins: - Console.WriteLine("YOU WON, FLOPPY EARS !"); - Console.WriteLine("THINK YOU'RE PRETTY SMART !"); - Console.WriteLine("LETS PLAY AGAIN AND I'LL BLOW YOUR SHOES OFF !!"); - Console.WriteLine(); - Console.WriteLine(); - goto StartTheGame; - TheComputerWins: - Console.WriteLine(); - Console.WriteLine("YOU POOR BOOB! YOU TOOK THE LAST MATCH! I GOTCHA!!"); - Console.WriteLine("HA ! HA ! I BEAT YOU !!!"); - Console.WriteLine(); - Console.WriteLine("GOOD BYE LOSER!"); - Console.WriteLine(); - Console.WriteLine(); - goto StartNewGame; - - } - } -} diff --git a/93_23_Matches/csharp/ObjectOrientedVersion.Program.cs b/93_23_Matches/csharp/ObjectOrientedVersion.Program.cs deleted file mode 100644 index 7b88d7b7..00000000 --- a/93_23_Matches/csharp/ObjectOrientedVersion.Program.cs +++ /dev/null @@ -1,161 +0,0 @@ -using System; -using System.Threading; - -namespace _23matches -{ - class ObjectOrientedVersion_Program - { - /// - /// Object-oriented version - /// - /// - static void Main_Two(string[] args) - { - Game game = new Game(); - game.GameRun(); - } - } - public class Game - { - string command; - int N; - int K; - Random random = new Random(); - public void GameRun() - { - StartNewGame(); - StartTheGame(); - } - void StartNewGame() - { - Console.WriteLine("23 MATCHES".PadLeft(31)); - Console.WriteLine("CREATIVE COMPUTING MORRISTOWN, NEW JERSEY".PadLeft(15)); - Console.WriteLine(); - Console.WriteLine(); - Console.WriteLine(); - Console.WriteLine("THIS IS A GAME CALLED '23 MATCHES'."); - Console.WriteLine(); - Console.WriteLine("WHEN IT IS YOUR TURN, YOU MAY TAKE ONE, TWO, OR THREE"); - Console.WriteLine("MATCHES. THE OBJECT OF THE GAME IS NOT TO HAVE TO TAKE"); - Console.WriteLine("THE LAST MATCH."); - Console.WriteLine(); - Console.WriteLine("Input exit to close the program."); - Console.WriteLine("Input cls Screen Clear."); - Console.WriteLine(); - Console.WriteLine(); - Console.WriteLine("LET'S FLIP A COIN TO SEE WHO GOES FIRST."); - Console.WriteLine("IF IT COMES UP HEADS, I WILL WIN THE TOSS."); - Console.WriteLine(); - } - void StartTheGame() - { - N = 23; - K = 0; - int Q = random.Next(2); - if (Q == 1) - ComputerFirst(); - else - { - PlayerFirst(); - } - } - void ComputerFirst() - {//210 - Console.WriteLine("HEADS! I WIN! HA! HA!"); - Console.WriteLine("PREPARE TO LOSE, MEATBALL-NOSE!!"); - Console.WriteLine(); - int ain = random.Next(1, 3); - Console.WriteLine($"I TAKE {ain} MATCHES"); - N = N - ain; - PlayersProceed(); - } - void PlayerFirst() - { - Console.WriteLine("TAILS! YOU GO FIRST. "); - Console.WriteLine(); - PlayersSpeak(); - } - void PlayersProceed() - { - Console.WriteLine($"THE NUMBER OF MATCHES IS NOW {N}"); - Console.WriteLine(); - PlayersSpeak(); - } - void RemindsPlayersToEnter() - { - Console.WriteLine("YOUR TURN -- YOU MAY TAKE 1, 2 OR 3 MATCHES."); - Console.WriteLine("HOW MANY DO YOU WISH TO REMOVE "); - } - void PlayersSpeak() - { - RemindsPlayersToEnter(); - command = Console.ReadLine().ToLower(); - if (command.Equals("exit")) - { - System.Diagnostics.Process tt = System.Diagnostics.Process.GetProcessById(System.Diagnostics.Process.GetCurrentProcess().Id); - tt.Kill(); - } - if (command.Equals("cls")) - { - Console.Clear(); - PlayersSpeak(); - } - try - { - K = Convert.ToInt32(command); - } - catch (System.Exception) - { - PlayerInputError(); - } - if (K > 3 || K <= 0) - PlayerInputError(); - N = N - K; - Console.WriteLine($"THERE ARE NOW {N} MATCHES REMAINING."); - if (N == 4 || N == 3 || N == 2) - TheComputerSpeaks(N); - else if (N <= 1) - ThePlayerWins(); - else - TheComputerSpeaks(4 - K); - - } - void PlayerInputError() - { - Console.WriteLine("VERY FUNNY! DUMMY!"); - Console.WriteLine("DO YOU WANT TO PLAY OR GOOF AROUND?"); - Console.WriteLine("NOW, HOW MANY MATCHES DO YOU WANT "); - PlayersSpeak(); - } - void TheComputerSpeaks(int ain) - { - int Z = ain; - Console.WriteLine($"MY TURN ! I REMOVE {Z} MATCHES");//390 - N = N - Z; - if (N <= 1) - TheComputerWins(); - else - PlayersProceed(); - } - void ThePlayerWins() - { - Console.WriteLine("YOU WON, FLOPPY EARS !"); - Console.WriteLine("THINK YOU'RE PRETTY SMART !"); - Console.WriteLine("LETS PLAY AGAIN AND I'LL BLOW YOUR SHOES OFF !!"); - Console.WriteLine(); - Console.WriteLine(); - StartTheGame(); - } - void TheComputerWins() - { - Console.WriteLine(); - Console.WriteLine("YOU POOR BOOB! YOU TOOK THE LAST MATCH! I GOTCHA!!"); - Console.WriteLine("HA ! HA ! I BEAT YOU !!!"); - Console.WriteLine(); - Console.WriteLine("GOOD BYE LOSER!"); - Console.WriteLine(); - Console.WriteLine(); - GameRun(); - } - } -} diff --git a/93_23_Matches/csharp/README.md b/93_23_Matches/csharp/README.md deleted file mode 100644 index fd759c06..00000000 --- a/93_23_Matches/csharp/README.md +++ /dev/null @@ -1,5 +0,0 @@ -Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html) - -Conversion to [Microsoft C#](https://docs.microsoft.com/en-us/dotnet/csharp/) - -The program is available in two versions, a "goto" version that mimics the original program and an "object-oriented" version. From 1a08141c1a4d2169184b7202557b6e7f8b6c8f9c Mon Sep 17 00:00:00 2001 From: Sean Lynch <66145294+MacroScenery@users.noreply.github.com> Date: Sat, 14 May 2022 17:05:23 -0400 Subject: [PATCH 2/8] created blank code --- 93_23_Matches/csharp/23Matches.cs | 12 ++++++++++++ 93_23_Matches/csharp/csharp.csproj | 10 ++++++++++ 2 files changed, 22 insertions(+) create mode 100644 93_23_Matches/csharp/23Matches.cs create mode 100644 93_23_Matches/csharp/csharp.csproj diff --git a/93_23_Matches/csharp/23Matches.cs b/93_23_Matches/csharp/23Matches.cs new file mode 100644 index 00000000..9785c730 --- /dev/null +++ b/93_23_Matches/csharp/23Matches.cs @@ -0,0 +1,12 @@ +using System; + +namespace Program +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} \ No newline at end of file diff --git a/93_23_Matches/csharp/csharp.csproj b/93_23_Matches/csharp/csharp.csproj new file mode 100644 index 00000000..74abf5c9 --- /dev/null +++ b/93_23_Matches/csharp/csharp.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + From f8d4b8d6ba7f4c0310ec968ff7a592b40a3f25bd Mon Sep 17 00:00:00 2001 From: Sean Lynch <66145294+MacroScenery@users.noreply.github.com> Date: Sat, 14 May 2022 17:45:27 -0400 Subject: [PATCH 3/8] Started work on code --- 93_23_Matches/csharp/23Matches.cs | 52 ++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/93_23_Matches/csharp/23Matches.cs b/93_23_Matches/csharp/23Matches.cs index 9785c730..0982c9fb 100644 --- a/93_23_Matches/csharp/23Matches.cs +++ b/93_23_Matches/csharp/23Matches.cs @@ -6,7 +6,57 @@ namespace Program { static void Main(string[] args) { - Console.WriteLine("Hello World!"); + // Print introduction text + + // Prints the title with 31 spaces placed in front of the text using the PadLeft() string function + Console.WriteLine("23 MATCHES".PadLeft(31)); + Console.WriteLine("CREATIVE COMPUTING MORRISTOWN, NEW JERSEY".PadLeft(15)); + + // Print 3 blank lines with \n escape sequence + Console.Write("\n\n\n"); + Console.WriteLine(" THIS IS A GAME CALLED '23 MATCHES'."); + Console.Write("\n"); + + Console.WriteLine("WHEN IT IS YOUR TURN, YOU MAY TAKE ONE, TWO, OR THREE"); + Console.WriteLine("MATCHES. THE OBJECT OF THE GAME IS NOT TO HAVE TO TAKE"); + Console.WriteLine("THE LAST MATCH."); + Console.Write("\n"); + Console.WriteLine("LET'S FLIP A COIN TO SEE WHO GOES FIRST."); + Console.WriteLine("IF IT COMES UP HEADS, I WILL WIN THE TOSS."); + Console.Write("\n"); + + + int numberOfMatches = 23; + + // Create a random class object to generate the coin toss + Random random = new Random(); + // Generates a random number between 0.0 and 1.0 + // Multiplies that number by 2 and then + // Converts it into an integer giving either a 0 or a 1 + int coinTossResult = (int)(2 * random.NextDouble()); + + if (coinTossResult == 1) + { + Console.WriteLine("TAILS! YOU GO FIRST. "); + Console.Write("\n"); + Game(); + } + else + { + Console.WriteLine("HEADS! I WIN! HA! HA!"); + Console.WriteLine("PREPARE TO LOSE, MEATBALL-NOSE!!"); + Console.Write("\n"); + Console.WriteLine("I TAKE 2 MATCHES"); + numberOfMatches = numberOfMatches - 2; + Game(); + } + } + + static void Game() + { + + } + } } \ No newline at end of file From 570355695d46a8c2090a60a4d3873ab5b9c88849 Mon Sep 17 00:00:00 2001 From: Sean Lynch <66145294+MacroScenery@users.noreply.github.com> Date: Sun, 15 May 2022 10:06:14 -0400 Subject: [PATCH 4/8] Finished draft Code is not fully commented There is an issue of double input if you win the coin toss --- 93_23_Matches/csharp/23Matches.cs | 87 +++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 4 deletions(-) diff --git a/93_23_Matches/csharp/23Matches.cs b/93_23_Matches/csharp/23Matches.cs index 0982c9fb..dbe3dfb0 100644 --- a/93_23_Matches/csharp/23Matches.cs +++ b/93_23_Matches/csharp/23Matches.cs @@ -39,7 +39,7 @@ namespace Program { Console.WriteLine("TAILS! YOU GO FIRST. "); Console.Write("\n"); - Game(); + numberOfMatches = PlayerTurn(numberOfMatches)[0]; } else { @@ -48,14 +48,93 @@ namespace Program Console.Write("\n"); Console.WriteLine("I TAKE 2 MATCHES"); numberOfMatches = numberOfMatches - 2; - Game(); } + do + { + Console.WriteLine("THE NUMBER OF MATCHES IS NOW " + numberOfMatches); + int[] totalNumberAndNumberRemoved = PlayerTurn(numberOfMatches); + numberOfMatches = ComputerTurn(totalNumberAndNumberRemoved); + } while (numberOfMatches > 1); + } - static void Game() - { + static int[] PlayerTurn(int numberOfMatches) + { + Console.WriteLine("YOUR TURN -- YOU MAY TAKE 1, 2, OR 3 MATCHES."); + Console.Write("HOW MANY DO YOU WISH TO REMOVE ?? "); + // Get player input + int numberOfMatchesRemove = ReadPlayerInput(); + // If the input is invalid (not 1, 2, or 3) + // then ask the player to input again + while (numberOfMatchesRemove > 3 || numberOfMatchesRemove <= 0) + { + Console.WriteLine("VERY FUNNY! DUMMY!"); + Console.WriteLine("DO YOU WANT TO PLAY OR GOOF AROUND?"); + Console.Write("NOW, HOW MANY MATCHES DO YOU WANT ??"); + numberOfMatchesRemove = ReadPlayerInput(); + } + + // Remove the player specified number of matches + numberOfMatches = numberOfMatches - numberOfMatchesRemove; + + Console.WriteLine("THE ARE NOW " + numberOfMatches + " MATCHES REMAINING"); + int[] totalNumberAndNumberRemoved = {numberOfMatches, numberOfMatchesRemove}; + return totalNumberAndNumberRemoved; + + } + static int ComputerTurn(int[] totalNumberAndNumberRemoved) + { + int numberOfMatches = totalNumberAndNumberRemoved[0]; + int numberOfMatchesRemovedByPlayer = totalNumberAndNumberRemoved[1]; + + int numberOfMatchesRemovedByComputer = 0; + switch (numberOfMatches) + { + case 4: + numberOfMatchesRemovedByComputer = 3; + break; + case 3: + numberOfMatchesRemovedByComputer = 2; + break; + case 2: + numberOfMatchesRemovedByComputer = 1; + break; + case 1: case 0: + Console.WriteLine("YOU WON, FLOPPY EARS !"); + Console.WriteLine("THING YOU'RE PRETTY SMART !"); + Console.WriteLine("LETS PLAY AGAIN AND I'LL BLOW YOUR SHOES OFF !!"); + break; + default: + numberOfMatchesRemovedByComputer = 4 - numberOfMatchesRemovedByPlayer; + break; + } + + if (numberOfMatchesRemovedByComputer != 0) + { + Console.WriteLine("MY TURN ! I REMOVE " + numberOfMatchesRemovedByComputer + " MATCHES"); + if (numberOfMatches <= 1) + { + Console.Write("\n"); + Console.WriteLine("YOU POOR BOOB! YOU TOOK THE LAST MATCH! I GOTCHA!!"); + Console.WriteLine("HA ! HA ! I BEAT YOU !!!"); + Console.Write("\n"); + Console.WriteLine("GOOD BYE LOSER!"); + } + } + + + + + return numberOfMatches; + } + + static int ReadPlayerInput() + { + // Read user input and convert to integer + int playerInput = Convert.ToInt32(Console.ReadLine()); + return playerInput; } } From 40741f3b75bbfe93951e27a1c971807ee21f97e9 Mon Sep 17 00:00:00 2001 From: Sean Lynch <66145294+MacroScenery@users.noreply.github.com> Date: Sun, 15 May 2022 10:28:38 -0400 Subject: [PATCH 5/8] Fixed code to run with public vars --- 93_23_Matches/csharp/23Matches.cs | 52 +++++++++++++++++-------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/93_23_Matches/csharp/23Matches.cs b/93_23_Matches/csharp/23Matches.cs index dbe3dfb0..28f3d3bb 100644 --- a/93_23_Matches/csharp/23Matches.cs +++ b/93_23_Matches/csharp/23Matches.cs @@ -4,6 +4,9 @@ namespace Program { class Program { + + public static int numberOfMatches; + public static int numberOfMatchesRemovedByPlayer; static void Main(string[] args) { // Print introduction text @@ -26,7 +29,7 @@ namespace Program Console.Write("\n"); - int numberOfMatches = 23; + numberOfMatches = 23; // Create a random class object to generate the coin toss Random random = new Random(); @@ -38,8 +41,7 @@ namespace Program if (coinTossResult == 1) { Console.WriteLine("TAILS! YOU GO FIRST. "); - Console.Write("\n"); - numberOfMatches = PlayerTurn(numberOfMatches)[0]; + PlayerTurn(); } else { @@ -52,42 +54,38 @@ namespace Program do { - Console.WriteLine("THE NUMBER OF MATCHES IS NOW " + numberOfMatches); - int[] totalNumberAndNumberRemoved = PlayerTurn(numberOfMatches); - numberOfMatches = ComputerTurn(totalNumberAndNumberRemoved); + Console.Write("THE NUMBER OF MATCHES IS NOW " + numberOfMatches); + PlayerTurn(); + ComputerTurn(); } while (numberOfMatches > 1); } - static int[] PlayerTurn(int numberOfMatches) + static void PlayerTurn() { + Console.WriteLine("\n"); Console.WriteLine("YOUR TURN -- YOU MAY TAKE 1, 2, OR 3 MATCHES."); Console.Write("HOW MANY DO YOU WISH TO REMOVE ?? "); // Get player input - int numberOfMatchesRemove = ReadPlayerInput(); + numberOfMatchesRemovedByPlayer = ReadPlayerInput(); // If the input is invalid (not 1, 2, or 3) // then ask the player to input again - while (numberOfMatchesRemove > 3 || numberOfMatchesRemove <= 0) + while (numberOfMatchesRemovedByPlayer > 3 || numberOfMatchesRemovedByPlayer <= 0) { Console.WriteLine("VERY FUNNY! DUMMY!"); Console.WriteLine("DO YOU WANT TO PLAY OR GOOF AROUND?"); Console.Write("NOW, HOW MANY MATCHES DO YOU WANT ??"); - numberOfMatchesRemove = ReadPlayerInput(); + numberOfMatchesRemovedByPlayer = ReadPlayerInput(); } // Remove the player specified number of matches - numberOfMatches = numberOfMatches - numberOfMatchesRemove; + numberOfMatches = numberOfMatches - numberOfMatchesRemovedByPlayer; - Console.WriteLine("THE ARE NOW " + numberOfMatches + " MATCHES REMAINING"); - int[] totalNumberAndNumberRemoved = {numberOfMatches, numberOfMatchesRemove}; - return totalNumberAndNumberRemoved; - + Console.WriteLine("THE ARE NOW " + numberOfMatches + " MATCHES REMAINING"); } - static int ComputerTurn(int[] totalNumberAndNumberRemoved) + static void ComputerTurn() { - int numberOfMatches = totalNumberAndNumberRemoved[0]; - int numberOfMatchesRemovedByPlayer = totalNumberAndNumberRemoved[1]; int numberOfMatchesRemovedByComputer = 0; switch (numberOfMatches) @@ -114,6 +112,7 @@ namespace Program if (numberOfMatchesRemovedByComputer != 0) { Console.WriteLine("MY TURN ! I REMOVE " + numberOfMatchesRemovedByComputer + " MATCHES"); + numberOfMatches = numberOfMatches - numberOfMatchesRemovedByComputer; if (numberOfMatches <= 1) { Console.Write("\n"); @@ -123,17 +122,22 @@ namespace Program Console.WriteLine("GOOD BYE LOSER!"); } } - - - - - return numberOfMatches; } static int ReadPlayerInput() { // Read user input and convert to integer - int playerInput = Convert.ToInt32(Console.ReadLine()); + int playerInput = 0; + try + { + playerInput = Convert.ToInt32(Console.ReadLine()); + } + catch (System.Exception) + { + Console.WriteLine("?REENTER"); + Console.Write("?? "); + playerInput = ReadPlayerInput(); + } return playerInput; } From 363a216a9e8b8543e994b1c6d3a4a737a6a6640f Mon Sep 17 00:00:00 2001 From: Sean Lynch <66145294+MacroScenery@users.noreply.github.com> Date: Sun, 15 May 2022 10:34:23 -0400 Subject: [PATCH 6/8] fixed double input bug --- 93_23_Matches/csharp/23Matches.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/93_23_Matches/csharp/23Matches.cs b/93_23_Matches/csharp/23Matches.cs index 28f3d3bb..8a839d23 100644 --- a/93_23_Matches/csharp/23Matches.cs +++ b/93_23_Matches/csharp/23Matches.cs @@ -7,6 +7,7 @@ namespace Program public static int numberOfMatches; public static int numberOfMatchesRemovedByPlayer; + public static bool playerGoesFirst = false; static void Main(string[] args) { // Print introduction text @@ -41,6 +42,7 @@ namespace Program if (coinTossResult == 1) { Console.WriteLine("TAILS! YOU GO FIRST. "); + playerGoesFirst = true; PlayerTurn(); } else @@ -54,8 +56,12 @@ namespace Program do { - Console.Write("THE NUMBER OF MATCHES IS NOW " + numberOfMatches); - PlayerTurn(); + if (playerGoesFirst == false) + { + Console.Write("THE NUMBER OF MATCHES IS NOW " + numberOfMatches); + PlayerTurn(); + } + playerGoesFirst = false; ComputerTurn(); } while (numberOfMatches > 1); From 823cd56686a35bba282fd4eb0803b0e40f8347c3 Mon Sep 17 00:00:00 2001 From: Sean Lynch <66145294+MacroScenery@users.noreply.github.com> Date: Sun, 15 May 2022 10:51:24 -0400 Subject: [PATCH 7/8] Add comments --- 93_23_Matches/csharp/23Matches.cs | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/93_23_Matches/csharp/23Matches.cs b/93_23_Matches/csharp/23Matches.cs index 8a839d23..87d7b855 100644 --- a/93_23_Matches/csharp/23Matches.cs +++ b/93_23_Matches/csharp/23Matches.cs @@ -5,9 +5,10 @@ namespace Program class Program { + // Initialize 3 public variables so that they can be ascessed anywhere in the code public static int numberOfMatches; public static int numberOfMatchesRemovedByPlayer; - public static bool playerGoesFirst = false; + public static bool playerGoesFirst = false; // a flag to show if the player won the coin toss static void Main(string[] args) { // Print introduction text @@ -29,7 +30,7 @@ namespace Program Console.WriteLine("IF IT COMES UP HEADS, I WILL WIN THE TOSS."); Console.Write("\n"); - + // Set the number of matches to 23 numberOfMatches = 23; // Create a random class object to generate the coin toss @@ -42,6 +43,7 @@ namespace Program if (coinTossResult == 1) { Console.WriteLine("TAILS! YOU GO FIRST. "); + // Sets the player coin toss flag to true playerGoesFirst = true; PlayerTurn(); } @@ -54,20 +56,25 @@ namespace Program numberOfMatches = numberOfMatches - 2; } + // loops the code until there is 1 or fewer matches do { + // Checks if the player has already gone + // because they won the coin toss + // if they have not then the player can go if (playerGoesFirst == false) { Console.Write("THE NUMBER OF MATCHES IS NOW " + numberOfMatches); PlayerTurn(); } + // sets the coint toss flag to false since + // this is only needed on the first loop of the code playerGoesFirst = false; ComputerTurn(); } while (numberOfMatches > 1); } - static void PlayerTurn() { Console.WriteLine("\n"); @@ -92,7 +99,7 @@ namespace Program } static void ComputerTurn() { - + // Initialize the numberOfMatchesRemovedByComputer int numberOfMatchesRemovedByComputer = 0; switch (numberOfMatches) { @@ -105,20 +112,23 @@ namespace Program case 2: numberOfMatchesRemovedByComputer = 1; break; - case 1: case 0: + case 1: case 0: // If the computer losses call this case Console.WriteLine("YOU WON, FLOPPY EARS !"); Console.WriteLine("THING YOU'RE PRETTY SMART !"); Console.WriteLine("LETS PLAY AGAIN AND I'LL BLOW YOUR SHOES OFF !!"); break; - default: + default: // If there are > than 4 matches call this case numberOfMatchesRemovedByComputer = 4 - numberOfMatchesRemovedByPlayer; break; } - + // If the numberOfMatchesRemovedByComputer has been updated run this code, + // if not them the computer has lost if (numberOfMatchesRemovedByComputer != 0) { Console.WriteLine("MY TURN ! I REMOVE " + numberOfMatchesRemovedByComputer + " MATCHES"); numberOfMatches = numberOfMatches - numberOfMatchesRemovedByComputer; + // If there are less than or equal to 1 matches + // then the player has lost if (numberOfMatches <= 1) { Console.Write("\n"); @@ -130,18 +140,24 @@ namespace Program } } + + // This method handles the player input + // and will handle inncorrect input static int ReadPlayerInput() { // Read user input and convert to integer int playerInput = 0; + // Try to read player input try { playerInput = Convert.ToInt32(Console.ReadLine()); } + // If there is an error in the player input catch (System.Exception) { Console.WriteLine("?REENTER"); Console.Write("?? "); + // Ask the player to reenter their input playerInput = ReadPlayerInput(); } return playerInput; From 0629b85d9f6198d39ad7d714570c0cb9e0b82427 Mon Sep 17 00:00:00 2001 From: Sean Lynch <66145294+MacroScenery@users.noreply.github.com> Date: Sun, 15 May 2022 10:54:06 -0400 Subject: [PATCH 8/8] fixed small printing error --- 93_23_Matches/csharp/23Matches.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/93_23_Matches/csharp/23Matches.cs b/93_23_Matches/csharp/23Matches.cs index 87d7b855..f2aeeaf8 100644 --- a/93_23_Matches/csharp/23Matches.cs +++ b/93_23_Matches/csharp/23Matches.cs @@ -88,7 +88,7 @@ namespace Program { Console.WriteLine("VERY FUNNY! DUMMY!"); Console.WriteLine("DO YOU WANT TO PLAY OR GOOF AROUND?"); - Console.Write("NOW, HOW MANY MATCHES DO YOU WANT ??"); + Console.Write("NOW, HOW MANY MATCHES DO YOU WANT ?? "); numberOfMatchesRemovedByPlayer = ReadPlayerInput(); }