codigo:
Código
#include <iostream> #include <fstream> #include <cstdlib> #include <ctime> #include <string> using namespace std; int main(){ //generacion de caras del dado ( del 1 al 6 ) int norte,sur,este,oeste,random,cara1,cara2,cara3,cara4,cara5,cara6,face,Puntuacion = 0, partidasGanadas= 0,partidasEmpatadas = 0,partidasPerdidas = 0, puntuacionFinal = 0, eleccion1,cara,eJ,eC; bool salir = false; string eleccionJugador,reglas; ifstream leer_reglas; do{ cout << "Que quieres hacer?" << endl; cout << "1- Juega y tira el dado" << endl; cout << "6- Ver instrucciones" << endl; cout << "0- Salir" << endl; cin >> eleccion1; switch(eleccion1) { case 0: cout << "Puntuacion :" << Puntuacion << endl; cout << "Partidas Ganadas : " << partidasGanadas << endl; cout << "Partidas Perdidas : " << partidasPerdidas << endl; cout << "Partidas Empatadas : " << partidasEmpatadas << endl; cout << "Puntuacion final :" << puntuacionFinal << endl; cout << "Hasta luego!" << endl; cout <<"Pulse una enter para continuar...."; cin.fail(); cin.sync(); cin.get(); salir = true; break; case 6: leer_reglas.open("reglas.txt"); if(leer_reglas.is_open()){ while (!leer_reglas.fail() && reglas != "XXX" ){ getline ( leer_reglas,reglas); if (reglas != "XXX"){ cout << reglas << endl; } } leer_reglas.close(); } break; case 1: srand(time(0)); cout << "resultado del dado" << endl; for ( int i = 1; i <= 1; i++ ){ cout << 1 + (rand()%6) << endl; } srand (time(NULL)); random = 1+(rand()%24); if ( random == 0 ){ cara1 = 1; cara2 = 2; cara3 = 3; } else if ( random == 1 ){ cara1 = 1; cara2 = 3; cara3 = 5; } else if ( random == 2 ){ cara1 = 1; cara2 = 5; cara3 = 4; } else if ( random == 3 ){ cara1 = 1; cara2 = 4; cara3 = 2; } else if ( random == 4 ){ cara1 = 2; cara2 = 6; cara3 = 3; } else if ( random == 5 ){ cara1 = 2; cara2 =3; cara3 =1; } else if ( random == 6 ){ cara1 = 2; cara2 =4; cara3 =6; } else if ( random == 7 ){ cara1 =2; cara2 =1; cara3 =4; } else if ( random == 8 ){ cara1 =3; cara2 =5; cara3 =1; } else if ( random == 9 ){ cara1 =3; cara2 =1; cara3 =2; } else if ( random == 10 ){ cara1 =3; cara2 =2; cara3 =6; } else if ( random == 11 ){ cara1 =3; cara2 =5; cara3 =1; } else if ( random == 12){ cara1 =4; cara2 =2; cara3 =1; } else if ( random == 13 ){ cara1 =4; cara2 =1; cara3 =5; } else if ( random == 14 ){ cara1 =4; cara2 =5; cara3 =6; } else if ( random == 15 ){ cara1 =4; cara2 =6; cara3 =2; } else if ( random == 16 ){ cara1 =5; cara2 =6; cara3 =4; } else if ( random == 17 ){ cara1 =5; cara2 =4; cara3 =1; } else if ( random == 18 ){ cara1 =5; cara2 =1; cara3 =3; } else if ( random == 19 ){ cara1 =5; cara2 =3; cara3 =6; } else if ( random == 20 ){ cara1 =6; cara2 =5; cara3 =3; } else if ( random == 21 ){ cara1 =6; cara2 =3; cara3 =2; } else if ( random == 22 ){ cara1 =6; cara2 =2; cara3 =4; } else if ( random == 23 ){ cara1 =6; cara2 =4; cara3 =5; } cout << "Elige elemento ( 1-norte, 2-sur, 3-este, 4-oeste)" << endl; cin >> eJ; while((eJ != 1)&&(eJ != 2)&&(eJ != 3)&&(eJ != 4)) { cout << "Elemento desconocido. Intentelo de nuevo " << endl; cout << "Elige elemento ( 1-norte, 2-sur, 3-este, 4-oeste)" << endl; cin >> eJ; } switch(eJ){ case 1: eleccionJugador = "norte"; break; case 2: eleccionJugador = "sur"; break; case 3: eleccionJugador = "este"; break; case 4: eleccionJugador = "oeste"; break; } srand (time(NULL)); eC = 1+ rand ( ) % 6; switch(eC){ case 2: cout << "eleccion cpu: norte" << endl; cout << "Tu eleccion : " << eleccionJugador << endl; if ( (face == 1) || (eJ == 1)){ cout << "puntuacion" << endl; srand(time(0)); for ( int i = 1; i <= 1; i++ ){ cout << 1 + (rand()%6) << endl; } cara1 = cara2; cara2 = (cara1)-7; norte=true; sur=false; este=false; oeste=false; Puntuacion++; } else if (( face == 2) || (eJ == 1)){ cout << "puntuacion" << endl; srand(time(0)); for ( int i = 1; i <= 1; i++ ){ cout << 1 + (rand()%6) << endl; } cara2 = cara2; cara2 = (cara2)-7; norte=true; sur=false; este=false; oeste=false; Puntuacion++; } else if (( face == 3)|| ( eJ == 1)){ cout << "puntuacion" << endl; srand(time(0)); for ( int i = 1; i <= 1; i++ ){ cout << 1 + (rand()%6) << endl; } cara3= cara2; cara2 = (cara3)-7; norte=true; sur=false; este=false; oeste=false; Puntuacion++; } else if (( face == 4)|| ( eJ == 1 )){ cout << "puntuacion" << endl; srand(time(0)); for ( int i = 1; i <= 1; i++ ){ cout << 1 + (rand()%6) << endl; } cara4 = cara2; cara2 = (cara4)-7; norte=true; sur=false; este=false; oeste=false; Puntuacion++; } else if (( face == 5)|| ( eJ == 1 )){ cout << "puntuacion" << endl; srand(time(0)); for ( int i = 1; i <= 1; i++ ){ cout << 1 + (rand()%6) << endl; } cara5 = cara2; cara2 = (cara5)-7; norte=true; sur=false; este=false; oeste=false; Puntuacion++; } else if (( face == 6)|| ( eJ == 1 )){ cout << "puntuacion" << endl; cout << 1 + (rand()%6) << endl; srand(time(0)); for ( int i = 1; i <= 1; i++ ){ cout << 1 + (rand()%6) << endl; } cara6 = cara2; cara2 = (cara6)-7; norte=true; sur=false; este=false; oeste=false; Puntuacion++; } ;break; case 3: cout << "eleccion cpu: sur" << endl; cout << "Tu eleccion : " << eleccionJugador << endl; if ( (face == 1) || (eJ == 2) ){ cout << "puntuacion" << endl; Puntuacion++; srand(time(0)); for ( int i = 1; i <= 1; i++ ){ cout << 1 + (rand()%6) << endl; } cara2 = cara1; cara1 = (cara2)-7; norte=false; sur=true; este=false; oeste=false; } else if (( face == 2) || (eJ == 2) ){ cout << "puntuacion" << endl; Puntuacion++; srand(time(0)); for ( int i = 1; i <= 1; i++ ){ cout << 1 + (rand()%6) << endl; } cara2 = cara1; cara1 = (cara2)-7; norte=false; sur=true; este=false; oeste=false; } else if (( face == 3) || (eJ == 2) ){ cout << "puntuacion" << endl; srand(time(0)); for ( int i = 1; i <= 1; i++ ){ cout << 1 + (rand()%6) << endl; } cara3 = cara1; cara1 = (cara3)-7; norte=false; sur=true; este=false; oeste=false; Puntuacion++; } else if (( face == 4) || (eJ == 2) ){ cout << "puntuacion" << endl; Puntuacion++; srand(time(0)); for ( int i = 1; i <= 1; i++ ){ cout << 1 + (rand()%6) << endl; } cara4 = cara1; cara1 = ( cara4 )-7; norte=false; sur=true; este=false; oeste=false; } else if (( face == 5) || (eJ == 2) ){ cout << "puntuacion" << endl; Puntuacion++; srand(time(0)); for ( int i = 1; i <= 1; i++ ){ cout << 1 + (rand()%6) << endl; } cara5 = cara1; cara1 = ( cara5 )-7; norte=false; sur=true; este=false; oeste=false; } else if (( face == 6) || (eJ == 2) ){ cout << "puntuacion" << endl; Puntuacion++; srand(time(0)); for ( int i = 1; i <= 1; i++ ){ cout << 1 + (rand()%6) << endl; } cara6 = cara1; cara1 = (cara6)-7; norte=false; sur=true; este=false; oeste=false; } break; case 4: cout << "eleccion cpu: este" << endl; cout << "Tu eleccion : " << eleccionJugador << endl; if ((face == 1) || (eJ == 3) ){ cout << "puntuacion" << endl; Puntuacion++; srand(time(0)); for ( int i = 1; i <= 1; i++ ){ cout << 1 + (rand()%6) << endl; } cara1 = cara3; cara3 = (cara1)-7; norte=false; sur=false; este=true; oeste=false; } else if (( face == 2) || (eJ == 3) ){ cout << "puntuacion" << endl; Puntuacion++; srand(time(0)); for ( int i = 1; i <= 1; i++ ){ cout << 1 + (rand()%6) << endl; } cara2 = cara3; cara3 = (cara2)-7; norte=false; sur=false; este=true; oeste=false; } else if (( face == 3) || (eJ == 3) ){ cout << "puntuacion" << endl; Puntuacion++; srand(time(0)); for ( int i = 1; i <= 1; i++ ){ cout << 1 + (rand()%6) << endl; } cara3 = cara3; cara3 = (cara3)-7; norte=false; sur=false; este=true; oeste=false; } else if (( face == 4) || (eJ == 3) ){ cout << "puntuacion" << endl; Puntuacion++; srand(time(0)); for ( int i = 1; i <= 1; i++ ){ cout << 1 + (rand()%6) << endl; } cara4 = cara3; cara3 = (cara4)-7; norte=false; sur=false; este=true; oeste=false; } else if (( face == 5) || (eJ == 3) ){ cout << "puntuacion" << endl; Puntuacion++; srand(time(0)); for ( int i = 1; i <= 1; i++ ){ cout << 1 + (rand()%6) << endl; } cara5 = cara3; cara3 = (cara5)-7; norte=false; sur=false; este=true; oeste=false; } else if (( face == 6) || (eJ == 3) ){ cout << "puntuacion" << endl; Puntuacion++; srand(time(0)); for ( int i = 1; i <= 1; i++ ){ cout << 1 + (rand()%6) << endl; } cara6 = cara3; cara3 = (cara6)-7; norte=false; sur=false; este=true; oeste=false; } break; case 5: cout << "eleccion cpu: oeste" << endl; cout << "Tu eleccion : " << eleccionJugador << endl; if ( (face == 1) || (eJ == 4) ){ cout << "puntuacion" << endl; srand(time(0)); for ( int i = 1; i <= 1; i++ ){ cout << 1 + (rand()%6) << endl; } cara1 = cara4; cara4 = (cara1)-7; norte=false; sur=false; este=false; oeste=true; Puntuacion++; } else if (( face == 2) || (eJ == 4) ){ cout << "puntuacion" << endl; srand(time(0)); for ( int i = 1; i <= 1; i++ ){ cout << 1 + (rand()%6) << endl; } cara2=cara4; cara4=(cara2)-7; norte=false; sur=false; este=false; oeste=true; Puntuacion++; } else if (( face == 3) || (eJ == 4) ){ cout << "puntuacion" << endl; srand(time(0)); for ( int i = 1; i <= 1; i++ ){ cout << 1 + (rand()%6) << endl; } cara3 = cara4; cara4= (cara3)-7; norte=false; sur=false; este=false; oeste=true; Puntuacion++; } else if (( face == 4) || (eJ == 4) ){ cout << "puntuacion" << endl; srand(time(0)); for ( int i = 1; i <= 1; i++ ){ cout << 1 + (rand()%6) << endl; } cara4 = cara4; cara4 = (cara4)-7; norte=false; sur=false; este=false; oeste=true; Puntuacion++; } else if (( face == 5) || (eJ == 4) ){ cout << "puntuacion" << endl; srand(time(0)); for ( int i = 1; i <= 1; i++ ){ cout << 1 + (rand()%6) << endl; } cara5= cara4; cara4 = (cara5)-7; norte=false; sur=false; este=false; oeste=true; Puntuacion++; } else if (( face == 6) || (eJ == 4) ){ cout << "puntuacion" << endl; srand(time(0)); for ( int i = 1; i <= 1; i++ ){ cout << 1 + (rand()%6) << endl; } cara6 = cara4; cara4 = (cara6)-7; norte=false; sur=false; este=false; oeste=true; Puntuacion++; } break; } } }while (!salir); return 0; }
[MOD] El codigo se pone entre etiquetas, gracias.