My Rock,Paper,Scissors Game

Joined
Jun 22, 2022
Messages
1
Reaction score
0
Hi, I'm begginer in C# and I made this simple game(better than nothing). If posible, rate my code. I would like some feedback.




static void Main(string[] args)
{
string repeat = "";
Console.WriteLine("Welcome to RPS game!");
while(repeat != "n")
{
Console.WriteLine("Choose one of the following options:\n1. rock\n2. paper\n3. scissors");
Console.WriteLine("-------------------------------------");
string playerChoice = Console.ReadLine();
Console.WriteLine("--------------------------");
Random AI = new Random();
int n = AI.Next(0, 3);

string[] choices = { "rock", "paper", "scissors" };

Console.WriteLine("User choose: " + playerChoice);
Console.WriteLine("AI choose: " + choices[n]);
Console.WriteLine("----------------------------");

if(playerChoice == "rock" && n == 0)
{
Console.WriteLine("Draw!");
}
else if( playerChoice == "rock" && n == 1)
{
Console.WriteLine("AI wins!");

}
else if(playerChoice == "rock" && n == 2)
{
Console.WriteLine("User wins!");
Console.Beep();
}
else if (playerChoice == "paper" && n == 0)
{
Console.WriteLine("User wins!");
Console.Beep();
}
else if (playerChoice == "paper" && n == 1)
{
Console.WriteLine("Draw!");
}
else if (playerChoice == "paper" && n == 2)
{
Console.WriteLine("AI wins!");

}
else if (playerChoice == "scissors" && n == 0)
{
Console.WriteLine("AI wins!");

}
else if (playerChoice == "scissors" && n == 1)
{
Console.WriteLine("User wins!");
Console.Beep();
}
else if (playerChoice == "scissors" && n == 2)
{
Console.WriteLine("User wins!");
Console.Beep();

}
else
{
Console.WriteLine("Error");
}
Console.WriteLine("Do you want to play again?(y/n)");
repeat = Console.ReadLine();
Console.WriteLine("--------------------------");
}
Console.ReadKey();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top