From df0272355b5a5a10fd11c74257860154e334a7d2 Mon Sep 17 00:00:00 2001 From: Alexander Huddleston Date: Mon, 2 Nov 2015 17:52:36 -0600 Subject: [PATCH] Added undo button. --- Board.cpp | 1 + Client.java | 24 +++++++++++++++++++++++- Server.cpp | 4 +++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Board.cpp b/Board.cpp index 7dde616..84a7a35 100644 --- a/Board.cpp +++ b/Board.cpp @@ -547,6 +547,7 @@ void Board::interpret(string input, Board& tablero){ input = myToUpper(input); if (input == "UNDO"){ + cout << "TEST"; undo(tablero); } diff --git a/Client.java b/Client.java index 3f76014..eee69c6 100755 --- a/Client.java +++ b/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)); @@ -223,6 +235,10 @@ public class Client { } oldBoard = board; } + + public final void undoMoveSend() { + undoString = "UNDO"; + } public void sendLocation(int r, int c) { //debugging. @@ -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); diff --git a/Server.cpp b/Server.cpp index b0c01f2..6acd853 100644 --- a/Server.cpp +++ b/Server.cpp @@ -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()) {