Updating branches.
This commit is contained in:
parent
7723ca5bbb
commit
2cd4345b6e
2 changed files with 39 additions and 10 deletions
BIN
Client.class
BIN
Client.class
Binary file not shown.
49
Client.java
49
Client.java
|
@ -10,13 +10,26 @@ import java.io.InputStreamReader;
|
|||
import java.util.Scanner;
|
||||
import java.io.DataInputStream;
|
||||
import java.util.Arrays;
|
||||
import javax.swing.*;
|
||||
import javax.swing.text.html.parser.ParserDelegator;
|
||||
|
||||
public class Client {
|
||||
|
||||
public static void main (String[] args) {
|
||||
Scanner keyboard = new Scanner(System.in);
|
||||
String hostname = args[0];
|
||||
int portnum = Integer.parseInt(args[1]);
|
||||
//keyboard.nextLine(); // used to buffer out extra space.
|
||||
ParserDelegator parserDelegator = new ParserDelegator();
|
||||
//System.out.println("parserDelegator set: "+ parserDelegator);
|
||||
JFrame frame = new JFrame("Breakthrough");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setSize(800, 600);
|
||||
frame.setLocationRelativeTo(null);
|
||||
|
||||
|
||||
//frame.pack();
|
||||
frame.setVisible(true);
|
||||
|
||||
try {
|
||||
Socket echoSocket = new Socket(hostname, portnum);
|
||||
|
@ -24,24 +37,40 @@ public class Client {
|
|||
BufferedReader in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream()));
|
||||
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
|
||||
|
||||
String userInput;
|
||||
String userInput = "test";
|
||||
char[] b = new char[256];
|
||||
in.read(b, 0, 256);
|
||||
System.out.println(b);
|
||||
|
||||
while((userInput = stdIn.readLine()) != null) {
|
||||
String temp = "<html><b>" + String.valueOf(b).replace("\n", "<br>").trim() + "</b></html>";
|
||||
JLabel label = new JLabel("<html>testing<html>");
|
||||
frame.getContentPane().add(label);
|
||||
System.out.print(b);
|
||||
String g = "GAME OVER";
|
||||
char[] go = new char[9];
|
||||
for(int x = 0; x < go.length; ++x) {
|
||||
go[x] = g.charAt(x);
|
||||
}
|
||||
boolean end = false;
|
||||
int c = 0;
|
||||
while(!end && (userInput != null)) {
|
||||
userInput = stdIn.readLine();
|
||||
output.println(userInput);
|
||||
output.flush();
|
||||
char[] buffer = new char[256];
|
||||
in.read(buffer, 0, 256);
|
||||
System.out.println(buffer);
|
||||
for(int i = 0; i < buffer.length - 10; ++i) {
|
||||
if(Arrays.copyOfRange(buffer, i, i+10).equals("GAME OVER")) {
|
||||
System.out.println("b");
|
||||
break;
|
||||
JLabel display = new JLabel(Arrays.toString(buffer));
|
||||
if(c == 0) {
|
||||
frame.getContentPane().remove(label);
|
||||
++c;
|
||||
}
|
||||
else {
|
||||
frame.getContentPane().remove(display);
|
||||
}
|
||||
frame.getContentPane().add(display);
|
||||
for(int i = 0; i < buffer.length; ++i) {
|
||||
if(Arrays.equals(Arrays.copyOfRange(buffer, i, i+9), go)) {
|
||||
end = true;
|
||||
}
|
||||
}
|
||||
System.out.println("testing.");
|
||||
}
|
||||
output.close();
|
||||
in.close();
|
||||
|
|
Reference in a new issue