#include #include // Richiesto per rand() e srand() #include // Richiesto per time() using namespace std; int main() { srand(time(0)); const int CARTA = 1, FORBICE = 2, SASSO = 3; int numeroCasuale, cartaGiocatore, cartaComputer; string nomeGiocatore, nomeCartaGiocatore, nomeCartaComputer; cout << "Benvenuto nel gioco della morra cinese, cominciamo..." << endl; cout << "Come ti chiami ? "; getline(cin,nomeGiocatore); cout << "Ciao " << nomeGiocatore << ", scegli la carta con cui giocare questa partita:" << endl; cout << endl; cout << "+------------+" << endl; cout << "| 1. CARTA |" << endl; cout << "| 2. FORBICE |" << endl; cout << "| 3. SASSO |" << endl; cout << "+------------+" << endl; cin >> cartaGiocatore; if (cartaGiocatore == CARTA) { nomeCartaGiocatore = "CARTA"; } else if (cartaGiocatore == FORBICE) { nomeCartaGiocatore = "FORBICE"; } else { nomeCartaGiocatore = "SASSO"; } cout << "Ok perfetto, ora il computer sta scegliendo una carta..." << endl; cartaComputer = (rand() % 2) + 1; if (cartaComputer == CARTA) { nomeCartaComputer = "CARTA"; } else if (cartaComputer == FORBICE) { nomeCartaComputer = "FORBICE"; } else { nomeCartaComputer = "SASSO"; } cout << "Fatto." << endl; cout << "Attendi, sto elaborando l'esito della partita..." << endl << endl; cout << "Il computer ha giocato " << nomeCartaComputer << endl << endl; if (cartaGiocatore == cartaComputer) { cout << "-> Esito: PAREGGIO <-" << endl; } else { if (cartaGiocatore == CARTA) { if (cartaComputer == SASSO) { cout << "-> Esito: HAI VINTO ! <-" << endl; } else { cout << "-> Esito: HAI PERSO ! <-" << endl; } } if (cartaGiocatore == FORBICE) { if (cartaComputer == SASSO) { cout << "-> Esito: HAI PERSO ! <-" << endl; } else { cout << "-> Esito: HAI VINTO ! <-" << endl; } } if (cartaGiocatore == SASSO) { if (cartaComputer == CARTA) { cout << "-> Esito: HAI PERSO ! <-" << endl; } else { cout << "-> Esito: HAI VINTO ! <-" << endl; } } } return 0; }