Files
gomoku/src/Human.java
Aubin DORIVAL 7efba643b5 docs
2025-03-31 12:01:51 +02:00

66 lines
1.7 KiB
Java

import java.io.Console;
public class Human extends Player{
/**
* This class is an extends of the class Player, this allows the player to choose his move.
*/
//------------------Methods--------------------------
/**
* Return the coordinate of the move played by the player.
* @param board The actual Gomoku board.
* @return The cell of the move played.
*/
public GomokuCell chooseMove(GomokuBoard board){
Console cons = System.console();
int x=0,y=0;
boolean pass = false;
do{
do{
try {
System.out.println("Veuillez saisir le X");
x = Integer.parseInt( cons.readLine());
pass=true;
} catch (NumberFormatException e) {
System.out.println("Ce n'est pas un nombre !");
pass=false;
}
}
while(!pass);
do{
try {
System.out.println("Veuillez saisir le Y");
y = Integer.parseInt( cons.readLine());
pass=true;
} catch (NumberFormatException e) {
System.out.println("Ce n'est pas un nombre !");
pass=false;
}
}
while(!pass);
pass =board.get(x,y).isPlayable();
if(!pass)
{
System.out.println("Cette case n'est pas jouable !");
}
}
while(!pass);
System.out.println("Vous avez saisi : "+ x+", "+ y);
return board.get(x,y);
}
}