Added undo button.
This commit is contained in:
parent
e6edce2103
commit
df0272355b
3 changed files with 27 additions and 2 deletions
|
@ -547,6 +547,7 @@ void Board::interpret(string input, Board& tablero){
|
|||
input = myToUpper(input);
|
||||
|
||||
if (input == "UNDO"){
|
||||
cout << "TEST";
|
||||
undo(tablero);
|
||||
}
|
||||
|
||||
|
|
24
Client.java
24
Client.java
|
@ -33,6 +33,7 @@ public class Client {
|
|||
public static final int BLACK = 0, WHITE = 1;
|
||||
public static String boardoutput = "";
|
||||
public String oldBoard = "";
|
||||
public static String undoString = "";
|
||||
|
||||
public Client() {
|
||||
initializeGui();
|
||||
|
@ -109,7 +110,18 @@ public class Client {
|
|||
}
|
||||
|
||||
// fill the board.
|
||||
boardPanel.add(new JLabel(""));
|
||||
Action undoMove = new AbstractAction("") {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
undoMoveSend();
|
||||
}
|
||||
};
|
||||
ImageIcon icon = new ImageIcon( new BufferedImage(64, 64, BufferedImage.TYPE_INT_ARGB));
|
||||
JButton undo = new JButton("UNDO", icon);
|
||||
undo.setMargin(buttonMargin);
|
||||
undo.setAction(undoMove);
|
||||
undo.setBackground(new Color(150, 150, 150));
|
||||
boardPanel.add(undo);
|
||||
// fill the top row
|
||||
for(int c = 0; c < 8; c++) {
|
||||
boardPanel.add(new JLabel(Columns.substring(c, c + 1), SwingConstants.CENTER));
|
||||
|
@ -224,6 +236,10 @@ public class Client {
|
|||
oldBoard = board;
|
||||
}
|
||||
|
||||
public final void undoMoveSend() {
|
||||
undoString = "UNDO";
|
||||
}
|
||||
|
||||
public void sendLocation(int r, int c) {
|
||||
//debugging.
|
||||
System.out.println("row: " + r + " col: " + c);
|
||||
|
@ -296,6 +312,12 @@ public class Client {
|
|||
window.updateBoard(String.valueOf(buffer).trim());
|
||||
while(!end && boardoutput.length() < 4) {
|
||||
Thread.sleep(100);
|
||||
if(!undoString.equals("")) {
|
||||
System.out.println(undoString);
|
||||
output.println(undoString);
|
||||
output.flush();
|
||||
undoString = "";
|
||||
}
|
||||
}
|
||||
System.out.println(boardoutput);
|
||||
output.println(boardoutput);
|
||||
|
|
|
@ -31,6 +31,9 @@ string tempParse(string move) {
|
|||
for(int c = 0; c < 4; c++) {
|
||||
if(!isdigit(move[c])) {
|
||||
//cout << "\nfjdkjfjd\n";
|
||||
if(move.substr(0, 4) == "UNDO") {
|
||||
return "UNDO";
|
||||
}
|
||||
return move;
|
||||
}
|
||||
}
|
||||
|
@ -145,7 +148,6 @@ int main(int argc, char *argv[])
|
|||
bzero(buffer,256);
|
||||
//cout << move << "\n\n";
|
||||
move = tempParse(move);
|
||||
//cout << move << "\n\n";
|
||||
e.getBoard()->interpret(move,(*e.getBoard()));
|
||||
|
||||
if(e.getBoard()->isValid()) {
|
||||
|
|
Reference in a new issue