mirror of
https://github.com/Cpt-Adok/SNAKE.git
synced 2026-01-25 11:34:06 +00:00
ajout de plein d'autre fonction
This commit is contained in:
@@ -2,43 +2,45 @@ package personnages;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* <p>la classe Player est la classe principale pour l'utilisation de toute
|
||||
* input et output que l'utilisateur peut faire.
|
||||
*/
|
||||
public class Player extends Personnage {
|
||||
private int[] coordinate;
|
||||
|
||||
/**
|
||||
* <p>le constructor definie les coordonnées de la tête et defini n.
|
||||
*
|
||||
* @param n est une variable qui contient le nombre de
|
||||
* tour avant l'augmentation de taille.
|
||||
* @param coordinate est un array de <strong>2 entiers</strong>
|
||||
* qui est <strong>{x, y}</strong>
|
||||
* @param n est une variable qui contient le nombre detour avant
|
||||
* l'augmentation de taille.
|
||||
* @param coordinate est un array de <strong>2 entiers</strong> qui
|
||||
* est représenté comme <strong>{x, y}</strong> et qui represente les
|
||||
* coordonnées de la tête du personnage.
|
||||
*/
|
||||
public Player(int n, int[] coordinate) {
|
||||
super(n, coordinate);
|
||||
this.coordinate = coordinate;
|
||||
}
|
||||
|
||||
public void changeCoordinate() {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
char value;
|
||||
String value;
|
||||
|
||||
do {
|
||||
value = scanner.nextLine().charAt(0);
|
||||
} while (!moveCoordinate((int)value));
|
||||
value = scanner.nextLine();
|
||||
} while (!moveCoordinate((int)'w'));
|
||||
|
||||
scanner.close();
|
||||
}
|
||||
|
||||
public int[] getCoordinate() {
|
||||
return coordinate;
|
||||
return coordinate.get(0);
|
||||
}
|
||||
|
||||
private boolean moveCoordinate(int keys) {
|
||||
switch (keys) {
|
||||
case 119: Mouvement.HAUT.editCoordinate(coordinate); break;
|
||||
case 115: Mouvement.BAS.editCoordinate(coordinate); break;
|
||||
case 97: Mouvement.GAUCHE.editCoordinate(coordinate); break;
|
||||
case 100: Mouvement.DROITE.editCoordinate(coordinate); break;
|
||||
case 119: Mouvement.HAUT.editCoordinate(getCoordinate()); break;
|
||||
case 115: Mouvement.BAS.editCoordinate(getCoordinate()); break;
|
||||
case 97: Mouvement.GAUCHE.editCoordinate(getCoordinate()); break;
|
||||
case 100: Mouvement.DROITE.editCoordinate(getCoordinate()); break;
|
||||
default: return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user