Last active
March 10, 2018 00:42
-
-
Save parzibyte/4df50073df0242f662be21e476646e50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void turnoDelJugadorDos() { | |
String coordenadas; | |
/* | |
Escuchar y dar bienvenida | |
*/ | |
serialJugadorDos.listen(); | |
serialJugadorDos.println("Bienvenido, jugador 2"); | |
int barcosDestruidos = 0; | |
boolean intentosAgotados = false, todosLosBarcosDestruidos = false; | |
do { | |
serialJugadorDos.println("Te quedan " + String(INTENTOS_MAXIMOS - intentosJugadorDos) + " intentos. Ingresa las coordenadas para realizar el ataque: "); | |
while (!serialJugadorDos.available()); | |
coordenadas = serialJugadorDos.readString(); | |
int x, y; | |
boolean deberiaRestarIntento = true; | |
if (esCoordenadaValida(coordenadas, x, y)) { | |
char objetivo = dispararYObtenerObjetivo(x, y); | |
switch (objetivo) { | |
case AGUA: | |
serialJugadorDos.println("Disparo no acertado. Le diste al agua."); | |
marcarDisparoNoAcertadoEn(x, y); | |
indicarDisparoErroneo(); | |
break; | |
case FRAGATA_1: | |
case FRAGATA_2: | |
case DESTRUCTOR_1: | |
case DESTRUCTOR_2: | |
case ACORAZADO_1: | |
case SUBMARINO_1: | |
case PORTA_AVIONES_1: | |
serialJugadorDos.println("Disparo acertado!"); | |
marcarDisparoAcertadoEn(x, y); | |
indicarDisparoAcertado(); | |
break; | |
case DISPARO_ACERTADO: | |
case DISPARO_NO_ACERTADO: | |
deberiaRestarIntento = false; | |
serialJugadorDos.println("Ya habias disparado a esas coordenadas. Intenta en otro lugar"); | |
break; | |
} | |
if (!hayMasInstanciasDe(objetivo)) { | |
apagarLedDe(objetivo); | |
barcosDestruidos++; | |
//Right here, restar los barcos | |
} | |
} else { | |
serialJugadorDos.println("Coordenadas invalidas o fuera de rango"); | |
deberiaRestarIntento = false; | |
} | |
if (deberiaRestarIntento) intentosJugadorDos++; | |
dibujarEscenario(); | |
intentosAgotados = intentosJugadorDos >= INTENTOS_MAXIMOS; | |
todosLosBarcosDestruidos = barcosDestruidos >= 7; | |
if (intentosAgotados || todosLosBarcosDestruidos) break; | |
} while (true); | |
if (todosLosBarcosDestruidos) { | |
jugadorDosGana(); | |
} else if (intentosAgotados) { | |
jugadorDosPierde(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment