GUI Fully functional to play. Need to encorporate quit, undo, and game over conditions.
This commit is contained in:
parent
e8d9c61f86
commit
44e97150b1
2 changed files with 56 additions and 8 deletions
27
Client.java
27
Client.java
|
@ -30,6 +30,7 @@ public class Client {
|
||||||
private JPanel boardPanel;
|
private JPanel boardPanel;
|
||||||
private static final String Columns = "ABCDEFGH";
|
private static final String Columns = "ABCDEFGH";
|
||||||
public static final int BLACK = 0, WHITE = 1;
|
public static final int BLACK = 0, WHITE = 1;
|
||||||
|
public static String boardoutput = "";
|
||||||
|
|
||||||
public Client() {
|
public Client() {
|
||||||
initializeGui();
|
initializeGui();
|
||||||
|
@ -86,10 +87,12 @@ public class Client {
|
||||||
Insets buttonMargin = new Insets(0,0,0,0);
|
Insets buttonMargin = new Insets(0,0,0,0);
|
||||||
for(int r = 0; r < boardSquares.length; ++r) {
|
for(int r = 0; r < boardSquares.length; ++r) {
|
||||||
for(int c = 0; c < boardSquares.length; ++c) {
|
for(int c = 0; c < boardSquares.length; ++c) {
|
||||||
|
final int selectrow = r;
|
||||||
|
final int selectcol = c;
|
||||||
Action selectPiece = new AbstractAction("") {
|
Action selectPiece = new AbstractAction("") {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
sendLocation();
|
sendLocation(selectrow, selectcol);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
JButton b = new JButton();
|
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);
|
Scanner keyboard = new Scanner(System.in);
|
||||||
String hostname = args[0];
|
String hostname = args[0];
|
||||||
int portnum = Integer.parseInt(args[1]);
|
int portnum = Integer.parseInt(args[1]);
|
||||||
|
@ -233,11 +238,10 @@ public class Client {
|
||||||
frame.pack();
|
frame.pack();
|
||||||
frame.setMinimumSize(frame.getSize());
|
frame.setMinimumSize(frame.getSize());
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
|
userInput = stdIn.readLine();
|
||||||
|
output.println(userInput);
|
||||||
|
|
||||||
while(!end && (userInput != null)) {
|
while(!end) {
|
||||||
userInput = stdIn.readLine();
|
|
||||||
output.println(userInput);
|
|
||||||
output.flush();
|
|
||||||
char[] buffer = new char[256];
|
char[] buffer = new char[256];
|
||||||
in.read(buffer, 0, 256);
|
in.read(buffer, 0, 256);
|
||||||
for(int i = 0; i < buffer.length; ++i) {
|
for(int i = 0; i < buffer.length; ++i) {
|
||||||
|
@ -247,6 +251,13 @@ public class Client {
|
||||||
}
|
}
|
||||||
System.out.println(String.valueOf(buffer).trim());
|
System.out.println(String.valueOf(buffer).trim());
|
||||||
window.updateBoard(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();
|
output.close();
|
||||||
in.close();
|
in.close();
|
||||||
|
|
37
Server.cpp
37
Server.cpp
|
@ -20,6 +20,40 @@ void error(const char *msg)
|
||||||
exit(1);
|
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 main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int sockfd, newsockfd, portno;
|
int sockfd, newsockfd, portno;
|
||||||
|
@ -113,6 +147,9 @@ int main(int argc, char *argv[])
|
||||||
n = read(newsockfd,buffer,255);
|
n = read(newsockfd,buffer,255);
|
||||||
move = buffer;
|
move = buffer;
|
||||||
bzero(buffer,256);
|
bzero(buffer,256);
|
||||||
|
//cout << move << "\n\n";
|
||||||
|
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