From a5671cab3936a5b60558dc04f25470a4d20174a6 Mon Sep 17 00:00:00 2001 From: Alexander Huddleston Date: Thu, 29 Oct 2015 13:32:48 -0500 Subject: [PATCH] Updating branch. --- Client.class | Bin 2962 -> 0 bytes Client.java | 135 +++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 110 insertions(+), 25 deletions(-) delete mode 100644 Client.class diff --git a/Client.class b/Client.class deleted file mode 100644 index 01f480af6c769c08d2557624dd93adf546800323..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2962 zcmZ`*Yjhh&75>JSw5!!Rdf0NZX_LBb8f538#7&)6c3f=P2~O?Ev0S@~d1Nh*Z6(sK zx>`9&%NtWDZGl30G*Bol)IfPOfvil_q&y3h*E#SP`jd0u7w7PY1C(%Q<%e91kI(Gv zy?4I*%{TYX>b3t|y$+xgzf*88#wFbE#{?!7G~fXR8Jv0?TOiRcr2x3M87tdJ*Va!RGmyi?hXB0#QU<=O5$ctw|f}!9hjLR^^v#8)fSTag7 zY%wj1VL`?@;XE(lf{ce0?5<^hSi!sT9>Mgz3f_nJ%lLo@|DXW=kVw5Kh7T)v1RoKh z9~HAl#qcrVcud665X55=9v3iA$oRN|d+-SXwG$GptYZJZ-IpDj1NywHFl?EKB%-imRxqcp29u zTvzc5e#qcI);BWPmYNtGQ}HAGSjA6pMa55rpg%*OgjYqfODcXYH2npBsp2*KO2x0m zk*~=(lo~vr;$*1#O(n-tC#b3GH;f6s>m%}2t#KY8xjd6ib&@kqAK>rhFnXOEW>8j4IATmdM@yB zlWJ!rw|>r!C(T09G^pp??p0{TM6Q&pwR-H7z-`@xsS6*R<94cSuNAD2qkT<}dJieJ zeO;*y9yi4nLaGy1FkA)YT;3jPm>H5FHkG8UlZ-ySSmXwo_HDv`1-nlA zmF6LQX+h7Id1}_Z;*$RxDMBn>%u3{$QCKS>9cf!OgJ2zA2!Gu1~78 zmeozy5u-Rr*3vh)ijT5s`!xj@l@tXaH}njNE04!y~>!xnApBiZ#lg^B{8 zq^AfkE4qX>z%6P#g@ha7rIJ3!aVvW1^Dq7y!02M_qp_dfcF>d2)7w!2yF?R)B#l1T z7=j-I7^FFcHXebOzVTpxs-hut8I2WqhC3QNM>;&6%kcJA;mcGYB|KHgnTWpvCE?Y) zJ_iBK8*Xe1H$31#)x69>ljij}*iuC>vv)@Yp@grBa7Lrhh^K<)gj7XKri!R*YOP>v z1=|wxs?p8tn*0$hp@bP;_9g9wxFymSxz)jK4sIt) zWETw%?ntOr?9N2qQb8<1j2yIUO%6IHFJq4uaIiPBFR>-$C+uKjS120Ng4drzR14B< zOElzQ|NV<0wshk!uBQlN=nZQH&79$U4Q{87;Dm zPLaJi8or3;H41kwhS`!3Nlw&E6O=)iUypr3BtxS6V{4aaah#;^-I?!W^5j(Zd_Jb`vR zMUl^94}I?T;t$w|*RdaeMjU^o)qlf5{0p5-!a>%ALo9^5STnlV4jg8?a5vk7d)NUa z*kN?DBzo9M9AOjaWv6j3n?*k>Vt_r2LG}oavWvv~8Ja(jHh*dYvTX_ diff --git a/Client.java b/Client.java index 54075ca..809f6fb 100755 --- a/Client.java +++ b/Client.java @@ -11,25 +11,109 @@ import java.util.Scanner; import java.io.DataInputStream; import java.util.Arrays; import javax.swing.*; -import javax.swing.text.html.parser.ParserDelegator; +import javax.*; +import java.awt.*; +import java.awt.geom.*; +//import javax.swing.text.html.parser.ParserDelegator; -public class Client { +public class Client extends JFrame { + + public Client() { + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + } + + public void drawBoard(String b) { + board = b; + bp = new BoardPanel(); + board = TrimBoard(); + JFrame frame = new JFrame("Breakthrough"); + frame.getContentPane().add(BorderLayout.CENTER, bp); + frame.setSize(800, 600); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + bp.DrawPieces(); + /* + Graphics test = getGraphics(); + test.clearRect(0, 0, 800, 600); + test.setColor(Color.black); + */ + //frame.getContentPane().add(test, BorderLayout.CENTER); + //this.paint(test); + //frame.repaint(); + } + + public String TrimBoard() { + String output = ""; + for(int i = 0; i < board.length(); ++i) { + if(board.charAt(i) == 'X') { + output += board.charAt(i); + } + + else if(board.charAt(i) == '_') { + output += board.charAt(i); + } + + else if(board.charAt(i) == 'O') { + output += board.charAt(i); + } + } + return output; + } + + class BoardPanel extends JPanel { + public void DrawPieces() { + Graphics g = getGraphics(); + g.clearRect(0, 0, 800, 600); + g.setColor(Color.black); + this.validate(); + //add("Center", new BoardCanvas()); + + //background.setRect(0.0, 0.0, 800.0, 600.0); + //back = background; + //back.setPaint(0, 0, 0); + //g.draw(background); + } + } + + class BoardCanvas extends Canvas { + public void paint(Graphics graphics) { + Graphics2D g = (Graphics2D) graphics; + + Shape pieces[] = new Shape[32]; + + int c = 0; + + Shape sh = new Ellipse2D.Double(0,0,100,100); + g.draw(sh); + + for(int x = 0; x < board.length(); ++x) { + if(board.charAt(x) == 'X') { + pieces[c] = new Ellipse2D.Double((((x%8) + 1)*10), ((x/8)*20), 10, 10); + c++; + } + + else if(board.charAt(x) == 'O') { + pieces[c] = new Ellipse2D.Double((((x%8) + 1)*10), ((x/8)*20), 10, 10); + c++; + } + } + + for(int s = 0; s < pieces.length; ++s) { + if(pieces[s] != null) { + g.draw(pieces[s]); + } + } + + } + } + 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); + Client window = new Client(); try { Socket echoSocket = new Socket(hostname, portnum); @@ -40,37 +124,34 @@ public class Client { String userInput = "test"; char[] b = new char[256]; in.read(b, 0, 256); - String temp = "" + String.valueOf(b).replace("\n", "
").trim() + "
"; - JLabel label = new JLabel("testing"); - frame.getContentPane().add(label); - System.out.print(b); + + String temp = String.valueOf(b).trim(); + System.out.print(temp); + //setBoard(temp); + //window.drawBoard(temp); + 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); - 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(String.valueOf(buffer).trim()); + window.drawBoard(String.valueOf(buffer).trim()); } output.close(); in.close(); @@ -82,4 +163,8 @@ public class Client { System.err.println("IOException: " + e.getMessage()); } } + + String board; + + BoardPanel bp; } \ No newline at end of file