Merge branch 'master' of https://github.tamu.edu/brj2013/Breakthrough
This commit is contained in:
commit
a8596f9ef2
2 changed files with 28 additions and 18 deletions
26
Client.java
26
Client.java
|
@ -21,6 +21,7 @@ import java.net.URL;
|
|||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.*;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
//import javax.swing.text.html.parser.ParserDelegator;
|
||||
|
||||
public class Client {
|
||||
|
@ -319,14 +320,23 @@ public class Client {
|
|||
String diff = "?";
|
||||
in.read(b, 0, 256);
|
||||
temp = String.valueOf(b).trim();
|
||||
if(gameMode == 3) {
|
||||
while(!diff.equals("EASY") && !diff.equals("MEDIUM") && !diff.equals("HARD")) {
|
||||
if(gameMode != 3) {
|
||||
while(!diff.equals("1") && !diff.equals("2") && !diff.equals("3")) {
|
||||
diff = JOptionPane.showInputDialog(frame, temp);//diff = stdIn.readLine();
|
||||
diff = diff.toUpperCase();
|
||||
if(!diff.equals("EASY") && !diff.equals("MEDIUM") && !diff.equals("HARD")) {
|
||||
//diff = diff.toUpperCase();
|
||||
if(!diff.equals("1") && !diff.equals("2") && !diff.equals("3")) {
|
||||
JOptionPane.showMessageDialog(null, diff + "\nInvalid difficulty.\n" + temp);
|
||||
}
|
||||
}
|
||||
if(diff.equals("1")) {
|
||||
userInput = "EASY";
|
||||
}
|
||||
else if(diff.equals("2")) {
|
||||
userInput = "MEDIUM";
|
||||
}
|
||||
else if(diff.equals("3")) {
|
||||
userInput = "HARD";
|
||||
}
|
||||
}
|
||||
output.println(userInput);
|
||||
}
|
||||
|
@ -339,9 +349,7 @@ public class Client {
|
|||
{
|
||||
while(!end) {
|
||||
char[] buffer = new char[256];
|
||||
if(in.available()) {
|
||||
in.read(buffer, 0, 256);
|
||||
}
|
||||
in.read(buffer, 0, 256);
|
||||
for(int i = 0; i < buffer.length; ++i) {
|
||||
if(Arrays.equals(Arrays.copyOfRange(buffer, i, i+9), go)) {
|
||||
frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
|
||||
|
@ -352,13 +360,13 @@ public class Client {
|
|||
System.out.println(String.valueOf(buffer).trim());
|
||||
window.updateBoard(String.valueOf(buffer).trim());
|
||||
while(!end && boardoutput.length() < 4) {
|
||||
if(in.available()) {
|
||||
if(in.ready()) {
|
||||
in.read(buffer, 0, 256);
|
||||
System.out.println(String.valueOf(buffer).trim());
|
||||
window.updateBoard(String.valueOf(buffer).trim());
|
||||
}
|
||||
String tempstring;
|
||||
Thread.sleep(100);
|
||||
Thread.sleep(1);
|
||||
if(!undoString.equals("")) {
|
||||
System.out.println(undoString);
|
||||
output.println(undoString);
|
||||
|
|
20
Server.cpp
20
Server.cpp
|
@ -76,7 +76,7 @@ int main(int argc, char *argv[])
|
|||
string final_move;
|
||||
|
||||
//Ask client about game type
|
||||
string introduction = "WELCOME\n1. Play against AI?\n2. Watch AI vs. AI?\nEnter choice: \n";
|
||||
string introduction = "WELCOME\n1. Play against AI?\n2. Watch AI vs. AI?3. Play Client vs. Client?\nEnter choice: \n";
|
||||
write(newsockfd, introduction.c_str(), introduction.length());
|
||||
n = read(newsockfd,info,255); //Reads choice as a string
|
||||
istringstream convert(info); //Converts the read string to an integer
|
||||
|
@ -85,14 +85,16 @@ int main(int argc, char *argv[])
|
|||
cout << "OK" << endl;
|
||||
bzero(info,256); //Resets info back to normal
|
||||
|
||||
string difficulty_select = "Choose Difficulty\n1. Easy\n2. Medium\n3. Hard\nEnter choice: \n";
|
||||
write(newsockfd, difficulty_select.c_str(), difficulty_select.length());
|
||||
n = read(newsockfd,info,255);
|
||||
istringstream con(info);
|
||||
string choice_difficulty = "EASY";
|
||||
con >> choice_difficulty;
|
||||
cout << "OK" << endl;
|
||||
bzero(info,256);
|
||||
if(choice != 3) {
|
||||
string difficulty_select = "Choose Difficulty\n1. Easy\n2. Medium\n3. Hard\nEnter choice: \n";
|
||||
write(newsockfd, difficulty_select.c_str(), difficulty_select.length());
|
||||
n = read(newsockfd,info,255);
|
||||
istringstream con(info);
|
||||
con >> choice_difficulty;
|
||||
cout << "OK" << endl;
|
||||
bzero(info,256);
|
||||
}
|
||||
|
||||
while(true) {
|
||||
|
||||
|
@ -131,7 +133,7 @@ int main(int argc, char *argv[])
|
|||
boardState = e.getBoard()->boardToString();
|
||||
cout << boardState << "testing\n\n";
|
||||
write(newsockfd, boardState.c_str(), boardState.length());//Display the board to the client (line by line)
|
||||
write(newsockfd2, boardState.c_str(), boardState.length());//Display the board to the client (line by line)
|
||||
//write(newsockfd2, boardState.c_str(), boardState.length());//Display the board to the client (line by line)
|
||||
e.getBoard()->changeTurns();
|
||||
e.getBoard()->setValidFalse();
|
||||
}
|
||||
|
|
Reference in a new issue