-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRPSLS.cpp
64 lines (55 loc) · 1.95 KB
/
RPSLS.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
#include <iostream>
#include <stdlib.h>
#include <vector>
std::string pick_item(int, std::vector<std::string>);
int main() {
srand(time(NULL));
int computer = rand() % 5 + 1;
int user = 0;
std::string winner;
std::vector<std::string> actionNext = {"cuts", "covers", "crushes", "poisons", "smashes"};
std::vector<std::string> actionBeforeLast = {"decapitates", "disproves", "crushes", "eats", "vaporizes"};
std::vector<std::string> signs = {"Scissors", "Paper", "Rock", "Lizard", "Spock"};
std::string action;
std::cout << "=================================\n";
std::cout << "Rock Paper Scissors Lizard Spock!\n";
std::cout << "=================================\n";
std::cout << "1) ✌️\n";
std::cout << "2) ✋\n";
std::cout << "3) ✊\n";
std::cout << "4) 🤏\n";
std::cout << "5) 🖖\n";
std::cout << "shoot!\n\n";
std::cin >> user;
std::cout << "\n";
if(computer != user) {
if((user + 1) % 5 == computer % 5) {
action = pick_item(user, actionNext);
winner = "you";
}
if((user + 5 - 2) % 5 == computer % 5) {
action = pick_item(user, actionBeforeLast);
winner = "you";
}
if((computer + 1) % 5 == user % 5) {
action = pick_item(computer, actionNext);
winner = "computer";
}
if((computer + 5 - 2) % 5 == user % 5) {
action = pick_item(computer, actionBeforeLast);
winner = "computer";
}
if(winner == "computer") {
std::cout << pick_item(computer, signs) << " " << action << " " << pick_item(user, signs) << "\n";
std::cout << "And the winner is: " << winner << "!\n";
} else if (winner == "you") {
std::cout << pick_item(user, signs) << " " << action << " " << pick_item(computer, signs) << "\n";
std::cout << "And the winner is: " << winner << "!\n";
}
} else
std::cout << "The game ended in a draw\n";
return 0;
}
std::string pick_item(int index, std::vector<std::string> items) {
return items[index - 1];
}