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);
|
input = myToUpper(input);
|
||||||
|
|
||||||
if (input == "UNDO"){
|
if (input == "UNDO"){
|
||||||
|
cout << "TEST";
|
||||||
undo(tablero);
|
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 final int BLACK = 0, WHITE = 1;
|
||||||
public static String boardoutput = "";
|
public static String boardoutput = "";
|
||||||
public String oldBoard = "";
|
public String oldBoard = "";
|
||||||
|
public static String undoString = "";
|
||||||
|
|
||||||
public Client() {
|
public Client() {
|
||||||
initializeGui();
|
initializeGui();
|
||||||
|
@ -109,7 +110,18 @@ public class Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
// fill the board.
|
// 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
|
// fill the top row
|
||||||
for(int c = 0; c < 8; c++) {
|
for(int c = 0; c < 8; c++) {
|
||||||
boardPanel.add(new JLabel(Columns.substring(c, c + 1), SwingConstants.CENTER));
|
boardPanel.add(new JLabel(Columns.substring(c, c + 1), SwingConstants.CENTER));
|
||||||
|
@ -223,6 +235,10 @@ public class Client {
|
||||||
}
|
}
|
||||||
oldBoard = board;
|
oldBoard = board;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final void undoMoveSend() {
|
||||||
|
undoString = "UNDO";
|
||||||
|
}
|
||||||
|
|
||||||
public void sendLocation(int r, int c) {
|
public void sendLocation(int r, int c) {
|
||||||
//debugging.
|
//debugging.
|
||||||
|
@ -296,6 +312,12 @@ public class Client {
|
||||||
window.updateBoard(String.valueOf(buffer).trim());
|
window.updateBoard(String.valueOf(buffer).trim());
|
||||||
while(!end && boardoutput.length() < 4) {
|
while(!end && boardoutput.length() < 4) {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
|
if(!undoString.equals("")) {
|
||||||
|
System.out.println(undoString);
|
||||||
|
output.println(undoString);
|
||||||
|
output.flush();
|
||||||
|
undoString = "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
System.out.println(boardoutput);
|
System.out.println(boardoutput);
|
||||||
output.println(boardoutput);
|
output.println(boardoutput);
|
||||||
|
|
|
@ -31,6 +31,9 @@ string tempParse(string move) {
|
||||||
for(int c = 0; c < 4; c++) {
|
for(int c = 0; c < 4; c++) {
|
||||||
if(!isdigit(move[c])) {
|
if(!isdigit(move[c])) {
|
||||||
//cout << "\nfjdkjfjd\n";
|
//cout << "\nfjdkjfjd\n";
|
||||||
|
if(move.substr(0, 4) == "UNDO") {
|
||||||
|
return "UNDO";
|
||||||
|
}
|
||||||
return move;
|
return move;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,7 +148,6 @@ int main(int argc, char *argv[])
|
||||||
bzero(buffer,256);
|
bzero(buffer,256);
|
||||||
//cout << move << "\n\n";
|
//cout << move << "\n\n";
|
||||||
move = tempParse(move);
|
move = tempParse(move);
|
||||||
//cout << move << "\n\n";
|
|
||||||
e.getBoard()->interpret(move,(*e.getBoard()));
|
e.getBoard()->interpret(move,(*e.getBoard()));
|
||||||
|
|
||||||
if(e.getBoard()->isValid()) {
|
if(e.getBoard()->isValid()) {
|
||||||
|
|
Reference in a new issue