Amélioration de l'algorithme, plusieurs tests mais utilisaiton CPU élevé à cause du MouseMotionListener et pas l'algo en lui même
This commit is contained in:
parent
895194cdf2
commit
4845a40c55
@ -63,21 +63,20 @@ public class Grille extends JPanel{
|
||||
}
|
||||
|
||||
public void hover(int column, int player) {
|
||||
Pion.setHighlightColor(player == Constants.PLAYER_ONE ? Constants.PLAYER_ONE_COLOR : Constants.PLAYER_TWO_COLOR );
|
||||
boolean found = false;
|
||||
for(int x = 0; x < this.column; x++) {
|
||||
for(int y = 0; y < this.row; y++) {
|
||||
for(int y = this.row - 1; y >= 0; y--) {
|
||||
this.grille[x][y].setHover(false);
|
||||
this.grille[x][y].setPturn(player);
|
||||
this.grille[x][y].repaint(); //On utilise un peu moins de CPU à redessiner uniquement chaque pion
|
||||
if(!found && x == column && this.grille[column][y].getPlayer() == Constants.EMPTY_PLAYER) {
|
||||
this.grille[column][y].setHover(true);
|
||||
this.grille[x][y].repaint(); //On utilise un peu moins de CPU à redessiner uniquement chaque pion
|
||||
found = true;
|
||||
}
|
||||
if(this.grille[x][y].getPlayer() == Constants.EMPTY_PLAYER) //Si on est sur un pion vide on passe à la colonne suivante (économise des calculs lorsque grille quasiment vide)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(column != -1) {
|
||||
for (int row = this.row - 1; row >= 0; row--) {
|
||||
if (this.grille[column][row].getPlayer() == Constants.EMPTY_PLAYER) {
|
||||
this.grille[column][row].setHover(true);
|
||||
this.grille[column][row].setPturn(player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.repaint();
|
||||
}
|
||||
}
|
@ -6,9 +6,9 @@ import fr.iutfbleau.projetAgile.Utils.Constants;
|
||||
|
||||
public class Pion extends JComponent{
|
||||
|
||||
private static Color HIGHLIGHT_COLOR = null;
|
||||
private int player;
|
||||
private boolean hover = false;
|
||||
private int pturn;
|
||||
|
||||
public static Dimension getPionMinimumSize() {
|
||||
return new Dimension(80,80);
|
||||
@ -27,7 +27,6 @@ public class Pion extends JComponent{
|
||||
this.setMaximumSize(new Dimension(150,150));
|
||||
this.setPreferredSize(new Dimension(120,120));
|
||||
this.player = player;
|
||||
this.pturn=0;
|
||||
}
|
||||
|
||||
public void setPlayer(int player) {
|
||||
@ -37,14 +36,15 @@ public class Pion extends JComponent{
|
||||
public void setHover(boolean b) {
|
||||
this.hover = b;
|
||||
}
|
||||
public void setPturn(int n){
|
||||
this.pturn=n;
|
||||
}
|
||||
|
||||
public int getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public static void setHighlightColor(Color c) {
|
||||
Pion.HIGHLIGHT_COLOR = c;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
Graphics g2 = g.create();
|
||||
@ -61,12 +61,7 @@ public class Pion extends JComponent{
|
||||
break;
|
||||
}
|
||||
if(this.hover) {
|
||||
if(this.pturn==Constants.PLAYER_ONE){
|
||||
g2.setColor(Color.RED);
|
||||
}
|
||||
if(this.pturn==Constants.PLAYER_TWO){
|
||||
g2.setColor(Color.YELLOW);
|
||||
}
|
||||
g2.setColor(Pion.HIGHLIGHT_COLOR);
|
||||
g2.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||
}
|
||||
g2.setColor(c);
|
||||
|
Loading…
Reference in New Issue
Block a user