added backonestep method to retract steps from user and repaint panel
parent
6a505ef34d
commit
8dcb29d701
|
@ -108,6 +108,63 @@ public class GameGUI {
|
|||
madeMoves.push(logEntrance);
|
||||
}
|
||||
|
||||
public static void backOneStep(Stack<String> movesMade, JButton[][] buttons, String[][] colors, JPanel grid){
|
||||
try {
|
||||
String move = movesMade.pop();
|
||||
String[] line = move.split("\\.");
|
||||
String y = line[0];
|
||||
String x = line[1];
|
||||
String color = line[2];
|
||||
if(color.equals("W")){
|
||||
int i = Integer.parseInt(y);
|
||||
int j = Integer.parseInt(x);
|
||||
JButton b0 = buttons[i][j];
|
||||
b0.setOpaque(true);
|
||||
b0.setForeground(Color.WHITE);
|
||||
b0.setContentAreaFilled(true);
|
||||
b0.setBorderPainted(false);
|
||||
b0.setFocusPainted(false);
|
||||
b0.setBackground(Color.BLACK);
|
||||
buttons[i][j] = b0;
|
||||
String str = colors[i][j];
|
||||
String str0 = str.substring(0, str.length() - 1);
|
||||
colors[i][j] = str0;
|
||||
grid.repaint();
|
||||
gridUpdate(grid, buttons);
|
||||
}else if(color.equals("G")){
|
||||
int i = Integer.parseInt(y);
|
||||
int j = Integer.parseInt(x);
|
||||
JButton b0 = buttons[i][j];
|
||||
b0.setOpaque(true);
|
||||
b0.setForeground(Color.BLACK);
|
||||
b0.setContentAreaFilled(true);
|
||||
b0.setBorderPainted(false);
|
||||
b0.setFocusPainted(false);
|
||||
b0.setBackground(Color.WHITE);
|
||||
buttons[i][j] = b0;
|
||||
String str = colors[i][j];
|
||||
String str0 = str.substring(0, str.length() - 1);
|
||||
colors[i][j] = str0;
|
||||
gridUpdate(grid, buttons);
|
||||
} else if(color.equals("B")){
|
||||
int i = Integer.parseInt(y);
|
||||
int j = Integer.parseInt(x);
|
||||
JButton b0 = buttons[i][j];
|
||||
b0.setOpaque(true);
|
||||
b0.setForeground(Color.BLACK);
|
||||
b0.setContentAreaFilled(true);
|
||||
b0.setBorderPainted(false);
|
||||
b0.setFocusPainted(false);
|
||||
b0.setBackground(Color.lightGray);
|
||||
buttons[i][j] = b0;
|
||||
String str = colors[i][j];
|
||||
String str0 = str.substring(0, str.length() - 1);
|
||||
colors[i][j] = str0;
|
||||
gridUpdate(grid, buttons);
|
||||
}
|
||||
} catch(EmptyStackException e) {}
|
||||
}
|
||||
|
||||
public static void gridUpdate(JPanel grid, JButton[][] buttons){
|
||||
grid.removeAll();
|
||||
grid.repaint();
|
||||
|
|
Loading…
Reference in New Issue