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
| #include <iostream> #include <string> #include <random>
using namespace std;
string text_temp(int num) { if (num == 1) { return "가위"; } else if (num == 2) { return "바위"; } else { return "보"; } }
int main() { int Count = 1; int player;
cout << "가위바위보" << endl;
random_device rd; mt19937 gen(rd());
uniform_int_distribution<int> dis(1, 3);
string com_out;
while (1) { int com = dis(gen);
cout << "가위(1)바위(2)보(3)종료(0) : "; cin >> player;
Count++;
if (player == 0) { cout << "종료" << endl; break; }
else if (player == com) { cout << "비겼습니다." << endl; cout << "상대(" << text_temp(com) << ") : 플레이어(" << text_temp(player) << ")" << endl; }
else if ((player == 1 && com == 3) || (player == 2 && com == 1) || (player == 3 && com == 2)) { cout << "이겼습니다." << endl; cout << "상대(" << text_temp(com) << ") : 플레이어(" << text_temp(player) << ")" << endl; }
else if (player > 3) { cout << "숫자는 1, 2, 3중에서만 입력해주세요." << endl; } else { cout << "졌습니다." << endl; cout << "상대(" << text_temp(com) << ") : 플레이어(" << text_temp(player) << ")" << endl; } }
return 0; }
|