Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ----------CODIGO PRINCIPAL DEL JUEGO-----------
- int vidaJugador = 100;
- string nombreJugador = ingresarNombre();
- int armaJugador = seleccionarArma(nombreJugador);
- bool lucharActivo = deseaLuchar();
- while (lucharActivo)
- {
- iniciarBatalla(nombreJugador,vidaJugador,armaJugador);
- lucharActivo = deseaReiniciarLucha();
- }
- Console.Clear();
- Console.WriteLine("Muchas gracias por jugar!");
- //-------------------FUNCIONES---------------------
- bool deseaLuchar()
- {
- bool response = false;
- int opcion;
- do
- {
- Console.WriteLine("¿Querés luchar? 1) Si 2) No");
- opcion = int.Parse(Console.ReadLine());
- Console.Clear();
- switch (opcion)
- {
- case 1:
- response = true;
- break;
- case 2:
- response = false;
- break;
- default:
- Console.WriteLine("El ingreso es incorrecto.");
- break;
- }
- } while (opcion < 1 || opcion > 2);
- return response;
- }
- bool deseaReiniciarLucha()
- {
- int opcion;
- do
- {
- Console.WriteLine("¿Querés reiniciar la luchar? 1) Si 2) No");
- opcion = int.Parse(Console.ReadLine());
- Console.Clear();
- if (opcion < 1 || opcion > 2)
- Console.WriteLine("El ingreso es incorrecto.");
- } while (opcion < 1 || opcion > 2);
- if (opcion == 1)
- return true;
- else
- return false;
- }
- string ingresarNombre()
- {
- string nombre = "";
- do
- {
- Console.WriteLine("Ingresá tu nombre para comenzar a jugar:");
- nombre = Console.ReadLine();
- Console.Clear();
- if (nombre == null || nombre.Length < 8)
- Console.WriteLine("Tu ingreso debe tener al menos 8 caracteres.");
- } while (nombre == null || nombre.Length < 8 );
- return nombre;
- }
- int seleccionarArma(string nombre)
- {
- const int ESPADA = 10;
- const int HACHA = 7;
- const int DAGA = 3;
- int opcionesDeMenu;
- int armaSeleccionada = 0;
- do
- {
- Console.WriteLine("Bien, " + nombre + ". Elegí tu arma: 1) Espada 2) Hacha 3) Daga");
- opcionesDeMenu = int.Parse(Console.ReadLine());
- switch (opcionesDeMenu)
- {
- case 1:
- armaSeleccionada = ESPADA;
- break;
- case 2:
- armaSeleccionada = HACHA;
- break;
- case 3:
- armaSeleccionada = DAGA;
- break;
- default:
- Console.WriteLine("El ingreso es incorrecto");
- break;
- }
- } while (armaSeleccionada == 0);
- return armaSeleccionada;
- }
- bool atacarEnemigo(string nombre,int vidaJugador, int arma, int vidaMonstruo)
- {
- do
- {
- Console.WriteLine("Presiona 1 para atacar:");
- int atacar = int.Parse(Console.ReadLine());
- Console.Clear();
- if (atacar == 1)
- {
- vidaMonstruo -= arma;
- Console.WriteLine("La vida de el monstruo ahora es de " + vidaMonstruo + ".");
- Random ataqueMonstruo = new Random();
- int ataqueM = ataqueMonstruo.Next(1, 15);
- vidaJugador -= ataqueM;
- Console.WriteLine("El monstruo también ha atacado con un daño de " + ataqueM + ". Tu vida es de " + vidaJugador + ".");
- }
- else
- {
- Console.WriteLine("El ingreso es incorrecto.");
- }
- } while (vidaMonstruo > 0 && vidaJugador > 0);
- if (vidaJugador > vidaMonstruo)
- return true;
- else
- return false;
- }
- void iniciarBatalla(string nombre, int vida, int arma)
- {
- int vidaMonstruo = 100;
- Console.WriteLine("El monstruo ha ingresado a la sala. Su vida es de " + vidaMonstruo + ".");
- bool victoria = atacarEnemigo(nombre, vida, arma, vidaMonstruo);
- if (victoria)
- Console.WriteLine("El monstruo fue derrotado.");
- else
- Console.WriteLine("Perdiste.");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement