From 22ccbc69489756f1a828cdaaa384170c89a54656 Mon Sep 17 00:00:00 2001 From: DeMarco Date: Sat, 6 Oct 2018 11:01:55 -0500 Subject: [PATCH 01/14] finished week1 practice --- Week1-Practice/Program.cs | 51 ++++++++++++++++++++++++++++ Week1-Practice/Week1-Practice.csproj | 9 +++++ 2 files changed, 60 insertions(+) create mode 100644 Week1-Practice/Program.cs create mode 100644 Week1-Practice/Week1-Practice.csproj diff --git a/Week1-Practice/Program.cs b/Week1-Practice/Program.cs new file mode 100644 index 00000000..f5903523 --- /dev/null +++ b/Week1-Practice/Program.cs @@ -0,0 +1,51 @@ +using System; + +namespace Week1_Practice +{ + class Program + { + static void Main(string[] args) + { + int input1 = 0; + int input2 = 0; + + Console.WriteLine("Give me a number between 0 and 100:"); + input1 = Convert.ToInt32(Console.ReadLine()); + Console.WriteLine("Give me another number between 0 and 100:"); + input2 = Convert.ToInt32(Console.ReadLine()); + + Console.WriteLine(input1 + input2); + + int yardLength = 0; + int inchLength = 0; + Console.WriteLine("Give me a number of yards?"); + yardLength = Convert.ToInt32(Console.ReadLine()); + inchLength = (yardLength * 36); + + Console.WriteLine("You have {0} inches!", inchLength); + + bool people = true; + bool f = false; + decimal numb = 0.0M; + + + string firstName = "DeMarco"; + string lastName = "Spears"; + int age = 27; + string job = "Client Support Agent"; + string favoriteBand = "Beetles"; + string favoriteSportsTeam = "Golden State Warriors"; + + + Console.WriteLine("Give me a decimal number?"); + numb = Convert.ToDecimal(Console.ReadLine()); + Console.WriteLine(numb * numb); + Console.WriteLine("I love sports my favorite team is the {0}", favoriteSportsTeam); + Console.WriteLine("My birthday is on the forth of July, I'm {0} years old!", age); + Console.WriteLine("My favorite band of all time is the {0}!", favoriteBand); + Console.WriteLine("I work at Dell as a {0}!", job); + + } + } + +} diff --git a/Week1-Practice/Week1-Practice.csproj b/Week1-Practice/Week1-Practice.csproj new file mode 100644 index 00000000..b8c2678e --- /dev/null +++ b/Week1-Practice/Week1-Practice.csproj @@ -0,0 +1,9 @@ + + + + Exe + netcoreapp2.1 + Week1_Practice + + + From d8271b9287dcc7b28b64eb2e2553a3a1f71b1782 Mon Sep 17 00:00:00 2001 From: DeMarco Date: Sun, 7 Oct 2018 22:18:07 -0500 Subject: [PATCH 02/14] textgame file added --- TextGame/TextGame.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 TextGame/TextGame.cs diff --git a/TextGame/TextGame.cs b/TextGame/TextGame.cs new file mode 100644 index 00000000..cb26e2c1 --- /dev/null +++ b/TextGame/TextGame.cs @@ -0,0 +1,18 @@ +musing System; +using threading; + +namespace TextGame +{ + + class Program + { + + public void Main(string[] args) + { + Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); + Console.WriteLine("Welcome to the cavern of secrets!"); + Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); + + } + } +} \ No newline at end of file From e11262739c429c1abcd0b6091fac436f01ebbb42 Mon Sep 17 00:00:00 2001 From: DeMarco Date: Sun, 7 Oct 2018 22:22:14 -0500 Subject: [PATCH 03/14] file renamed --- TextGame/{TextGame.cs => Program.cs} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename TextGame/{TextGame.cs => Program.cs} (94%) diff --git a/TextGame/TextGame.cs b/TextGame/Program.cs similarity index 94% rename from TextGame/TextGame.cs rename to TextGame/Program.cs index cb26e2c1..2ad6914c 100644 --- a/TextGame/TextGame.cs +++ b/TextGame/Program.cs @@ -1,5 +1,5 @@ musing System; -using threading; +// using threading; namespace TextGame { From 2efd24f79bc6e2d9e43a8d53fcb47161e25369a9 Mon Sep 17 00:00:00 2001 From: DeMarco Date: Mon, 8 Oct 2018 00:01:06 -0500 Subject: [PATCH 04/14] 1st attempt text game --- TextGame/Program.cs | 58 +++++++++++++++++++++++++++++++++++++--- TextGame/textgame.csproj | 8 ++++++ 2 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 TextGame/textgame.csproj diff --git a/TextGame/Program.cs b/TextGame/Program.cs index 2ad6914c..f36f44f5 100644 --- a/TextGame/Program.cs +++ b/TextGame/Program.cs @@ -1,5 +1,5 @@ -musing System; -// using threading; +using System; +using System.Threading; namespace TextGame { @@ -7,12 +7,62 @@ namespace TextGame class Program { - public void Main(string[] args) + static void Main(string[] args) { Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); Console.WriteLine("Welcome to the cavern of secrets!"); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); + Thread.Sleep(1000); + 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 take it? [y/n]: "); + string ch1 = Console.ReadLine(); + string ch2 = Console.ReadLine(); + string ch3 = Console.ReadLine(); + + int stick = 0; + if (ch1 == "y") + { + Console.WriteLine("You have taken the stick!"); + Thread.Sleep(2000); + stick = 1; + } + else + { + Console.WriteLine("You did not take the stick"); + stick = 0; + Console.WriteLine("As you proceed further into the cave, you see a small glowing object"); + + } + if (ch2 == "y") + { + 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]"); + } + if (ch3 == "y") + { + if (stick == 1) + Console.WriteLine("You only have a stick to fight with!"); + Console.WriteLine("You quickly jab the spider in it's eye and gain an advantage"); + Thread.Sleep(2000); + Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); + Console.WriteLine(" Fighting... "); + Console.WriteLine(" YOU MUST HIT ABOVE A 5 TO KILL THE SPIDER "); + Console.WriteLine("IF THE SPIDER HITS HIGHER THAN YOU, YOU WILL DIE"); + Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); + Thread.Sleep(2000); + // Random random = new Random(); + // int fdmg1 = Random.Next(3, 10); + // int edmg1 = Random.Next(1, 5); + Console.WriteLine("you hit a"); + Console.WriteLine("the spider hits a"); + Thread.Sleep(2000); + } + } } -} \ No newline at end of file +} diff --git a/TextGame/textgame.csproj b/TextGame/textgame.csproj new file mode 100644 index 00000000..23df6047 --- /dev/null +++ b/TextGame/textgame.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.1 + + + From ff1c62b4b12f48870fcd03309b0a8c72004e15db Mon Sep 17 00:00:00 2001 From: DeMarco Date: Tue, 9 Oct 2018 22:04:21 -0500 Subject: [PATCH 05/14] updated text game --- TextGame/Program.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/TextGame/Program.cs b/TextGame/Program.cs index f36f44f5..eb04b169 100644 --- a/TextGame/Program.cs +++ b/TextGame/Program.cs @@ -54,9 +54,10 @@ static void Main(string[] args) Console.WriteLine("IF THE SPIDER HITS HIGHER THAN YOU, YOU WILL DIE"); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); Thread.Sleep(2000); - // Random random = new Random(); - // int fdmg1 = Random.Next(3, 10); - // int edmg1 = Random.Next(1, 5); + // Random randomNub = new Random(); + // int fdmg1 = Random.Next(3, 11); + // int edmg1 = Random.Next(1, 6); + //the random number gen will not display properly- im getting an error message Console.WriteLine("you hit a"); Console.WriteLine("the spider hits a"); Thread.Sleep(2000); From 2feaa9e102ae5a59afef09124d7aadb48d7a4848 Mon Sep 17 00:00:00 2001 From: DeMarco Date: Wed, 10 Oct 2018 19:23:07 -0500 Subject: [PATCH 06/14] week2-2 practice --- Week2-2-Practice/Program.cs | 22 ++++++++++++++++++++++ Week2-2-Practice/Week2-2-Practice.csproj | 9 +++++++++ 2 files changed, 31 insertions(+) create mode 100644 Week2-2-Practice/Program.cs create mode 100644 Week2-2-Practice/Week2-2-Practice.csproj diff --git a/Week2-2-Practice/Program.cs b/Week2-2-Practice/Program.cs new file mode 100644 index 00000000..db35e611 --- /dev/null +++ b/Week2-2-Practice/Program.cs @@ -0,0 +1,22 @@ +using System; + +namespace Week2_2_Practice +{ + class Program + { + static void Main(string[] args) + { + string userInput = ""; + userInput = Console.ReadLine(Convert.ToInt32()); + Console.WriteLine("Please provide a number 0 - 100:"); + if(userInput => 90) + { + Console.WriteLine("You got an A!"); + } + else + { + Console.WriteLine("sorry buddy!") + } + } + } +} diff --git a/Week2-2-Practice/Week2-2-Practice.csproj b/Week2-2-Practice/Week2-2-Practice.csproj new file mode 100644 index 00000000..370e0eee --- /dev/null +++ b/Week2-2-Practice/Week2-2-Practice.csproj @@ -0,0 +1,9 @@ + + + + Exe + netcoreapp2.1 + Week2_2_Practice + + + From 15fd5beea94cb8330d859c0bcfd1c68a9f30eff6 Mon Sep 17 00:00:00 2001 From: DeMarco Date: Wed, 10 Oct 2018 20:22:22 -0500 Subject: [PATCH 07/14] Finished week2 practice --- Week2-2-Practice/Program.cs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Week2-2-Practice/Program.cs b/Week2-2-Practice/Program.cs index db35e611..bbabb1a2 100644 --- a/Week2-2-Practice/Program.cs +++ b/Week2-2-Practice/Program.cs @@ -6,17 +6,22 @@ class Program { static void Main(string[] args) { - string userInput = ""; - userInput = Console.ReadLine(Convert.ToInt32()); - Console.WriteLine("Please provide a number 0 - 100:"); - if(userInput => 90) - { - Console.WriteLine("You got an A!"); - } - else - { - Console.WriteLine("sorry buddy!") + int grade = 0; + Console.WriteLine("Please enter a number from 0 - 100:"); + String input = Console.ReadLine(); + grade = Convert.ToInt32(input); + + if (grade >= 90){ + Console.WriteLine("You made an A!"); + } else if (grade >= 80){ + Console.WriteLine("You made a B!"); + } else if (grade >= 70){ + Console.WriteLine("You made a C!"); + } else { + Console.WriteLine("You Failed!!!"); } + + Console.Write("End of Program"); } } } From 379f584c6f0fc6688d7f9fdd3a8345dc8dfec4f0 Mon Sep 17 00:00:00 2001 From: DeMarco Date: Sun, 14 Oct 2018 19:42:08 -0500 Subject: [PATCH 08/14] first draft PigLatin --- PigLatin/PigLatin.cs | 60 +++++++++++++++++----- RockPaperScissors/RockPaperScissors.csproj | 2 +- 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/PigLatin/PigLatin.cs b/PigLatin/PigLatin.cs index 702647dd..cd759fa6 100644 --- a/PigLatin/PigLatin.cs +++ b/PigLatin/PigLatin.cs @@ -1,21 +1,57 @@ using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; namespace PigLatin { class Program { - public static void Main() + static void Main(string[] args) { - // your code goes here - - // leave this command at the end so your program does not close automatically - Console.ReadLine(); - } + Console.WriteLine("Enter a word"); + Console.ReadLine(); - public static string TranslateWord(string word) - { - // your code goes here - return word; } - } -} + + public static string TranslateWord(string str) + { + string pigWord = ""; + string sentence = ""; + string firstLetter; + string restOfWord; + string vowels = "AEIOUaeiou"; + int letterPosition; + + while (sentence.ToLower() != "quit") + { + Console.WriteLine("Please enter a word or sentence:"); + + sentence = Console.ReadLine(); + + foreach (string newstr in sentence.Split()) + { + firstLetter = str.Substring(0, 1); + restOfWord = str.Substring(1, str.Length - 1); + + letterPosition = vowels.IndexOf(firstLetter); + + if (letterPosition == -1) + { + // it's a consonant + pigWord = restOfWord + firstLetter + "ay"; + } + else + { + // it's a vowel + pigWord = str + "yay"; + } // end if + + Console.Write("{0} ", pigWord); + return newstr; + + } + } + } + } +} \ No newline at end of file diff --git a/RockPaperScissors/RockPaperScissors.csproj b/RockPaperScissors/RockPaperScissors.csproj index ce1697ae..23df6047 100644 --- a/RockPaperScissors/RockPaperScissors.csproj +++ b/RockPaperScissors/RockPaperScissors.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp2.0 + netcoreapp2.1 From be448d5d9643cfb4d0175d177cbf49147246bfc0 Mon Sep 17 00:00:00 2001 From: DeMarco Date: Mon, 15 Oct 2018 18:36:20 -0500 Subject: [PATCH 09/14] Final paperrockscissors --- RockPaperScissors/RockPaperScissors.cs | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/RockPaperScissors/RockPaperScissors.cs b/RockPaperScissors/RockPaperScissors.cs index 470ae756..cdd99479 100644 --- a/RockPaperScissors/RockPaperScissors.cs +++ b/RockPaperScissors/RockPaperScissors.cs @@ -14,11 +14,45 @@ public static void Main() // leave this command at the end so your program does not close automatically Console.ReadLine(); + } public static string CompareHands(string hand1, string hand2) { // Your code here + if (hand1 == "rock" && hand2 == "rock") + { + Console.WriteLine("Tie"); + } else if (hand1 == "rock" && hand2 == "scissors") + { + Console.WriteLine("hand1 wins!"); + } else if (hand1 == "rock" && hand2 == "paper") + { + Console.WriteLine("hand2 wins!"); + } else if (hand1 == "scissors" && hand2 == "rock") + { + Console.WriteLine("hand2 wins"); + } else if (hand1 == "scissors" && hand2 == "paper") + { + Console.WriteLine("hand1 wins"); + } else if (hand1 == "scissors" && hand2 == "scissors") + { + Console.WriteLine("Tie"); + } else if (hand1 == "paper" && hand2 == "paper") + { + Console.WriteLine("Tie"); + } else if (hand1 == "paper" && hand2 == "scissors") + { + Console.WriteLine("hand2 wins"); + } else if (hand1 == "paper" && hand2 == "rock") + { + Console.WriteLine("hand1 wins"); + } else + { + Console.WriteLine("try again"); + } + + return hand1 + ' ' + hand2; } } From 94c3d890c2d274c4fc264a0966d313acd06abdf9 Mon Sep 17 00:00:00 2001 From: DeMarco Date: Thu, 18 Oct 2018 19:17:04 -0500 Subject: [PATCH 10/14] I tried to fix it --- PigLatin/PigLatin.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/PigLatin/PigLatin.cs b/PigLatin/PigLatin.cs index cd759fa6..a98527bb 100644 --- a/PigLatin/PigLatin.cs +++ b/PigLatin/PigLatin.cs @@ -1,6 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; +// using System.Collections.Generic; +// using System.Linq; using System.Text; namespace PigLatin @@ -14,7 +14,7 @@ static void Main(string[] args) } - public static string TranslateWord(string str) + public String TranslateWord(string word) { string pigWord = ""; string sentence = ""; @@ -29,10 +29,10 @@ public static string TranslateWord(string str) sentence = Console.ReadLine(); - foreach (string newstr in sentence.Split()) + foreach (string text in sentence.Split()) { - firstLetter = str.Substring(0, 1); - restOfWord = str.Substring(1, str.Length - 1); + firstLetter = text.Substring(0, 1); + restOfWord = text.Substring(1, text.Length - 1); letterPosition = vowels.IndexOf(firstLetter); @@ -44,12 +44,12 @@ public static string TranslateWord(string str) else { // it's a vowel - pigWord = str + "yay"; + pigWord = text + "yay"; } // end if Console.Write("{0} ", pigWord); - return newstr; - + return word; + } } } From af637c29a04682d43e7559863b907f40590ba435 Mon Sep 17 00:00:00 2001 From: DeMarco Date: Thu, 18 Oct 2018 19:46:04 -0500 Subject: [PATCH 11/14] added test --- RockPaperScissors/RockPaperScissors.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/RockPaperScissors/RockPaperScissors.cs b/RockPaperScissors/RockPaperScissors.cs index cdd99479..0f5ff5c5 100644 --- a/RockPaperScissors/RockPaperScissors.cs +++ b/RockPaperScissors/RockPaperScissors.cs @@ -14,6 +14,7 @@ public static void Main() // leave this command at the end so your program does not close automatically Console.ReadLine(); + } @@ -55,5 +56,20 @@ public static string CompareHands(string hand1, string hand2) return hand1 + ' ' + hand2; } + // public static bool test() + // { + // return 0; + + // CompareHands("Paper", "Paper") == 0 && + // CompareHands("Paper", "Rock") == 1 && + // CompareHands("Paper", "Scissors") == 2 && + // CompareHands("Rock", "Paper") == 2 && + // CompareHands("Rock", "Rock") == 0 && + // CompareHands("Rock", "Scissors") == 1 && + // CompareHands("Scissors", "Paper") == 1 && + // CompareHands("Scissors", "Scissors") == 0 && + // CompareHands("Scissors", "Rock") == 2; + + // } } } From d93b7b0f6293d9e6b4ece111427c449d5e69efba Mon Sep 17 00:00:00 2001 From: DeMarco Date: Wed, 24 Oct 2018 21:15:30 -0500 Subject: [PATCH 12/14] Updated TTT game --- RockPaperScissors/RockPaperScissors.cs | 118 +++++++++++++++++-------- 1 file changed, 79 insertions(+), 39 deletions(-) diff --git a/RockPaperScissors/RockPaperScissors.cs b/RockPaperScissors/RockPaperScissors.cs index 0f5ff5c5..bafcab9f 100644 --- a/RockPaperScissors/RockPaperScissors.cs +++ b/RockPaperScissors/RockPaperScissors.cs @@ -8,53 +8,72 @@ public static void Main() { Console.WriteLine("Enter hand 1:"); string hand1 = Console.ReadLine().ToLower(); - Console.WriteLine("Enter hand 2:"); - string hand2 = Console.ReadLine().ToLower(); - Console.WriteLine(CompareHands(hand1, hand2)); + string hand2 = GetComputerHand().ToLower(); + Console.WriteLine("You choose " + + hand1 + " and the computer choose " + hand2); // leave this command at the end so your program does not close automatically - Console.ReadLine(); - - + // Console.ReadLine(); + int outCome = CompareHands(hand1, hand2); + if (outCome == 0) + { + Console.WriteLine("You tied!"); + } + else if (outCome == 1) + { + Console.WriteLine("Hand 1 wins"); + } + else + { + Console.WriteLine("Hand 2 wins"); + } + } - - public static string CompareHands(string hand1, string hand2) + + public static int CompareHands(string hand1, string hand2) { // Your code here - if (hand1 == "rock" && hand2 == "rock") + if (hand1 == hand2) + { + return 0; + } + else if (hand1 == "rock" && hand2 == "scissors") { - Console.WriteLine("Tie"); - } else if (hand1 == "rock" && hand2 == "scissors") + return 1; + } + else if (hand1 == "rock" && hand2 == "paper") { - Console.WriteLine("hand1 wins!"); - } else if (hand1 == "rock" && hand2 == "paper") + return 2; + } + else if (hand1 == "scissors" && hand2 == "rock") { - Console.WriteLine("hand2 wins!"); - } else if (hand1 == "scissors" && hand2 == "rock") + return 1; + } + else if (hand1 == "scissors" && hand2 == "paper") { - Console.WriteLine("hand2 wins"); - } else if (hand1 == "scissors" && hand2 == "paper") + return 1; + // } else if (hand1 == hand2) + // { + // Console.WriteLine("Tie"); + // } else if (hand1 == "Paper" && hand2 == "Paper") + // { + // Console.WriteLine("Tie"); + } + else if (hand1 == "paper" && hand2 == "scissors") { - Console.WriteLine("hand1 wins"); - } else if (hand1 == "scissors" && hand2 == "scissors") - { - Console.WriteLine("Tie"); - } else if (hand1 == "paper" && hand2 == "paper") - { - Console.WriteLine("Tie"); - } else if (hand1 == "paper" && hand2 == "scissors") - { - Console.WriteLine("hand2 wins"); - } else if (hand1 == "paper" && hand2 == "rock") - { - Console.WriteLine("hand1 wins"); - } else - { - Console.WriteLine("try again"); - } - - - return hand1 + ' ' + hand2; + return 2; + } + else if (hand1 == "paper" && hand2 == "rock") + { + return 1; + } + else + { + Console.WriteLine("Try again"); + } + + + return 0; } // public static bool test() // { @@ -69,7 +88,28 @@ public static string CompareHands(string hand1, string hand2) // CompareHands("Scissors", "Paper") == 1 && // CompareHands("Scissors", "Scissors") == 0 && // CompareHands("Scissors", "Rock") == 2; - - // } + + + public static String GetComputerHand() + { + Random Rnd = new Random(); + int randomInt = Rnd.Next(1, 4); + + if (randomInt == 1) + { + return "Rock"; + + } + else if (randomInt == 2) + { + return "Paper"; + } + else + { + return "Scissors"; + } + + } } } + From 83026ef8b9fbb5fe9c8624a1ea155879dd4530db Mon Sep 17 00:00:00 2001 From: DeMarco Date: Sat, 3 Nov 2018 11:13:19 -0500 Subject: [PATCH 13/14] attempt --- RockPaperScissors/RockPaperScissors.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/RockPaperScissors/RockPaperScissors.cs b/RockPaperScissors/RockPaperScissors.cs index bafcab9f..0ebeffba 100644 --- a/RockPaperScissors/RockPaperScissors.cs +++ b/RockPaperScissors/RockPaperScissors.cs @@ -14,6 +14,7 @@ public static void Main() // leave this command at the end so your program does not close automatically // Console.ReadLine(); + int outCome = CompareHands(hand1, hand2); if (outCome == 0) { @@ -26,12 +27,15 @@ public static void Main() else { Console.WriteLine("Hand 2 wins"); + } try { + } } public static int CompareHands(string hand1, string hand2) { + // Your code here if (hand1 == hand2) { @@ -69,11 +73,9 @@ public static int CompareHands(string hand1, string hand2) } else { - Console.WriteLine("Try again"); + throw new Exception("Please enter a valid hand!"); } - - - return 0; + return 3; } // public static bool test() // { From a8ee8e8ed2ece310602aa53ccc8735a3d91d6e64 Mon Sep 17 00:00:00 2001 From: DeMarco Date: Tue, 6 Nov 2018 19:53:19 -0600 Subject: [PATCH 14/14] Exceptions assignment --- RockPaperScissors/RockPaperScissors.cs | 91 +++++++++++++++----------- 1 file changed, 51 insertions(+), 40 deletions(-) diff --git a/RockPaperScissors/RockPaperScissors.cs b/RockPaperScissors/RockPaperScissors.cs index 0ebeffba..11ffbac4 100644 --- a/RockPaperScissors/RockPaperScissors.cs +++ b/RockPaperScissors/RockPaperScissors.cs @@ -24,58 +24,69 @@ public static void Main() { Console.WriteLine("Hand 1 wins"); } - else + else if (outCome == 2) { Console.WriteLine("Hand 2 wins"); - } try { - + } else { + Console.WriteLine("Please enter a valid hand"); + Console.ReadLine(); + } + } public static int CompareHands(string hand1, string hand2) { - - // Your code here - if (hand1 == hand2) - { - return 0; - } - else if (hand1 == "rock" && hand2 == "scissors") - { - return 1; - } - else if (hand1 == "rock" && hand2 == "paper") - { - return 2; - } - else if (hand1 == "scissors" && hand2 == "rock") + try { - return 1; - } - else if (hand1 == "scissors" && hand2 == "paper") - { - return 1; - // } else if (hand1 == hand2) - // { - // Console.WriteLine("Tie"); - // } else if (hand1 == "Paper" && hand2 == "Paper") - // { - // Console.WriteLine("Tie"); - } - else if (hand1 == "paper" && hand2 == "scissors") - { - return 2; - } - else if (hand1 == "paper" && hand2 == "rock") - { - return 1; + // Your code here + if (hand1 == hand2) + { + return 0; + } + else if (hand1 == "rock" && hand2 == "scissors") + { + return 1; + } + else if (hand1 == "rock" && hand2 == "paper") + { + return 2; + } + else if (hand1 == "scissors" && hand2 == "rock") + { + return 1; + } + else if (hand1 == "scissors" && hand2 == "paper") + { + return 1; + // } else if (hand1 == hand2) + // { + // Console.WriteLine("Tie"); + // } else if (hand1 == "Paper" && hand2 == "Paper") + // { + // Console.WriteLine("Tie"); + } + else if (hand1 == "paper" && hand2 == "scissors") + { + return 2; + } + else if (hand1 == "paper" && hand2 == "rock") + { + return 1; + } + else + { + throw new Exception("Please enter a valid hand!"); + + } } - else + catch { - throw new Exception("Please enter a valid hand!"); + Console.WriteLine("Please enter another choice!"); + return 3; } - return 3; + } // public static bool test() // {