(C#) 6. 가위바위보 게임
Rock-Scissors-Paper Game
#
- 최초 작성일: 2021년 3월 21일(월)
##
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
namespace Rock_Paper_Scissors
{
class Program
{
static void Main(string[] args)
{
enum Choice
{
// 0:가위 1:바위 2:보
const int ROCK = 0;
const int SCISSOR = 2;
const int PAPER = 1;
}
Random rand = new Random();
int aiChoice = rand.Next(0, 3); // 0~2사이의 랜덤 값
int choice = Convert.ToInt32(Console.ReadLine());
switch (choice)
{
case 0:
Console.WriteLine("당신의 선택은 가위입니다.");
break;
case 1:
Console.WriteLine("당신의 선택은 바위입니다.");
break;
case 2:
Console.WriteLine("당신의 선택은 보입니다.");
break;
}
switch (aiChoice)
{
case 0:
Console.WriteLine("상대방의 선택은 가위입니다.");
break;
case 1:
Console.WriteLine("상대방의 선택은 바위입니다.");
break;
case 2:
Console.WriteLine("상대방의 선택은 보입니다.");
break;
}
// 승리 무승부 패배
if (choice == 0)
{
if (aiChoice == 0)
{
Console.WriteLine("무승부");
}
else if (aiChoice == 1)
{
Console.WriteLine("패배.");
}
else // choice == 2
{
Console.WriteLine("승리.");
}
}
else if (choice == 1)
{
if (aiChoice == 0)
{
Console.WriteLine("승리.");
}
else if (aiChoice == 1)
{
Console.WriteLine("무승부");
}
else // choice == 2
{
Console.WriteLine("패배.");
}
}
else // choice == 2
{
if (aiChoice == 0)
{
Console.WriteLine("패배.");
}
else if (aiChoice == 1)
{
Console.WriteLine("승리.");
}
else // choice == 2
{
Console.WriteLine("무승부");
}
}
}
}
}
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.