Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <ctime>
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int round, i = 0;
- int player_score = 0;
- int pc_score = 0;
- int pc_choice = 0;
- char pc_to_human;
- char player_choice;
- // strings are completely unuseful but make the game easier to understand
- string pc_full_choice, player_full_choice = "";
- cout << "Giochiamo a morra cinese! "
- << "quanti turni vuoi giocare?" << endl;
- cin >> round;
- if (cin.fail()) {
- cout << "numero di round non valido" << endl;
- } else {
- for (i; i < round; i++) {
- cout << "----------------------------" << endl;
- cout << "Inserisci la tua giocata\n[c] => carta \n[f] => forbice\n[s] => "
- "sasso \n"
- << endl;
- cin >> player_choice;
- if (player_choice == 'c')
- player_full_choice = "carta";
- else if (player_choice == 'f')
- player_full_choice = "forbice";
- else if (player_choice == 's')
- player_full_choice = "sasso";
- if (player_choice != 'c' && player_choice != 'f' && player_choice != 's')
- cout << "la tua scelta non รจ valida" << endl;
- else {
- srand(time(0));
- pc_choice = rand() % 3;
- if (pc_choice == 0) {
- pc_to_human = 'c';
- pc_full_choice = "carta";
- } else if (pc_choice == 1) {
- pc_to_human = 'f';
- pc_full_choice = "forbice";
- } else {
- pc_to_human = 's';
- pc_full_choice = "sasso";
- }
- cout << "hai giocato " << player_full_choice << ", io gioco "
- << pc_full_choice << "\n"
- << endl;
- if (player_choice == pc_to_human)
- cout << "Hai pareggiato\n" << endl;
- else {
- switch (player_choice) {
- case 'c':
- if (pc_to_human == 's') {
- cout << "Hai vinto, carta batte sasso!\n" << endl;
- player_score++;
- } else {
- cout << "Hai perso, forbice batte carta!\n" << endl;
- pc_score++;
- }
- break;
- case 'f':
- if (pc_to_human == 'c') {
- cout << "Hai vinto, forbice batte carta!\n" << endl;
- player_score++;
- } else {
- cout << "Hai perso, sasso batte carta!\n" << endl;
- pc_score++;
- }
- break;
- case 's':
- if (pc_to_human == 'f') {
- cout << "Hai vinto, sasso batte forbice!\n" << endl;
- player_score++;
- } else {
- cout << "Hai perso, carta batte sasso!\n" << endl;
- pc_score++;
- }
- break;
- }
- }
- }
- }
- if (player_score > pc_score)
- cout << "===> RISULTATO FINALE: hai vinto " << player_score << " - "
- << pc_score << endl;
- else if (player_score == pc_score)
- cout << "===> RISULTATO FINALE: abbiamo pareggiato " << player_score
- << " - " << pc_score << endl;
- else
- cout << "==> RISULTATO FINALE: ho vinto io " << pc_score << " - "
- << player_score << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement