Created
February 27, 2021 11:01
-
-
Save AnshAg2007/f1058be8e1f44564cdfa6ca153b259ba to your computer and use it in GitHub Desktop.
My first game in c#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Game | |
{ | |
class RockPaperScissor | |
{ | |
public static void Main(string[] args) | |
{ | |
var rand = new Random(); | |
while (true) | |
{ | |
// Random Choice Function | |
string[] choices = { | |
"rock", | |
"paper", | |
"scissor" | |
}; | |
int choice = rand.Next(choices.Length); | |
string ch = choices[choice]; | |
// Here i start making the game | |
Console.Write("Your Choice:\t"); | |
string inp = Console.ReadLine(); | |
// statements | |
if (inp == "scissor" && ch == "paper") | |
{ | |
Console.WriteLine("You chose scissor\nComputer chose paper\nYou won :)"); | |
} | |
else if (inp == "rock" && ch == "scissor") | |
{ | |
Console.WriteLine("You chose rock\nComputer chose scissor\nYou won :)"); | |
} | |
else if (inp == "paper" && ch == "rock") | |
{ | |
Console.WriteLine("You chose paper\nComputer chose rock\nYou won :)"); | |
} | |
else if (inp == ch) | |
{ | |
Console.WriteLine($"You chose {inp}\nComputer chose {ch}\nTie!"); | |
} | |
else | |
{ | |
Console.WriteLine($"You chose {inp}\nComputer chose {ch}\nYou lose :("); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment