SAE21_2022/Attente.java

67 lines
1.9 KiB
Java
Raw Normal View History

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Random;
import javax.swing.*;
public class Attente implements KeyListener {
public static final boolean FINI = true;
public static final boolean ENCOURS = false;
private Random rand;
private int number;
private int compteur;
private These notreThese;
private Cellules[][] grilleCellules;
private int[] coordGate;
public Attente(These unPerso, Cellules[][] grille, int[] coord){
this.notreThese = unPerso;
this.grilleCellules = grille;
this.compteur=0;
this.rand = new Random();
this.coordGate = coord;
}
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
this.grilleCellules[notreThese.getCoord()[0]][notreThese.getCoord()[1]].peindre(Cellules.VUE);
this.number = this.rand.nextInt(4);
if(this.number == 0){
this.notreThese.goRight();
} else if(this.number == 1){
this.notreThese.goDown();
} else if(this.number == 2){
this.notreThese.goLeft();
} else {
this.notreThese.goTop();
}
this.grilleCellules[notreThese.getCoord()[0]][notreThese.getCoord()[1]].peindre(Cellules.DESSUS);
this.compteur++;
if(this.notreThese.isArrived(this.coordGate[2], this.coordGate[3]) == These.ARRIVE){
JOptionPane.showMessageDialog(null, "Labyrinthe treminé en "+this.compteur+" coups !", "Information", JOptionPane.INFORMATION_MESSAGE);
System.exit(1);
}
}
}
@Override
public void keyReleased(KeyEvent e) {
// Ne rien faire ici
}
@Override
public void keyTyped(KeyEvent e) {
// Ne rien faire ici
}
public void checked(){
System.out.println("true");
}
}