From bfc5f1ba5d0247c1592906ab3fcdf3804100f892 Mon Sep 17 00:00:00 2001 From: Forrest-Flowers Date: Mon, 15 Oct 2018 13:28:40 -0500 Subject: [PATCH 1/6] initial push for RPS --- RockPaperScissors/RockPaperScissors.cs | 27 ++++++++++-- textGame/Program.cs | 58 ++++++++++++++++++++++++++ week2Practice/Program.cs | 32 ++++++++++++++ week2Practice/week2Practice.csproj | 8 ++++ 4 files changed, 122 insertions(+), 3 deletions(-) create mode 100644 textGame/Program.cs create mode 100644 week2Practice/Program.cs create mode 100644 week2Practice/week2Practice.csproj diff --git a/RockPaperScissors/RockPaperScissors.cs b/RockPaperScissors/RockPaperScissors.cs index 470ae756..f2f1f6ee 100644 --- a/RockPaperScissors/RockPaperScissors.cs +++ b/RockPaperScissors/RockPaperScissors.cs @@ -6,9 +6,9 @@ class Program { public static void Main() { - Console.WriteLine("Enter hand 1:"); + Console.WriteLine("Rock, Paper, Scissors!"); string hand1 = Console.ReadLine().ToLower(); - Console.WriteLine("Enter hand 2:"); + Console.WriteLine("The Computer is thinking..."); string hand2 = Console.ReadLine().ToLower(); Console.WriteLine(CompareHands(hand1, hand2)); @@ -16,10 +16,31 @@ public static void Main() Console.ReadLine(); } + //returns 1 if hand1 wins + //returns 2 if hand2 wins + //returns 0 if tie. public static string CompareHands(string hand1, string hand2) { // Your code here - return hand1 + ' ' + hand2; + return 0; + } + + //returns true if all tests pass + //returns false if 1 or more fails + public static bool tests(){ + // return + // CompareHands("Rock","Paper") == 2 && + // CompareHands("Rock","Scissors") == 1 && + // CompareHands("Rock","Rock") == 0 && + // CompareHands("Paper","Scissors") == 2 && + // CompareHands("Paper","Rock") == 1 && + // CompareHands("Paper","Paper") == 0 && + // CompareHands("Scissors","Rock") == 2 && + // CompareHands("Scissors","Paper") == 1 && + // CompareHands("Scissors","Scissors") == 0; + + + } } } diff --git a/textGame/Program.cs b/textGame/Program.cs new file mode 100644 index 00000000..4d01903f --- /dev/null +++ b/textGame/Program.cs @@ -0,0 +1,58 @@ +using System; +using System.Threading; + +namespace textGame +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); + Console.WriteLine("Welcome to the cavern of secrets!"); + Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); + Thread.Sleep(2000); + + String ch1; + + + + Console.WriteLine("You enter a dark cavern out of curiosity. It is dark and you can only make out a small stick on the floor."); + Console.WriteLine("Do you pick up the stick? [y/n]"); + ch1 = Console.ReadLine(); + // STICK TAKEN + if (ch1 == "y" || ch1 == "Y" || ch1 == "Yes" || ch1 == "YES" || ch1 == "yes"){ + Console.WriteLine("You pick up the stick!"); + Thread.Sleep(2000); + bool stick = true; + }//STICK NOT TAKEN + else{ + Console.WriteLine("You pass up the Stick."); + Thread.Sleep(2000); + bool stick = false; + } + string ch2; + + Console.WriteLine("As you proceed further into the cave, you see a small glowing object"); + Console.WriteLine("Do you approach the object? [y/n]"); + ch2 = Console.ReadLine(); + + if(ch2 == "y" || ch2 == "Y" || ch2 == "Yes" || ch2 == "YES" || ch2 == "yes"){ + string ch3; + + Console.WriteLine("You approach the object..."); + Thread.Sleep(2000); + Console.WriteLine("As you draw closer, you begin to make out the object as an eye!"); + Thread.Sleep(2000); + Console.WriteLine("The eye belongs to a giant spider!"); + Console.WriteLine("Do you try to fight it? [Y/N]"); + + + + + + }else + + + } + } +} diff --git a/week2Practice/Program.cs b/week2Practice/Program.cs new file mode 100644 index 00000000..82e5266a --- /dev/null +++ b/week2Practice/Program.cs @@ -0,0 +1,32 @@ +using System; + +namespace week2Practice +{ + class Program + { + static void Main(string[] args) + { + //ask user for grade + //if number is a grade, print out you made an A + int grade = 0; + string input; + + Console.WriteLine("Enter a Numerical Grade:"); + input = Console.ReadLine(); + grade = Convert.ToInt32(input); + + if(grade >= 90){ + Console.WriteLine("You made an A! Congrats!"); + }else if(grade >= 80){ + Console.WriteLine("You made a B! Almost Perfect."); + }else if(grade >= 70){ + Console.WriteLine("You made a C! Study up."); + }else if(grade >= 60){ + Console.WriteLine("You made a D! You can do better."); + }else{ + Console.WriteLine("You Failed! Try again!"); + } + Console.WriteLine("Thank you for submitting."); + } + } +} diff --git a/week2Practice/week2Practice.csproj b/week2Practice/week2Practice.csproj new file mode 100644 index 00000000..23df6047 --- /dev/null +++ b/week2Practice/week2Practice.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.1 + + + From 9cfaf304bb42f62fd0f3c6493dc74b55f1d2734b Mon Sep 17 00:00:00 2001 From: Forrest-Flowers Date: Mon, 22 Oct 2018 19:38:09 -0500 Subject: [PATCH 2/6] Adding Computer --- ExceptionPractice/ExceptionPractice.csproj | 8 +++++ ExceptionPractice/Program.cs | 29 ++++++++++++++++ RockPaperScissors/RockPaperScissors.cs | 40 +++++++++++++++++++--- 3 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 ExceptionPractice/ExceptionPractice.csproj create mode 100644 ExceptionPractice/Program.cs diff --git a/ExceptionPractice/ExceptionPractice.csproj b/ExceptionPractice/ExceptionPractice.csproj new file mode 100644 index 00000000..23df6047 --- /dev/null +++ b/ExceptionPractice/ExceptionPractice.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.1 + + + diff --git a/ExceptionPractice/Program.cs b/ExceptionPractice/Program.cs new file mode 100644 index 00000000..a9e95829 --- /dev/null +++ b/ExceptionPractice/Program.cs @@ -0,0 +1,29 @@ +using System; + +namespace ExceptionPractice +{ + class Program + { + static void Main(string[] args) + { + try + { + double ans1 = divide(17.0, 0.0); + Console.WriteLine(ans1); + } + catch + { + Console.WriteLine("Oops, there was a problem with the divide function."); + } + + } + public static double divide(double num1, double num2) + { + if (num2 == 0.0) + { + throw new Exception("Cannot divide by 0, Sorry!"); + } + return num1 / num2; + } + } +} diff --git a/RockPaperScissors/RockPaperScissors.cs b/RockPaperScissors/RockPaperScissors.cs index f2f1f6ee..7dd0dc7a 100644 --- a/RockPaperScissors/RockPaperScissors.cs +++ b/RockPaperScissors/RockPaperScissors.cs @@ -9,25 +9,55 @@ public static void Main() Console.WriteLine("Rock, Paper, Scissors!"); string hand1 = Console.ReadLine().ToLower(); Console.WriteLine("The Computer is thinking..."); - string hand2 = Console.ReadLine().ToLower(); + string hand2 = "" Console.WriteLine(CompareHands(hand1, hand2)); // leave this command at the end so your program does not close automatically Console.ReadLine(); } - + + public static string checkInput(string hand1) + { + if (hand1 != "rock" && hand1 != "paper" && hand1 != "scissors") + { + throw new Exception("Incorrect Input."); + } + return hand1; + } + + public static void computerInput(string hand2){ + Random rps = new Random(); + + rps(0,3); + } + //returns 1 if hand1 wins //returns 2 if hand2 wins //returns 0 if tie. public static string CompareHands(string hand1, string hand2) { - // Your code here - return 0; + if (hand1 == hand2) + { + + } + else if (hand1 == "rock" && hand2 == "scissors" || hand1 == "paper" && hand2 == "rock" || hand1 == "scissors" && hand2 == "paper") + { + + } + else if (hand2 == "rock" && hand1 == "scissors" || hand2 == "paper" && hand1 == "rock" || hand2 == "scissors" && hand1 == "paper") + { + + } + else + { + + } } //returns true if all tests pass //returns false if 1 or more fails - public static bool tests(){ + public static bool tests(string hand1, string hand2) + { // return // CompareHands("Rock","Paper") == 2 && // CompareHands("Rock","Scissors") == 1 && From 65385bd4ae7b0691c0a579f063afeea706f4852e Mon Sep 17 00:00:00 2001 From: Forrest-Flowers Date: Wed, 24 Oct 2018 18:40:24 -0500 Subject: [PATCH 3/6] Mostly done, CompareHands is being funky --- RockPaperScissors/RockPaperScissors.cs | 88 +++++++++++++++----------- textGame/Program.cs | 47 +------------- 2 files changed, 52 insertions(+), 83 deletions(-) diff --git a/RockPaperScissors/RockPaperScissors.cs b/RockPaperScissors/RockPaperScissors.cs index 7dd0dc7a..e684e39f 100644 --- a/RockPaperScissors/RockPaperScissors.cs +++ b/RockPaperScissors/RockPaperScissors.cs @@ -6,18 +6,26 @@ class Program { public static void Main() { - Console.WriteLine("Rock, Paper, Scissors!"); - string hand1 = Console.ReadLine().ToLower(); - Console.WriteLine("The Computer is thinking..."); - string hand2 = "" - Console.WriteLine(CompareHands(hand1, hand2)); + string hand1 = playerInput(); + string hand2 = computerInput(); + + + + CompareHands(hand1, hand2); + - // leave this command at the end so your program does not close automatically + + + //Keep this here to keep code from closing out. Console.ReadLine(); } - public static string checkInput(string hand1) - { + //Get input from user and check if it's valid. + public static string playerInput() + { + Console.WriteLine("Rock, Paper, Scissors!"); + string hand1 = Console.ReadLine().ToLower(); + if (hand1 != "rock" && hand1 != "paper" && hand1 != "scissors") { throw new Exception("Incorrect Input."); @@ -25,52 +33,58 @@ public static string checkInput(string hand1) return hand1; } - public static void computerInput(string hand2){ + + //Takes a random number and turns it into a game choice. + public static string computerInput() + { Random rps = new Random(); + int num = rps.Next(0, 3); + string hand2; - rps(0,3); + Console.WriteLine(num); + + if (num == 0) + { + hand2 = "rock"; + Console.WriteLine("The computer chose rock!"); + } + else if (num == 1) + { + hand2 = "paper"; + Console.WriteLine("The Computer chose paper!"); + } + else if (num == 2) + { + hand2 = "scissors"; + Console.WriteLine("The computer chose scissors!"); + } + else + { + throw new Exception("Error in computer generation."); + } + return hand2; } - //returns 1 if hand1 wins - //returns 2 if hand2 wins - //returns 0 if tie. - public static string CompareHands(string hand1, string hand2) + + public static int CompareHands(string hand1, string hand2) { + if (hand1 == hand2) { - + return 0; } else if (hand1 == "rock" && hand2 == "scissors" || hand1 == "paper" && hand2 == "rock" || hand1 == "scissors" && hand2 == "paper") { - + return 1; } else if (hand2 == "rock" && hand1 == "scissors" || hand2 == "paper" && hand1 == "rock" || hand2 == "scissors" && hand1 == "paper") { - + return 2; } else { - + throw new Exception("Comparison Error."); } } - - //returns true if all tests pass - //returns false if 1 or more fails - public static bool tests(string hand1, string hand2) - { - // return - // CompareHands("Rock","Paper") == 2 && - // CompareHands("Rock","Scissors") == 1 && - // CompareHands("Rock","Rock") == 0 && - // CompareHands("Paper","Scissors") == 2 && - // CompareHands("Paper","Rock") == 1 && - // CompareHands("Paper","Paper") == 0 && - // CompareHands("Scissors","Rock") == 2 && - // CompareHands("Scissors","Paper") == 1 && - // CompareHands("Scissors","Scissors") == 0; - - - - } } } diff --git a/textGame/Program.cs b/textGame/Program.cs index 4d01903f..e9cd9656 100644 --- a/textGame/Program.cs +++ b/textGame/Program.cs @@ -7,52 +7,7 @@ class Program { static void Main(string[] args) { - Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); - Console.WriteLine("Welcome to the cavern of secrets!"); - Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); - Thread.Sleep(2000); - - String ch1; - - - - Console.WriteLine("You enter a dark cavern out of curiosity. It is dark and you can only make out a small stick on the floor."); - Console.WriteLine("Do you pick up the stick? [y/n]"); - ch1 = Console.ReadLine(); - // STICK TAKEN - if (ch1 == "y" || ch1 == "Y" || ch1 == "Yes" || ch1 == "YES" || ch1 == "yes"){ - Console.WriteLine("You pick up the stick!"); - Thread.Sleep(2000); - bool stick = true; - }//STICK NOT TAKEN - else{ - Console.WriteLine("You pass up the Stick."); - Thread.Sleep(2000); - bool stick = false; - } - string ch2; - - Console.WriteLine("As you proceed further into the cave, you see a small glowing object"); - Console.WriteLine("Do you approach the object? [y/n]"); - ch2 = Console.ReadLine(); - - if(ch2 == "y" || ch2 == "Y" || ch2 == "Yes" || ch2 == "YES" || ch2 == "yes"){ - string ch3; - - Console.WriteLine("You approach the object..."); - Thread.Sleep(2000); - Console.WriteLine("As you draw closer, you begin to make out the object as an eye!"); - Thread.Sleep(2000); - Console.WriteLine("The eye belongs to a giant spider!"); - Console.WriteLine("Do you try to fight it? [Y/N]"); - - - - - - }else - - + Console.WriteLine("Hello World!"); } } } From cb8681f9e25b1814074d172243c77277020f62e1 Mon Sep 17 00:00:00 2001 From: Forrest-Flowers Date: Sun, 28 Oct 2018 15:40:45 -0500 Subject: [PATCH 4/6] Finished all but Exception --- RockPaperScissors/RockPaperScissors.cs | 56 +++++++++++++++++++++----- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/RockPaperScissors/RockPaperScissors.cs b/RockPaperScissors/RockPaperScissors.cs index e684e39f..5b4fed9b 100644 --- a/RockPaperScissors/RockPaperScissors.cs +++ b/RockPaperScissors/RockPaperScissors.cs @@ -6,14 +6,32 @@ class Program { public static void Main() { + if (tests()) + { + Console.WriteLine("Tests Passed!"); + } + else + { + Console.WriteLine("Tests Failed!"); + } + Console.WriteLine("-----------------"); + string hand1 = playerInput(); string hand2 = computerInput(); + int compare = CompareHands(hand1, hand2); - - - CompareHands(hand1, hand2); - - + if (compare == 0) + { + Console.WriteLine("It's a tie!"); + } + else if (compare == 1) + { + Console.WriteLine("You Win, Congrats!"); + } + else if (compare == 2) + { + Console.WriteLine("Computer Wins! Sorry bud."); + } //Keep this here to keep code from closing out. @@ -23,6 +41,7 @@ public static void Main() //Get input from user and check if it's valid. public static string playerInput() { + Console.WriteLine("Rock, Paper, Scissors!"); string hand1 = Console.ReadLine().ToLower(); @@ -30,19 +49,21 @@ public static string playerInput() { throw new Exception("Incorrect Input."); } - return hand1; + else + { + return hand1; + } + } - //Takes a random number and turns it into a game choice. + //Takes a random number and turns it into the computer's hand. public static string computerInput() { Random rps = new Random(); int num = rps.Next(0, 3); string hand2; - Console.WriteLine(num); - if (num == 0) { hand2 = "rock"; @@ -68,7 +89,6 @@ public static string computerInput() public static int CompareHands(string hand1, string hand2) { - if (hand1 == hand2) { return 0; @@ -86,5 +106,21 @@ public static int CompareHands(string hand1, string hand2) throw new Exception("Comparison Error."); } } + + public static bool tests() + { + return + CompareHands("rock", "rock") == 0 && + CompareHands("rock", "scissors") == 1 && + CompareHands("rock", "paper") == 2 && + + CompareHands("paper", "paper") == 0 && + CompareHands("paper", "rock") == 1 && + CompareHands("paper", "scissors") == 2 && + + CompareHands("scissors", "scissors") == 0 && + CompareHands("scissors", "paper") == 1 && + CompareHands("scissors", "rock") == 2; + } } } From 149f0db8e26f5490b3609251552b85de4fd6724c Mon Sep 17 00:00:00 2001 From: Forrest-Flowers Date: Mon, 29 Oct 2018 18:51:18 -0500 Subject: [PATCH 5/6] almost got try catch --- RockPaperScissors/RockPaperScissors.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/RockPaperScissors/RockPaperScissors.cs b/RockPaperScissors/RockPaperScissors.cs index 5b4fed9b..90ecb2d0 100644 --- a/RockPaperScissors/RockPaperScissors.cs +++ b/RockPaperScissors/RockPaperScissors.cs @@ -16,10 +16,29 @@ public static void Main() } Console.WriteLine("-----------------"); - string hand1 = playerInput(); + string hand1 = null; + + + while (hand1 == null) + { + try + { + playerInput(); + } + catch + { + Console.WriteLine("Enter Rock Paper or Scissor. Come on, you know better than that."); + } + finally + { + hand1 = playerInput(); + } + } + string hand2 = computerInput(); int compare = CompareHands(hand1, hand2); + if (compare == 0) { Console.WriteLine("It's a tie!"); From 093b82b6c14cfe9d14d31444e985a61cd4c5d7fb Mon Sep 17 00:00:00 2001 From: Forrest-Flowers Date: Wed, 28 Nov 2018 13:37:24 -0600 Subject: [PATCH 6/6] Exception fixed --- RockPaperScissors/RockPaperScissors.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/RockPaperScissors/RockPaperScissors.cs b/RockPaperScissors/RockPaperScissors.cs index 90ecb2d0..6b59c9ea 100644 --- a/RockPaperScissors/RockPaperScissors.cs +++ b/RockPaperScissors/RockPaperScissors.cs @@ -29,10 +29,6 @@ public static void Main() { Console.WriteLine("Enter Rock Paper or Scissor. Come on, you know better than that."); } - finally - { - hand1 = playerInput(); - } } string hand2 = computerInput();