Simulador carrera de caballos desarrollado en C++

2
#include <iostream> #include <ctime> #include <cstdlib> #include <iomanip> #include <string> #include <stdlib.h> #include <time.h> using namespace std; void temporizador(int s) { for(int i=time(NULL)+s;time(NULL)!=i;time(NULL)); } void cronometro_regresivo(int a) { for(int i=a; i>=0; i--) { cout<<"Cuenta regresiva: "; system("color B"); cout<<i<<endl; if(i==3) cout<<"\n\nLISTOS"; else if(i==0) cout<<"\n\nFUERA"; temporizador(1); system("cls"); } } void caballo(int color) { int i,j,k; srand(time(NULL)); system("color E"); int a=0,b=0,c=0,d=0,x=1; b=(rand()%6)+b; c=(rand()%6)+c; d=(rand()%6)+d; while(b<65) { b=b+(rand()%6);//Acumula el numero aleatorio c=c+(rand()%6);//y siempre sera mayor al anterior. d=d+(rand()%6); cout<<"TIEMPO "<<a<<" segundos."<<endl; cout<<"----------------------------------------------------------------"<<endl; if(x==1) { cout<<setw(65)<<"|M|"<<endl; cout<<setw(b+1)<<" //"<<(char)16<<endl; cout<<setw(b)<<" ===="<<endl; cout<<setw(b)<<"// //"<<endl; cout<<"----------------------------------------------------------------"<<endl; cout<<setw(65)<<"|E|"<<endl; cout<<setw(c+1)<<" //"<<(char)16<<endl; cout<<setw(c)<<" ===="<<endl; cout<<setw(c)<<"// //"<<endl; cout<<"----------------------------------------------------------------"<<endl; cout<<setw(65)<<"|T|"<<endl; cout<<setw(d+1)<<" //"<<(char)16<<endl; cout<<setw(d)<<" ===="<<endl; cout<<setw(d)<<"// //"<<endl;

description

Diseño de un simulador de carreras de caballos en C++, facil de hacer usando el tiempo como variable aleatoria

Transcript of Simulador carrera de caballos desarrollado en C++

Page 1: Simulador carrera de caballos desarrollado en C++

#include <iostream>#include <ctime>#include <cstdlib>#include <iomanip>#include <string>#include <stdlib.h>#include <time.h>using namespace std;void temporizador(int s){ for(int i=time(NULL)+s;time(NULL)!=i;time(NULL));}

void cronometro_regresivo(int a){ for(int i=a; i>=0; i--) { cout<<"Cuenta regresiva: "; system("color B"); cout<<i<<endl; if(i==3) cout<<"\n\nLISTOS"; else if(i==0) cout<<"\n\nFUERA"; temporizador(1); system("cls"); }}

void caballo(int color){ int i,j,k; srand(time(NULL)); system("color E"); int a=0,b=0,c=0,d=0,x=1; b=(rand()%6)+b; c=(rand()%6)+c; d=(rand()%6)+d; while(b<65) { b=b+(rand()%6);//Acumula el numero aleatorio c=c+(rand()%6);//y siempre sera mayor al anterior. d=d+(rand()%6); cout<<"TIEMPO "<<a<<" segundos."<<endl; cout<<"----------------------------------------------------------------"<<endl; if(x==1) { cout<<setw(65)<<"|M|"<<endl; cout<<setw(b+1)<<" //"<<(char)16<<endl; cout<<setw(b)<<" ===="<<endl; cout<<setw(b)<<"// //"<<endl; cout<<"----------------------------------------------------------------"<<endl; cout<<setw(65)<<"|E|"<<endl; cout<<setw(c+1)<<" //"<<(char)16<<endl; cout<<setw(c)<<" ===="<<endl; cout<<setw(c)<<"// //"<<endl; cout<<"----------------------------------------------------------------"<<endl; cout<<setw(65)<<"|T|"<<endl; cout<<setw(d+1)<<" //"<<(char)16<<endl; cout<<setw(d)<<" ===="<<endl; cout<<setw(d)<<"// //"<<endl;

Page 2: Simulador carrera de caballos desarrollado en C++

cout<<setw(65)<<"|A|"<<endl; cout<<"----------------------------------------------------------------"<<endl; temporizador(1); system("cls"); x=0; } else if(x==0) { cout<<setw(65)<<"|M|"<<endl; cout<<setw(b+1)<<" //"<<(char)16<<endl; cout<<setw(b)<<" ===="<<endl; cout<<setw(b)<<"\\ \\"<<endl; cout<<"----------------------------------------------------------------"<<endl; cout<<setw(65)<<"|E|"<<endl; cout<<setw(c+1)<<" //"<<(char)16<<endl; cout<<setw(c)<<" ===="<<endl; cout<<setw(c)<<"\\ \\"<<endl; cout<<"----------------------------------------------------------------"<<endl; cout<<setw(65)<<"|T|"<<endl; cout<<setw(d+1)<<" //"<<(char)16<<endl; cout<<setw(d)<<" ===="<<endl; cout<<setw(d)<<"\\ \\"<<endl; cout<<setw(65)<<"|A|"<<endl; cout<<"----------------------------------------------------------------"<<endl; temporizador(1); system("cls"); if(b>=60) { cout<<"\nCABALLO UNO GANADOR"<<endl; break; } else if(c>=60) { cout<<"\nCABALLO DOS GANADOR"<<endl; break; } else if(d>=60) { cout<<"\nCABALLO TRES GANADOR"<<endl; break; } x=1; } a++;

} cout<<"Tiempo: "<<a<<" segundos.";}

int main (){ system("cls"); cronometro_regresivo(6); caballo(8); system("pause>null");}