forked from sonnynomnom/Codecademy-Learn-C-Plus-Plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rock_paper_scissors_lizard_spock.cpp
147 lines (138 loc) · 4.96 KB
/
rock_paper_scissors_lizard_spock.cpp
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* As Sheldon explains, "Scissors cuts paper, paper covers rock,
rock crushes lizard, lizard poisons Spock, Spock smashes scissors,
scissors decapitates lizard, lizard eats paper, paper disproves Spock,
Spock vaporizes rock, and as it always has, rock crushes scissors."
*/
#include <iostream>
#include <stdlib.h>
#include <ctime>
int main() {
// Get computer selection
srand (time(NULL));
int computer = rand() % 5 + 1;
int user;
std::cout << "1) Rock\n";
std::cout << "2) Paper\n";
std::cout << "3) Scissors\n";
std::cout << "4) Lizard\n";
std::cout << "5) Spock\n";
std::cout << "Choose your weapon: ";
std::cin >> user;
switch (user) {
case 1: // Human chooses Rock
switch (computer) {
case 1: // Computer chooses Rock
std::cout << "You tie! You both chose Rock!\n";
break;
case 2: // Computer chooses Paper
std::cout << "Computer wins! Paper covers Rock!\n";
break;
case 3: // Computer chooses Scissors
std::cout << "You win! Rock crushes Scissors!\n";
break;
case 4: // Computer chooses Lizard
std::cout << "You win! Rock crushes Lizard!\n";
break;
case 5: // Computer chooses Spock
std::cout << "Computer wins! Spock vaporizes Rock!\n";
break;
default: // Something went wrong with rand
std::cout << "Computer tried to cheat!?!\n";
break;
}
break;
case 2: // Human chooses Paper
switch (computer) {
case 1: // Computer chooses Rock
std::cout << "You win! Paper covers Rock!\n";
break;
case 2: // Computer chooses Paper
std::cout << "You tie! You both chose Paper!\n";
break;
case 3: // Computer chooses Scissors
std::cout << "Computer wins! Scissors cuts Paper!\n";
break;
case 4: // Computer chooses Lizard
std::cout << "Computer wins! Lizard eats Paper!\n";
break;
case 5: // Computer chooses Spock
std::cout << "You win! Paper disproves Spock!\n";
break;
default: // Something went wrong with rand
std::cout << "Computer tried to cheat!?!\n";
break;
}
break;
case 3: // Human chooses Scissors
switch (computer) {
case 1: // Computer chooses Rock
std::cout << "Computer wins! Rock crushes Scissors!\n";
break;
case 2: // Computer chooses Paper
std::cout << "You win! Scissors cuts Paper!\n";
break;
case 3: // Computer chooses Scissors
std::cout << "You tie! You both chose Scissors!\n";
break;
case 4: // Computer chooses Lizard
std::cout << "You win! Scissors decapitates Lizard!\n";
break;
case 5: // Computer chooses Spock
std::cout << "Computer wins! Spock smashes Scissors!\n";
break;
default: // Something went wrong with rand
std::cout << "Computer tried to cheat!?!\n";
break;
}
break;
case 4: // Human chooses Lizard
switch (computer) {
case 1: // Computer chooses Rock
std::cout << "Computer wins! Rock crushes Lizard!\n";
break;
case 2: // Computer chooses Paper
std::cout << "You win! Lizard eats Paper!\n";
break;
case 3: // Computer chooses Scissors
std::cout << "Computer wins! Scissors decapitates Lizard!\n";
break;
case 4: // Computer chooses Lizard
std::cout << "You tie! You both chose Lizard!\n";
break;
case 5: // Computer chooses Spock
std::cout << "You win! Lizard poisons Spock!\n";
break;
default: // Something went wrong with rand
std::cout << "Computer tried to cheat!?!\n";
break;
}
break;
case 5: // Human chooses Vulcan
switch (computer) {
case 1: // Computer chooses Rock
std::cout << "You win! Spock vaporizes Rock!\n";
break;
case 2: // Computer chooses Paper
std::cout << "Computer wins! Paper disproves Spock!\n";
break;
case 3: // Computer chooses Scissors
std::cout << "You win! Spock smashes Scissors!\n";
break;
case 4: // Computer chooses Lizard
std::cout << "Computer wins! Lizard poisons Spock!\n";
break;
case 5: // Computer chooses Spock
std::cout << "You tie! You both chose Spock!\n";
break;
default: // Something went wrong with rand
std::cout << "Computer tried to cheat!?!\n";
break;
}
break;
default: // Human chose outside 1-5 range
std::cout << "Did you try to cheat?!\n";
break;
}
std::cout << "Thank you for playing. Put me in a loop to play more!\n";
return 0;
}