Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <ctime>
- #include <windows.h>
- #define limpiar system("cls");
- using namespace std;
- struct usuario{
- string usuariog, contrasenyag;
- };
- int menu(){
- cout<<"--------------------"<<endl;
- cout<<" MENU "<<endl;
- cout<<"--------------------"<<endl<<endl;
- cout<<"1.Iniciar Sesion"<<endl<<endl;
- cout<<"2.Registrarse"<<endl<<endl;
- cout<<"3.Mostrar usuarios"<<endl<<endl;
- cout<<"4.Eliminar usuario"<<endl<<endl;
- cout<<"5.Salir"<<endl<<endl;
- int opcio;
- cin>>opcio;
- return opcio;
- }
- int menu2(){
- limpiar;
- cout<<"Selecciona minijuego"<<endl<<endl;
- cout<<"1.Gotta Catch Em All"<<endl<<endl;
- cout<<"2.Adivina el numero"<<endl<<endl;
- cout<<"3.Simon"<<endl<<endl;
- cout<<"4.Salir"<<endl<<endl;
- int opcio2;
- cin>>opcio2;
- return opcio2;
- }
- void adivinanumero(){
- srand(time(NULL));
- int opcion, numeroAleatorio, numeroUsuario, vidas;
- float probabilidad;
- menu:
- system("title Adivina el numero");
- system("color 0f");
- limpiar;
- vidas=5;
- cout << "Adivina el numero" << endl << endl;
- cout << "1. Facil -> (del 1 al 15)" << endl;
- cout << "2. Normal -> (del 1 al 25)" << endl;
- cout << "3. Dificil -> (del 1 al 50)" << endl;
- cout << "Elige la dificultad (escribe el numero): "; cin >> opcion;
- switch(opcion) {
- case 1:
- limpiar;
- system("title Dificultad facil. 1-15");
- system("color 0A");
- numeroAleatorio = rand() % 15 + 1;
- while (vidas > 0)
- {
- limpiar;
- cout << "Escribe un numero: "; cin >> numeroUsuario;
- if (numeroUsuario == numeroAleatorio)
- {
- limpiar;
- system("title Has ganado.");
- cout << "Bien! Has adivinado el numero en la dificultad facil." << endl;
- cout << "Probabilidades de ganar: 33.3%";
- Sleep(1000);
- goto menu;
- }
- if (numeroUsuario > numeroAleatorio)
- {
- limpiar;
- cout << "El numero aleatorio es MENOR que tu numero." << endl;
- vidas--;
- cout << "Vidas restantes: " << vidas << endl << endl;
- cout << "Volviendo..." << endl;
- Sleep(2000);
- }
- if (numeroUsuario < numeroAleatorio)
- {
- limpiar;
- cout << "El numero aleatorio es MAYOR que tu numero." << endl;
- vidas--;
- cout << "Vidas restantes: " << vidas << endl << endl;
- cout << "Volviendo..." << endl;
- Sleep(2000);
- }
- }
- limpiar;
- cout << "Has perdido en la dificultad facil!" << endl;
- cout << "Probabilidades de ganar: 33.3%" << endl << endl;
- cout << "El numero aleatorio era " << numeroAleatorio;
- Sleep (2000);
- goto menu;
- case 2:
- limpiar;
- system("title Dificultad normal. 1-25");
- system("color 0B");
- numeroAleatorio = rand() % 25 + 1;
- while (vidas > 0)
- {
- limpiar;
- cout << "Escribe un numero: "; cin >> numeroUsuario;
- if (numeroUsuario == numeroAleatorio)
- {
- limpiar;
- system("title Has ganado.");
- cout << "Muy bien! Has adivinado el numero en la dificultad normal." << endl;
- cout << "Probabilidades de ganar: 20%";
- Sleep(2000);
- goto menu;
- }
- if (numeroUsuario > numeroAleatorio)
- {
- limpiar;
- cout << "El numero aleatorio es MENOR que tu numero." << endl;
- vidas--;
- cout << "Vidas restantes: " << vidas << endl << endl;
- cout << "Volviendo..." << endl;
- Sleep(2000);
- }
- if (numeroUsuario < numeroAleatorio)
- {
- limpiar;
- cout << "El numero aleatorio es MAYOR que tu numero." << endl;
- vidas--;
- cout << "Vidas restantes: " << vidas << endl << endl;
- cout << "Volviendo..." << endl;
- Sleep(2000);
- }
- }
- limpiar;
- cout << "Has perdido!" << endl;
- cout << "Probabilidades de ganar: 20%" << endl << endl;
- cout << "El numero aleatorio era " << numeroAleatorio;
- Sleep (2000);
- goto menu;
- case 3:
- limpiar;
- system("title Dificultad difícil. 1-50");
- system("color 0E");
- numeroAleatorio = rand() % 50 + 1;
- while (vidas > 0)
- {
- limpiar;
- cout << "Escribe un numero: "; cin >> numeroUsuario;
- if (numeroUsuario == numeroAleatorio)
- {
- limpiar;
- system("title Has ganado.");
- cout << "Felicidades! Has adivinado el numero en la dificultad difícil." << endl;
- cout << "Probabilidades de ganar: 10%";
- Sleep (2000);
- goto menu;
- }
- if (numeroUsuario > numeroAleatorio)
- {
- limpiar;
- cout << "El numero aleatorio es MENOR que tu numero." << endl;
- vidas--;
- cout << "Vidas restantes: " << vidas << endl << endl;
- cout << "Volviendo..." << endl;
- Sleep(2000);
- }
- if (numeroUsuario < numeroAleatorio)
- {
- limpiar;
- cout << "El numero aleatorio es MAYOR que tu numero." << endl;
- vidas--;
- cout << "Vidas restantes: " << vidas << endl << endl;
- cout << "Volviendo..." << endl;
- Sleep(2000);
- }
- }
- limpiar;
- cout << "Has perdido :(" << endl;
- cout << "Probabilidades de ganar: 10%" << endl << endl;
- cout << "El numero aleatorio era " << numeroAleatorio;
- Sleep (2000);
- goto menu;
- }
- }
- void simon(){
- srand(time(NULL));
- // Lista de colores: 1f -> azul 2f -> verde 4f -> rojo 6f -> amarillo
- system ("title Simon");
- int nivel=1, comenzar, colorAleatorio, continuar=1, resultado=0, resultadoUsuario, iteraciones, n;
- cout << "El juego consiste en memorizar una secuencia de colores e intentar repetirla." << endl << endl << endl;
- cout << "Pulsa 0 cuando estes listo/lista!" << endl << endl;
- cin >> comenzar;
- while (comenzar!=0) {cin >> comenzar;}
- limpiar;
- while (continuar != 0 and nivel < 50)
- {
- cout << "NIVEL " << nivel;
- Sleep (1500);
- limpiar;
- iteraciones=nivel;
- while (iteraciones>=0)
- {
- colorAleatorio = rand() % 4 + 1;
- if (colorAleatorio == 1) system("color 1f");
- else if (colorAleatorio == 2) system("color 2f");
- else if (colorAleatorio == 3) system("color 4f");
- else system("color 6f");
- resultado = (resultado * 10) + colorAleatorio;
- iteraciones--;
- Sleep (1000);
- system ("color f");
- Sleep (1000);
- }
- limpiar;
- cout << "Azul -> 1" << endl << "Verde -> 2" << endl << "Rojo -> 3" << endl << "Amarillo -> 4" << endl << endl << endl << "INTRODUCE LA SECUENCIA DE COLORES: ";
- cin >> resultadoUsuario;
- if (resultado == resultadoUsuario) {
- limpiar;
- cout << "RESPUESTA CORRECTA!" << endl << "Para avanzar de nivel, pulsa 1." << endl << "Para salir, pulsa 0." << endl;
- if (nivel == 49) {cout << "ENHORABUENA!!!!! HAS CONSEGUIDO SUPERAR LOS 50 NIVELES";}
- cin >> continuar;
- }
- else
- {
- limpiar;
- cout << "RESPUESTA INCORRECTA :(" << endl << "Para reiniciar la partida, pulsa 1." << endl << "Para salir, pulsa 0." << endl;
- cin >> n;
- if (n==1) nivel=0;
- if (n==0) continuar=0;
- }
- nivel++;
- resultado=0;
- limpiar;
- }
- }
- void tipos(){
- srand(time(NULL));
- system ("title Gotta cath em all");
- // fuego gana a planta hielo
- // planta gana a tierra roca
- // hielo gana a planta tierra
- // tierra gana a roca fuego
- // roca gana a fuego hielo
- string usuario, IA, comenzar;
- int puntosUsuario = 0, puntosIA = 0, tipoIA, continuar=1;
- cout << "INSTRUCCIONES DEL JUEGO" << endl << endl << endl << "Tienes que escoger un tipo Pokemon, si el tipo de tu rival es mas eficaz, perderas, y viceversa." << endl
- << "El primero que llegue a 3 puntos gana la partida." << endl << endl <<
- " FUEGO gana a PLANTA y HIELO" << endl << " PLANTA gana a TIERRA y ROCA" << endl << " HIELO gana a PLANTA y TIERRA" << endl
- << " TIERRA gana a ROCA y FUEGO" << endl << " ROCA gana a FUEGO y HIELO";
- cout << endl << endl << "PULSA S CUANDO ESTES LISTO/LISTA" << endl;
- cin >> comenzar;
- while (comenzar != "s" and comenzar != "S") cin >> comenzar;
- limpiar;
- while (continuar == 1) {
- while (puntosUsuario != 3 and puntosIA != 3){
- cout << "TUS PUNTOS: " << puntosUsuario << endl << "PUNTOS RIVAL: " << puntosIA << endl << endl << "SELECCIONA UN TIPO POKEMON: " << endl << endl << "F --> Fuego"
- << endl << "P --> Planta" << endl << "H --> Hielo" << endl << "T --> Tierra" << endl << "R --> Roca" << endl << endl << "SELECCION: ";
- cin >> usuario;
- limpiar;
- cout << "3"; Sleep (500); limpiar;
- cout << "2"; Sleep (500); limpiar;
- cout << "1"; Sleep (500); limpiar;
- tipoIA = rand() % 5 + 1;
- if (tipoIA == 1) IA = "Fuego";
- else if (tipoIA == 2) IA = "Planta";
- else if (tipoIA == 3) IA = "Hielo";
- else if (tipoIA == 4) IA = "Tierra";
- else IA = "Roca";
- if (usuario == "F" or usuario == "f"){
- if (tipoIA == 1) {cout << "EMPATE" << endl << endl << endl << endl << "Tu tipo: Fuego" << endl << "Tipo Rival: " << IA; }
- if (tipoIA == 2) {cout << "GANAS LA RONDA" << endl << endl << endl << endl << "Tu tipo: Fuego" << endl << "Tipo Rival: " << IA; puntosUsuario++;}
- if (tipoIA == 3) {cout << "GANAS LA RONDA" << endl << endl << endl << endl << "Tu tipo: Fuego" << endl << "Tipo Rival: " << IA; puntosUsuario++;}
- if (tipoIA == 4) {cout << "PIERDES LA RONDA" << endl << endl << endl << endl << "Tu tipo: Fuego" << endl << "Tipo Rival: " << IA; puntosIA++;}
- if (tipoIA == 5) {cout << "PIERDES LA RONDA" << endl << endl << endl << endl << "Tu tipo: Fuego" << endl << "Tipo Rival: " << IA; puntosIA++;}
- Sleep (3000); limpiar;
- }
- if (usuario == "P" or usuario == "p"){
- if (tipoIA == 1) {cout << "PIERDES LA RONDA" << endl << endl << endl << endl << "Tu tipo: Planta" << endl << "Tipo Rival: " << IA; puntosIA++;}
- if (tipoIA == 2) {cout << "EMPATE" << endl << endl << endl << endl << "Tu tipo: Planta" << endl << "Tipo Rival: " << IA; }
- if (tipoIA == 3) {cout << "PIERDES LA RONDA" << endl << endl << endl << endl << "Tu tipo: Planta" << endl << "Tipo Rival: " << IA; puntosIA++;}
- if (tipoIA == 4) {cout << "GANAS LA RONDA" << endl << endl << endl << endl << "Tu tipo: Planta" << endl << "Tipo Rival: " << IA; puntosUsuario++;}
- if (tipoIA == 5) {cout << "GANAS LA RONDA" << endl << endl << endl << endl << "Tu tipo: Planta" << endl << "Tipo Rival: " << IA; puntosUsuario++;}
- Sleep (3000); limpiar;
- }
- if (usuario == "h" or usuario == "H"){
- if (tipoIA == 1) {cout << "PIERDES LA RONDA" << endl << endl << endl << endl << "Tu tipo: Hielo" << endl << "Tipo Rival: " << IA; puntosIA++;}
- if (tipoIA == 2) {cout << "GANAS LA RONDA" << endl << endl << endl << endl << "Tu tipo: Hielo" << endl << "Tipo Rival: " << IA; puntosUsuario++;}
- if (tipoIA == 3) {cout << "EMPATE" << endl << endl << endl << endl << "Tu tipo: Hielo" << endl << "Tipo Rival: " << IA; }
- if (tipoIA == 4) {cout << "GANAS LA RONDA" << endl << endl << endl << endl << "Tu tipo: Hielo" << endl << "Tipo Rival: " << IA; puntosUsuario++;}
- if (tipoIA == 5) {cout << "PIERDES LA RONDA" << endl << endl << endl << endl << "Tu tipo: Hielo" << endl << "Tipo Rival: " << IA; puntosIA++;}
- Sleep (3000); limpiar;
- }
- if (usuario == "t" or usuario == "T"){
- if (tipoIA == 1) {cout << "GANAS LA RONDA" << endl << endl << endl << endl << "Tu tipo: Tierra" << endl << "Tipo Rival: " << IA; puntosUsuario++;}
- if (tipoIA == 2) {cout << "PIERDES LA RONDA" << endl << endl << endl << endl << "Tu tipo: Tierra" << endl << "Tipo Rival: " << IA; puntosIA++;}
- if (tipoIA == 3) {cout << "PIERDES LA RONDA" << endl << endl << endl << endl << "Tu tipo: Tierra" << endl << "Tipo Rival: " << IA; puntosIA++;}
- if (tipoIA == 4) {cout << "EMPATE" << endl << endl << endl << endl << "Tu tipo: Tierra" << endl << "Tipo Rival: " << IA; }
- if (tipoIA == 5) {cout << "GANAS LA RONDA" << endl << endl << endl << endl << "Tu tipo: Tierra" << endl << "Tipo Rival: " << IA; puntosUsuario++;}
- Sleep (3000); limpiar;
- }
- if (usuario == "r" or usuario == "R"){
- if (tipoIA == 1) {cout << "GANAS LA RONDA" << endl << endl << endl << endl << "Tu tipo: Roca" << endl << "Tipo Rival: " << IA; puntosUsuario++;}
- if (tipoIA == 2) {cout << "PIERDES LA RONDA" << endl << endl << endl << endl << "Tu tipo: Roca" << endl << "Tipo Rival: " << IA; puntosIA++;}
- if (tipoIA == 3) {cout << "GANAS LA RONDA" << endl << endl << endl << endl << "Tu tipo: Roca" << endl << "Tipo Rival: " << IA; puntosUsuario++;}
- if (tipoIA == 4) {cout << "PIERDES LA RONDA" << endl << endl << endl << endl << "Tu tipo: Roca" << endl << "Tipo Rival: " << IA; puntosIA++;}
- if (tipoIA == 5) {cout << "EMPATE" << endl << endl << endl << endl << "Tu tipo: Roca" << endl << "Tipo Rival: " << IA;}
- Sleep (3000); limpiar;
- }
- }
- if (puntosIA == 3) {cout << "HAS PERDIDO :(" << endl << endl << endl;}
- if (puntosUsuario == 3) {cout << "FELICIDADES, HAS GANADO!" << endl << endl << endl;}
- cout << "Para salir, pulsa 0." << endl << "Para volver a jugar, pulsa 1." << endl;
- cin >> continuar;
- if (continuar==1) {puntosUsuario=0; puntosIA=0; limpiar;}
- }
- }
- void iniciosesion(vector<usuario>& u, usuario& ug){
- string usuario, contrasenya;
- bool trobat=false;
- int i=0, error=0;
- ifstream fin("usuarios.txt");
- cout<<endl;
- while(error==0){
- cout << "INICIAR SESION" << endl << endl;
- cout<<"Usuario: "; cin>>usuario;
- cout<<"Contrasenya: "; cin>>contrasenya;
- while(!fin.eof()){
- fin>>ug.usuariog>>ug.contrasenyag;
- u.push_back(ug);
- }
- while(i<u.size() and !trobat){
- if(usuario==u[i].usuariog and contrasenya==u[i].contrasenyag) trobat=true;
- else i++;
- }
- if(trobat){
- error=1;
- int op2=menu2();
- switch(op2){
- case 1: limpiar;
- tipos();
- break;
- case 2: limpiar;
- adivinanumero();
- break;
- case 3: limpiar;
- simon();
- break;
- case 4: limpiar;
- break;
- }
- }
- else{
- cout<<endl<<"Error"<<endl<<"Usuario no registrado o datos mal introducidos."<<endl;
- Sleep (3000);
- limpiar;
- }
- }
- }
- void registrarse(vector<usuario>& u){
- usuario nuevo;
- ofstream fout("usuarios.txt",ios::app);
- cout<<endl;
- cout<<"Introduce tus datos"<<endl;
- cout<<"Nuevo usuario: "; cin>>nuevo.usuariog;
- cout<<"Nueva contrasenya: "; cin>>nuevo.contrasenyag;
- u.push_back(nuevo);
- for(int i=0;i<u.size();i++){
- fout<<u[i].usuariog<<" "<<u[i].contrasenyag<<endl;
- }
- limpiar;
- iniciosesion(u,nuevo);
- }
- void mostrarusuarios(vector<usuario>& u){
- ifstream fin("usuarios.txt");
- usuario ug;
- vector<usuario> U;
- char volver;
- while(!fin.eof()){
- fin>>ug.usuariog>>ug.contrasenyag;
- u.push_back(ug);
- }
- for(int i=0;i<u.size()-1;i++){
- cout<<"Usuario: "<<u[i].usuariog<<endl<<endl;
- }
- cout<<"Quieres volver al menu? (s/n)";
- cin>>volver;
- if(volver=='s'){
- limpiar;
- int op=menu();
- switch(op){
- case 1: limpiar;
- iniciosesion(U,ug);
- break;
- case 2: limpiar;
- registrarse(U);
- break;
- case 3: limpiar;
- mostrarusuarios(U);
- break;
- case 4: limpiar;
- break;
- case 5: limpiar;
- cout<<"Gracias por jugar!";
- Sleep (3000);
- }
- }
- else;
- }
- void eliminarusuario(vector<usuario>& u){
- ifstream fin("usuarios.txt");
- usuario ug;
- vector<usuario> U;
- char volver;
- int posicion;
- while(!fin.eof()){
- fin>>ug.usuariog>>ug.contrasenyag;
- u.push_back(ug);
- }
- cout<<"En que posicion se encuentra el usuario que quieres eliminar?: ";
- cin>>posicion;
- u.erase(u.begin()+posicion);
- cout<<"El usuario ha sido eliminado correctamente"<<endl;
- ofstream fout("usuarios.txt");
- for(int i=0;i<u.size();i++){
- fout<<u[i].usuariog<<" "<<u[i].contrasenyag<<endl;
- }
- cout<<"Quieres volver al menu? (s/n)";
- cin>>volver;
- if(volver=='s'){
- limpiar;
- int op=menu();
- switch(op){
- case 1: limpiar;
- iniciosesion(U,ug);
- break;
- case 2: limpiar;
- registrarse(U);
- break;
- case 3: limpiar;
- mostrarusuarios(U);
- break;
- case 4: limpiar;
- eliminarusuario(U);
- break;
- case 5: limpiar;
- cout<<"Gracias por jugar!";
- Sleep (3000);
- }
- }
- else;
- }
- int main(){
- vector<usuario> U;
- usuario ug;
- bool trobat=false;
- int op=menu();
- switch(op){
- case 1: limpiar;
- iniciosesion(U,ug);
- break;
- case 2: limpiar;
- registrarse(U);
- break;
- case 3: limpiar;
- mostrarusuarios(U);
- break;
- case 4: limpiar;
- eliminarusuario(U);
- break;
- case 5: limpiar;
- cout<<"Gracias por jugar!";
- Sleep (3000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement