GUI Fully functional to play. Need to encorporate quit, undo, and game over conditions.

This commit is contained in:
Alexander Huddleston 2015-10-29 22:18:52 -05:00
parent e8d9c61f86
commit 44e97150b1
2 changed files with 56 additions and 8 deletions

View file

@ -30,6 +30,7 @@ public class Client {
private JPanel boardPanel;
private static final String Columns = "ABCDEFGH";
public static final int BLACK = 0, WHITE = 1;
public static String boardoutput = "";
public Client() {
initializeGui();
@ -86,10 +87,12 @@ public class Client {
Insets buttonMargin = new Insets(0,0,0,0);
for(int r = 0; r < boardSquares.length; ++r) {
for(int c = 0; c < boardSquares.length; ++c) {
final int selectrow = r;
final int selectcol = c;
Action selectPiece = new AbstractAction("") {
@Override
public void actionPerformed(ActionEvent e) {
sendLocation();
sendLocation(selectrow, selectcol);
}
};
JButton b = new JButton();
@ -190,11 +193,13 @@ public class Client {
}
}
public void sendLocation() {
public void sendLocation(int r, int c) {
//debugging.
System.out.println("row: " + r + " col: " + c);
boardoutput += "" + r + "" + c;
}
public static void main (String[] args) {
public static void main (String[] args) throws InterruptedException {
Scanner keyboard = new Scanner(System.in);
String hostname = args[0];
int portnum = Integer.parseInt(args[1]);
@ -233,11 +238,10 @@ public class Client {
frame.pack();
frame.setMinimumSize(frame.getSize());
frame.setVisible(true);
while(!end && (userInput != null)) {
userInput = stdIn.readLine();
output.println(userInput);
output.flush();
while(!end) {
char[] buffer = new char[256];
in.read(buffer, 0, 256);
for(int i = 0; i < buffer.length; ++i) {
@ -247,6 +251,13 @@ public class Client {
}
System.out.println(String.valueOf(buffer).trim());
window.updateBoard(String.valueOf(buffer).trim());
while(boardoutput.length() < 4) {
Thread.sleep(100);
}
System.out.println(boardoutput);
output.println(boardoutput);
output.flush();
boardoutput = "";
}
output.close();
in.close();

View file

@ -20,6 +20,40 @@ void error(const char *msg)
exit(1);
}
string tempParse(string move) {
string output = "";
int tempa = move[0] - '0';
int tempb = move[1] - '0';
int tempc = move[2] - '0';
int tempd = move[3] - '0';
//cout << "move: " << move << " " << tempa << " " << tempb << " " << tempc << " " << tempd << "\n";
for(int c = 0; c < 4; c++) {
if(!isdigit(move[c])) {
//cout << "\nfjdkjfjd\n";
return move;
}
}
if(tempa == (tempc + 1)) {
//cout << "\nTest\n";
if(tempb == tempd) {
output = ((char)('A' + tempb)) + to_string(8 - tempa) + "_f";
}
else if(tempb == (tempd + 1)) {
output = ((char)('A' + tempb)) + to_string(8 - tempa) + "_l";
}
else if(tempb == (tempd - 1)) {
output = ((char)('A' + tempb)) + to_string(8 - tempa) + "_r";
}
}
else {
return move;
}
cout << "Debugging: " << output << "\n\n";
return output;
}
int main(int argc, char *argv[])
{
int sockfd, newsockfd, portno;
@ -113,6 +147,9 @@ int main(int argc, char *argv[])
n = read(newsockfd,buffer,255);
move = buffer;
bzero(buffer,256);
//cout << move << "\n\n";
move = tempParse(move);
//cout << move << "\n\n";
e.getBoard()->interpret(move,(*e.getBoard()));
if(e.getBoard()->isValid()) {