using System;
namespace MyFirstProgram
{
internal class Program
{
static void Main(string[] args) // main method
{
// 가위 바위 보: Rock Paper Scissors
Random random = new Random();
bool playAgain = true;
String player;
String computer;
String answer;
while (playAgain)
{
player = "";
computer = "";
answer = "";
while (player != "ROCK" && player != "PAPER" && player != "SCISSORS")
{
Console.Write("Enter ROCK, PAPER, or SCISSORS: ");
player = Console.ReadLine().ToUpper();
Console.WriteLine(player);
}
switch (random.Next(1, 4))
{
case 1:
computer = "ROCK";
break;
case 2:
computer = "PAPER";
break;
case 3:
computer = "SCISSORS";
break;
}
Console.WriteLine("Player: " + player);
Console.WriteLine("Computer: " + computer);
switch (player) {
case "ROCK":
if (computer == "ROCK")
{
Console.WriteLine("It's a draw!");
}
else if(computer == "PAPER")
{
Console.WriteLine("You lose!");
}
else
{
Console.WriteLine("You win!");
}
break;
case "PAPER":
if (computer == "PAPER")
{
Console.WriteLine("It's a draw!");
}
else if (computer == "SCISSORS")
{
Console.WriteLine("You lose!");
}
else
{
Console.WriteLine("You win!");
}
break;
case "SCISSORS":
if (computer == "SCISSORS")
{
Console.WriteLine("It's a draw!");
}
else if (computer == "ROCK")
{
Console.WriteLine("You lose!");
}
else
{
Console.WriteLine("You win!");
}
break;
}
Console.Write("Would you like to play again (Y/N): ");
answer = Console.ReadLine().ToUpper();
if (answer == "Y")
{
playAgain= true;
}
else
{
playAgain = false;
}
}
Console.WriteLine("Thanks for playing!");
}
}
}
728x90
'언어 > [C#]' 카테고리의 다른 글
[C#] 배열 Arrays (0) | 2023.03.12 |
---|---|
[C#] 계산기: Calculator (0) | 2023.03.12 |
[C#] 숫자 맞추기 게임 (number guess game) - 업다운 (up and down) (0) | 2023.03.01 |
[C#] 다중 for문 (nested for loop) (0) | 2023.03.01 |
[C#] for문 (for loop) (0) | 2023.03.01 |