mirror of
https://github.com/Cpt-Adok/SNAKE.git
synced 2026-01-25 12:34:07 +00:00
ajout de plein de fonction et suppression des anciennes classes
This commit is contained in:
@@ -1,17 +1,46 @@
|
||||
package personnages;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Player extends Personnage {
|
||||
public Player(int size, int[] coordinate) {
|
||||
super(size, coordinate);
|
||||
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>
|
||||
*/
|
||||
public Player(int n, int[] coordinate) {
|
||||
super(n, coordinate);
|
||||
this.coordinate = coordinate;
|
||||
}
|
||||
|
||||
public void changeCoordinate(int keys) {
|
||||
public void changeCoordinate() {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
char value;
|
||||
|
||||
do {
|
||||
value = scanner.nextLine().charAt(0);
|
||||
} while (!moveCoordinate((int)value));
|
||||
|
||||
scanner.close();
|
||||
}
|
||||
|
||||
public int[] getCoordinate() {
|
||||
return coordinate;
|
||||
}
|
||||
|
||||
private boolean moveCoordinate(int keys) {
|
||||
switch (keys) {
|
||||
case 77: Mouvement.HAUT.editCoordinate(coordinate); // w
|
||||
case 73: Mouvement.BAS.editCoordinate(coordinate); // s
|
||||
case 61: Mouvement.GAUCHE.editCoordinate(coordinate); // a
|
||||
case 64: Mouvement.DROITE.editCoordinate(coordinate); // d
|
||||
default: break;
|
||||
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;
|
||||
default: return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user