Created
March 9, 2018 23:49
-
-
Save parzibyte/665fc10cd8b1c24901586018da05a89e 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 pedirUbicacionDeBarcos() { | |
serialJugadorUno.listen(); | |
serialJugadorUno.println("Bienvenido, jugador 1. Es hora de ubicar tus barcos"); | |
String coordenadas; | |
int barcos = 7, | |
barcosCompletados = 0; | |
do { | |
String nombreBarco = ""; | |
switch (barcosCompletados) { | |
case 0: | |
nombreBarco = "Fragata 1"; | |
break; | |
case 1: | |
nombreBarco = "Fragata 2"; | |
break; | |
case 2: | |
nombreBarco = "Destructor 1"; | |
break; | |
case 3: | |
nombreBarco = "Destructor 2"; | |
break; | |
case 4: | |
nombreBarco = "Acorazado"; | |
break; | |
case 5: | |
nombreBarco = "Submarino"; | |
break; | |
case 6: | |
nombreBarco = "Porta aviones"; | |
break; | |
} | |
serialJugadorUno.println("Introduce las coordenadas de " + nombreBarco + ""); | |
while (!serialJugadorUno.available()); | |
coordenadas = serialJugadorUno.readString(); | |
int x, y; | |
if (esCoordenadaValida(coordenadas, x, y)) { | |
switch (barcosCompletados) { | |
case 0: | |
//Fragata 1 | |
if (intentarDibujarBarco(x, y, FRAGATA_1, LONGITUD_FRAGATAS)) { | |
dibujarEscenario(); | |
barcosCompletados++; | |
encenderLedDe(FRAGATA_1); | |
} else { | |
serialJugadorUno.println("Coordenadas correctas, pero ya existe un barco en esa posición. Intenta de nuevo"); | |
} | |
break; | |
case 1: | |
//Fragata 2 | |
if (intentarDibujarBarco(x, y, FRAGATA_2, LONGITUD_FRAGATAS)) { | |
dibujarEscenario(); | |
barcosCompletados++; | |
encenderLedDe(FRAGATA_2); | |
} else { | |
serialJugadorUno.println("Coordenadas correctas, pero ya existe un barco en esa posición. Intenta de nuevo"); | |
} | |
break; | |
case 2: | |
//Destructor 1 | |
if (intentarDibujarBarco(x, y, DESTRUCTOR_1, LONGITUD_DESTRUCTORES)) { | |
dibujarEscenario(); | |
barcosCompletados++; | |
encenderLedDe(DESTRUCTOR_1); | |
} else { | |
serialJugadorUno.println("Coordenadas correctas, pero ya existe un barco en esa posición. Intenta de nuevo"); | |
} | |
break; | |
case 3: | |
//Destructor 2 | |
if (intentarDibujarBarco(x, y, DESTRUCTOR_2, LONGITUD_DESTRUCTORES)) { | |
dibujarEscenario(); | |
barcosCompletados++; | |
encenderLedDe(DESTRUCTOR_2); | |
} else { | |
serialJugadorUno.println("Coordenadas correctas, pero ya existe un barco en esa posición. Intenta de nuevo"); | |
} | |
break; | |
case 4: | |
//Acorazado 1 | |
if (intentarDibujarBarco(x, y, ACORAZADO_1, LONGITUD_ACORAZADOS)) { | |
dibujarEscenario(); | |
barcosCompletados++; | |
encenderLedDe(ACORAZADO_1); | |
} else { | |
serialJugadorUno.println("Coordenadas correctas, pero ya existe un barco en esa posición. Intenta de nuevo"); | |
} | |
break; | |
case 5: | |
//Submarino 1 | |
if (intentarDibujarBarco(x, y, SUBMARINO_1, LONGITUD_SUBMARINOS)) { | |
dibujarEscenario(); | |
barcosCompletados++; | |
encenderLedDe(SUBMARINO_1); | |
} else { | |
serialJugadorUno.println("Coordenadas correctas, pero ya existe un barco en esa posición. Intenta de nuevo"); | |
} | |
break; | |
case 6: | |
//Porta aviones 1 | |
if (intentarDibujarBarco(x, y, PORTA_AVIONES_1, LONGITUD_PORTA_AVIONES)) { | |
dibujarEscenario(); | |
barcosCompletados++; | |
encenderLedDe(PORTA_AVIONES_1); | |
} else { | |
serialJugadorUno.println("Coordenadas correctas, pero ya existe un barco en esa posición. Intenta de nuevo"); | |
} | |
break; | |
} | |
} else { | |
serialJugadorUno.println("Coordenadas incorrectas o fuera de rango. Recuerda que debes introducirlas en el formato x,y (con la coma incluida)"); | |
} | |
coordenadas = ""; | |
} while (barcosCompletados < barcos); | |
serialJugadorUno.println("Se ha terminado tu tiempo. Turno del jugador 2"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment