Scusami se te lo dico ma stai imparando c++ da solo o ti insegna un cane?!
codice:
/* Script Rayan94 */
#include <cstdlib>
#include <iostream>
#include <ctime>
#include <conio.h>
using namespace std;
int punti_giocatore=0,punti_computer=0;
string jugada()
{
int sceltaComputer,max=3,min=1;
string cout_Computer;
sceltaComputer =( rand() % (max-min+1) ) + min;
if (sceltaComputer == 1){
cout_Computer="Sasso";
}
if (sceltaComputer == 2){
cout_Computer="Carta";
}
if (sceltaComputer == 3){
cout_Computer="Forbici";
}
return cout_Computer;
}
void play(string sceltaComputer,string sceltaGiocatore)
{
if(sceltaComputer=="Sasso" && sceltaGiocatore=="Sasso")
{
punti_giocatore=punti_giocatore+0;
punti_computer=punti_computer+0;
cout << "Parita'! " << endl << endl;
}
if(sceltaComputer=="Sasso" && sceltaGiocatore=="Carta")
{
punti_giocatore=punti_giocatore+1;
punti_computer=punti_computer+0;
cout << "Giocatore vince! " << endl << endl;
}
if(sceltaComputer=="Sasso" && sceltaGiocatore=="Forbici")
{
punti_giocatore=punti_giocatore+0;
punti_computer=punti_computer+1;
cout << "Computer vince! " << endl << endl;
}
if(sceltaComputer=="Carta" && sceltaGiocatore=="Carta")
{
punti_giocatore=punti_giocatore+0;
punti_computer=punti_computer+0;
cout << "Parita'! " << endl << endl;
}
if(sceltaComputer=="Carta" && sceltaGiocatore=="Forbici")
{
punti_giocatore=punti_giocatore+1;
punti_computer=punti_computer+0;
cout << "Giocatore vince! " << endl << endl;
}
if(sceltaComputer=="Carta" && sceltaGiocatore=="Sasso")
{
punti_giocatore=punti_giocatore+0;
punti_computer=punti_computer+1;
cout << "Computer vince! " << endl << endl;
}
if(sceltaComputer=="Forbici" && sceltaGiocatore=="Forbici")
{
punti_giocatore=punti_giocatore+0;
punti_computer=punti_computer+0;
cout << "Parita'! " << endl << endl;
}
if(sceltaComputer=="Forbici" && sceltaGiocatore=="Sasso")
{
punti_giocatore=punti_giocatore+1;
punti_computer=punti_computer+0;
cout << "Giocatore vince! " << endl << endl;
}
if(sceltaComputer=="Forbici" && sceltaGiocatore=="Carta")
{
punti_giocatore=punti_giocatore+0;
punti_computer=punti_computer+1;
cout << "Computer vince! " << endl << endl;
}
}
int main(int argc, char *argv[])
{
char scelta='_';
string sceltaComputer,sceltaGiocatore;
srand (time(NULL));
cout << "Si cominicia il gioco: " << endl << endl;
while(scelta!='f')
{
system("CLS");
cout << "Premi il tasto: " << endl << endl;
cout << "[1] - Sasso." << endl;
cout << "[2] - Carta." << endl;
cout << "[3] - Forbici." << endl;
cout << "[f] - Esci dal gioco." << endl;
cout << endl << "Scelta :" << endl << endl;
scelta=getch();
switch(scelta)
{
case '1':
{
sceltaComputer=jugada();
sceltaGiocatore="Sasso";
cout << "Il Giocatore ha scelto " << sceltaGiocatore << "." << endl <<endl;
cout << "Il Computer ha scelto " << sceltaComputer << "." << endl << endl;;
play(sceltaComputer,sceltaGiocatore);
cout << "Punti Giocatore: " << punti_giocatore << " " << "Punti Computer: " << punti_computer << endl;
getch();
break;
}
case '2':
{
sceltaComputer=jugada();
sceltaGiocatore="Carta";
cout << "Il Giocatore ha scelto " << sceltaGiocatore << "." << endl <<endl;
cout << "Il Computer ha scelto " << sceltaComputer << "." << endl << endl;
play(sceltaComputer,sceltaGiocatore);
cout << "Punti Giocatore: " << punti_giocatore << " " << "Punti Computer: " << punti_computer << endl;
getch();
break;
}
case '3':
{
sceltaComputer=jugada();
sceltaGiocatore="Forbici";
cout << "Il Giocatore ha scelto " << sceltaGiocatore << "." << endl <<endl;
cout << "Il Computer ha scelto " << sceltaComputer << "." << endl << endl;
play(sceltaComputer,sceltaGiocatore);
cout << "Punti Giocatore: " << punti_giocatore << " " << "Punti Computer: " << punti_computer << endl;
getch();
break;
}
}
}
system("CLS");
cout << "Punteggio finale: " << endl << endl;
cout << "Punti Giocatore: " << punti_giocatore << " " << "Punti Computer: " << punti_computer << endl << endl;
system("PAUSE");
return EXIT_SUCCESS;
}