From f9d63ea1bbe667aa193d4330aeb15dca6e87f205 Mon Sep 17 00:00:00 2001 From: Jerrett Date: Mon, 9 Sep 2013 13:06:35 +0100 Subject: [PATCH] Final commit Needs the commands to work --- Battleship$GameState.class | Bin 1063 -> 1063 bytes Battleship.class | Bin 6113 -> 6630 bytes Battleship.java | 87 +++++++------ Command.java | 2 +- CommandWords.class | Bin 2520 -> 2575 bytes CommandWords.java | 1 + FireCommand.class | Bin 884 -> 1534 bytes FireCommand.java | 19 ++- Fleet.class | Bin 1748 -> 2134 bytes Fleet.ctxt | 9 +- Fleet.java | 46 +++---- Grid.class | Bin 1287 -> 1547 bytes Grid.ctxt | 11 +- Grid.java | 66 ++++++---- MissCommand.class | Bin 803 -> 803 bytes MissCommand.java | 4 + Parser.class | Bin 1985 -> 2019 bytes Parser.java | 28 +---- PlaceCommand.class | Bin 0 -> 746 bytes PlaceCommand.ctxt | 11 ++ PlaceCommand.java | 45 +++++++ Ship.class | Bin 1657 -> 1657 bytes Ship.java | 5 + ShipCommand.class | Bin 693 -> 1201 bytes ShipCommand.ctxt | 2 +- ShipCommand.java | 48 +++++++- SunkCommand.class | Bin 801 -> 862 bytes SunkCommand.java | 7 +- TalkCommand.class | Bin 1554 -> 1082 bytes TalkCommand.java | 21 +--- package.bluej | 244 ++++++++++++++++++++----------------- 31 files changed, 397 insertions(+), 259 deletions(-) create mode 100644 PlaceCommand.class create mode 100644 PlaceCommand.ctxt create mode 100644 PlaceCommand.java diff --git a/Battleship$GameState.class b/Battleship$GameState.class index c794b1aea02ef0d9b82ccd678a494350f706846c..17e083d213ce7fa7f783b5e097b42c7d0fab47e9 100644 GIT binary patch delta 35 ocmZ3^v7BQAKQp7iWC3OaAnC|#2P7Mq8(4)H)ENXOv$7}w0F289;Q#;t delta 35 ocmZ3^v7BQAKQp87WC3OaAnC|#2P7Mq8(2jd)ER^)v$7}w0FAN+@Bjb+ diff --git a/Battleship.class b/Battleship.class index 9ee5753342d92adb6a94ba82d79036144eeb23c5..428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xwJJ3wY5qh_RFdSvZZXj@z%-ue0WRBj9Tkv+=hIiq0 zJo+5KdkE=A_{w{dc{@c=ONP2B%_!iH@h2SRF3oI+MW-o$oc_t(TbPZ2&cQ`6=D8Gu z{#J&Z|CRiJX1l$m`9-E%$2^#S#KGa z&!WknxPlX>=tds{atlF_Wv$L|tOxxaFiEvYZ=$0s2+g&0y^kQgj_|vI030WbZeaj! z!y6gEI~lyUP}AEe^=Fj2i&AeV*S$KV2dU{co}TX_&E$+(xnmrvVLqXQD`7sNgWEuv zBh+;_?P?-G-$8AX)+v_MJ;eN4zS`f*yD+WVi~D$I=yY6+;5-d8{d6!F@8a*z{r}+Y z{Y|gsCBl60?CWQxA;~ptuKbJyaSOwv_5^n5@Lwt6_w#dAEk8O{etvYSj9RM9IcyzY zc^0ufbvfI{oUN?pY!+)`5oYLIMz_CWR#K*9J`}y0mN3aXVv)8;8Lx?1GF%gDoW|knpU}_<(1VZAhkFQ;HT2s$Jgw<_G(FnmFF0I=NPkFAjVutkThm7u(2r^Q4GZYEYx>>=^xc}CTtL4> z)5jLjS7`b^O}A@azWfCS?Z#S9h=u3DGFXPKf;rl9p7gQK8@*`kK zHLAs`iQfWR)J7FmoB7?~3clKGRqYzdt;}Yt>L7COVTPI43PJ@(%dsf<61s?*)z zrD`2I)OxH_JejBs+Ctk`U$Lt}UZE;WyOpKaRu}aRh~8XT@|FuM*)B%|zAcAUKbO3O zOJ2$)H)D;utZuormE{!M!MWuUY)7(Xw#?zy@#t-5@w!BJ&l%`rmha9Ya!3d*wGGW` zdo{q6sp#YJh3zL#2b8?gRvhWq&w%Wiw|}e}oiNEzgLP(ws%G(PNJV&nMu}OGIk?LosY_Aa!~%6=RJZR{)SY5K6?GriK0L-I P#A6#N2ich>uWA1+#xtH@ diff --git a/Battleship.java b/Battleship.java index 68e5376..bbba0b9 100644 --- a/Battleship.java +++ b/Battleship.java @@ -1,6 +1,4 @@ import java.awt.event.*; // Use some events -//import java.awt.*; // Graphics -//import javax.swing.*; // Use swing for GUI import java.util.*; // Util import java.io.*; //I/O import java.net.*; //Sockets @@ -11,8 +9,7 @@ * @author Jerrett Fowler * @version 1.2 (August 2013) */ - -//public class Battleship extends JFrame implements MouseListener, WindowListener + public class Battleship { @@ -25,6 +22,8 @@ private enum GameState private Parser parser; private Protocol protocol; Player currentPlayer; + Grid grids; + Fleet fleet; /** * Main @@ -32,7 +31,8 @@ private enum GameState public static void main(String[] args) throws IOException { int i = 0, portArg; - String arg, machine; + String arg = new String(); + String machine = new String(); boolean vflag = false; while (i < args.length && args[i].startsWith("-")) { @@ -84,7 +84,7 @@ public Battleship(String gameState, String serverName, int portNumber) //set up fleet newFleet(); //set up new grids - //createGrids(); + createGrids(); switch(gameState) { @@ -205,6 +205,22 @@ public void play() { printOpening(); + System.out.println(" GAME BOARD"); + + if(gameState == GameState.INITIALISE) //change this when READY works + { + grids.addShipFromFleet(fleet.getShipInFleet("SUBMARINE1")); + grids.addShipFromFleet(fleet.getShipInFleet("SUBMARINE2")); + grids.addShipFromFleet(fleet.getShipInFleet("SUBMARINE3")); + grids.addShipFromFleet(fleet.getShipInFleet("BATTLESHIP1")); + grids.addShipFromFleet(fleet.getShipInFleet("DESTROYER1")); + grids.addShipFromFleet(fleet.getShipInFleet("DESTROYER2")); + grids.printGrid(); + } + + System.out.println(); + System.out.println("Board is set up for you. Command for Placing a ship is not fully implemented."); + //Main gameplay loop while(!getPlayer().getEnd()) { @@ -242,40 +258,49 @@ else if(command.getName().equals("HELP")) else if(command.getName().equals("TALK")) { command.execute(getPlayer()); + + //send message to other player } else if(command.getName().equals("FIRE")) { command.execute(getPlayer()); + + //send message to other player } else if(command.getName().equals("MISS")) { command.execute(getPlayer()); + + //send message to other player } else if(command.getName().equals("HIT")) { command.execute(getPlayer()); + + //edit Grid + + //send message to other player } else if(command.getName().equals("SUNK")) { command.execute(getPlayer()); + + //remove ship from ArrayList + + //send message to other player } else if(command.getName().equals("ILOSE")) { - command.execute(getPlayer()); - } + command.execute(getPlayer()); - else if(command.getName().equals("SHIP")) - { - command.execute(getPlayer()); + //send message to other player } - - - //need to add more stuff here + } printClosing(); @@ -328,7 +353,7 @@ public Player getPlayer() */ public void newFleet() { - Fleet fleet = new Fleet(); + fleet = new Fleet(); } /** @@ -337,34 +362,8 @@ public void newFleet() private void createGrids() { // Create player grid - Grid grids = new Grid(); + grids = new Grid(); + + } - - /** - * Start of program - - public void init() - { - setSize(256, 256); - }*/ - - /** - * Mouse Event Overrides - */ - //public void mouseClicked(MouseEvent event) {} - //public void mouseEntered(MouseEvent event) {} - //public void mouseExited(MouseEvent event) {} - //public void mousePressed(MouseEvent event) {} - //public void mouseReleased(MouseEvent event) {} - - /** - * GFX Event Overrides - */ - //public void windowActivated(WindowEvent event) {} - //public void windowClosed(WindowEvent event) {} - //public void windowClosing(WindowEvent event) {} - //public void windowDeactivated(WindowEvent event) {} - //public void windowDeiconified(WindowEvent event) {} - //public void windowIconified(WindowEvent event) {} - //public void windowOpened(WindowEvent event) {} } diff --git a/Command.java b/Command.java index b8c7d93..0e678ae 100644 --- a/Command.java +++ b/Command.java @@ -6,7 +6,7 @@ * @author Jerrett Fowler * @version 1.0 (July 2013) */ -public abstract class Command //Why use abstract: http://stackoverflow.com/questions/7262892/java-best-practices-put-get-subclass-objects-into-hashmap-that-expects-supercla +public abstract class Command { public String secondWord; public String thirdWord; diff --git a/CommandWords.class b/CommandWords.class index 2852a4fb365ecea47e37cefd9865c81cc6703522..de2de2a1d19dc216ebed631b56b10c6e111c1a55 100644 GIT binary patch delta 894 zcmX|&|b5Qd*~6FD;{Hx&%3C`HOvN|ZrV*%LFd1PLP(iJfbiNF;+8v5S4*#}@m( zFJTxJl=9gx@X0Sx=ra@fa_-aJ@9BO|_5B$*->2=zpU>Zb5nr()F#e`S4l2P_+D@D(Yr6w<4AB-ki8shbu_bw?uq{2NOsNft~EGT+gpYokAkwYap!tx|J z7fSgnxk9LLDxk-zL8Cs9+k5gCrY!x$)HJ@jcbQueIcw>gjQApL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Xx)ltE65IFk+V><(0Pb*Eip6VOKc8E>*MR(o!c2s4=OO;fbm@<)Pb$e2+M}&;$^2a4g*ZeT3%QaWyJ~;qwR`X}!dAvZP*2*_m zEj))w3+tFOv0-5o9|){%`=RYg*|3#wyIwm~cCRD0x+6WC4Vkrhxozs`@-T z)J1x|cNg>iA3?>TbwCQBrg7j(Mf|k#h)>}@l8T}_vBB;_!ZXnLyTlkbhUvo z+r`OjCXy3c?jp+^#(gG^Ll-@d5w2%pvcOT6m%%xf{yN`Sj-}?gPU9kqxQr53Dc`^) zbm*nQEfK&p{az(w33~0~HG0SBS7U@JX2_w+FHfih+9yFv1^NlhM464u6EdANQ8d99 xSTb?m#09cE`4^)KW}oX(#tQfz>60itK>T|Ou?RvkI=nW(cj77Emm;e-{sFCC>9p8uh$`5Z)ReJ+R@I%^_jwrTKB5g zJGnenSP2T>w3|LPv2-Mgj)sdTNF$SU(T*8~IHJhOv?IKd?glTYAg4W}Kg36QsacUh zRt=GI$TKaIH(qCkf=r58<`SuMw7#f8F&JWeka@(+rG{AgAVRhvV<5CHO31Y-wSq-e zV%5aOXI_3$Z$mt^)Ipcm$)Ll G#^Nui0WFmP diff --git a/FireCommand.java b/FireCommand.java index 042aaf2..aed19ed 100644 --- a/FireCommand.java +++ b/FireCommand.java @@ -34,8 +34,23 @@ public boolean execute(Object o) } else { - //Check for the secondword and thirdword being ints and convert to ints appropriately - System.out.println("Fire"); + Player p = null; + p = (Player)o; + + String[] strArray = getSecondWord().split(" "); + int[] intArray = new int[strArray.length]; + + for(int i = 1; i < strArray.length; i++) + { + if(strArray[i] != null) + { + intArray[i] = Integer.parseInt(strArray[i]); + } + + } + + System.out.println("Fired on coordinates: " + intArray[1] + " x " + intArray[2]); + return true; } } diff --git a/Fleet.class b/Fleet.class index c26f4df01a33b9ddccfd68e40e8e3e4df3ed9151..634eaa2ac23ccebfa6c7c5fbfd804642e666b575 100644 GIT binary patch literal 2134 zcmZ`)Yfl_i7=F&~?9Q+Zuxx<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HXUP1_wPZ8NBQ=6sLqPa~U>l#2llh(G|nSJgyoXPcXqX zb6hvyZY1K|WYT5I<<`opoE2Y~nVpvjm)naoc2$3xdW*=2L<@VN*(c4k&u&uYdc z$Xa}A0yeFZy#dRL?F*Ue_LF+)Bs*(4;B$wpPcu^Qn&Tc>HJg=opBc^dnPtxB0S|p1 z@z~{w&pg@plTOmgX<)T-0$1*3L(DcN0+fXSWgtL}4^YDc)O0Kk2E2}lxYpCz09Fc5 z3^vkhSn1E$6Qxenahx?GABl!SEZV!JxS`_ZOA10E?rv2iLcx!135B6hWQ4^x(WzXc z#$_nhnUt9dc2G$zRkUfbKIJ)~Bp^-y+?T5xWOp|Vw zi8fp+K(myW{y^y}+uw@YdId48l%Vau2422F3$3QX;&QAeFj<77+Ad|@tzW1ocvGfE zux;~=VMmp+#WAT4R*7gE$2Wbf>uFRUGC{686@bZgAas=+Y+R?@(rPJ@3X8AU9g*_L zDwXxCIjWY3l}84a|Nd-v7xXsvE3^O%QN*wU8P(J=+8O7BLNk%HYFt{;8cz|*6l*&j o!4{dk;|!gux74GFld7`=@5MO3DRarVoT~Xn!dAs;b+kG254l@$VE_OC diff --git a/Fleet.ctxt b/Fleet.ctxt index e5857b5..0b806c7 100644 --- a/Fleet.ctxt +++ b/Fleet.ctxt @@ -4,11 +4,14 @@ comment0.target=Fleet() comment0.text=\n\ Constructor\ for\ objects\ of\ class\ Fleet\n comment1.params= comment1.target=int\ size() -comment1.text=\n\ An\ example\ of\ a\ method\ -\ replace\ this\ comment\ with\ your\ own\n\ \n\ @param\ \ y\ \ \ a\ sample\ parameter\ for\ a\ method\n\ @return\ \ \ \ \ the\ sum\ of\ x\ and\ y\ \n +comment1.text=\n\ Size\ of\ fleet\n\ \n\ @param\ \ y\ \ \ a\ sample\ parameter\ for\ a\ method\n\ @return\ \ \ \ \ the\ sum\ of\ x\ and\ y\ \n comment2.params=s comment2.target=void\ sink(Ship) comment2.text=\n\ Remove\ ships\ from\ fleet\n\ \n\ @param\ \ s\ \ \ A\ ship\n\ @return\ \ \ \ \ void\n comment3.params=shipID comment3.target=Ship\ getShipInFleet(java.lang.String) -comment3.text=\n\ Return\ an\ instance\ of\ a\ specific\ ship\n\ \n\ @param\ \ s\ \ \ A\ ship\n\ @return\ \ \ \ \ ship\n -numComments=4 +comment3.text=\n\ Return\ an\ instance\ of\ a\ specific\ ship\n\ \n\ @param\ \ shipID\ \ \ A\ ship\n\ @return\ \ \ \ \ ship\n +comment4.params= +comment4.target=void\ getFleet() +comment4.text=\n\ Lists\ all\ ships\n +numComments=5 diff --git a/Fleet.java b/Fleet.java index fee7719..54389cb 100644 --- a/Fleet.java +++ b/Fleet.java @@ -1,4 +1,5 @@ import java.util.ArrayList; +import java.util.Iterator; /** * Write a description of class Fleet here. @@ -23,18 +24,18 @@ public class Fleet public Fleet() { //3 Subs - sub1 = new Ship("s1", 2, 0, 0, 0); - sub2 = new Ship("s2", 2, 0, 0, 0); - sub3 = new Ship("s3", 2, 0, 0, 0); + sub1 = new Ship("SUBMARINE1", 2, 1, 0, 0); + sub2 = new Ship("SUBMARINE2", 2, 0, 2, 2); + sub3 = new Ship("SUBMARINE3", 2, 1, 1, 6); //1 Battleship - battleship1 = new Ship("b1", 4, 0, 0, 0); + battleship1 = new Ship("BATTLESHIP1", 4, 0, 5, 2); //2 Destroyers - destroyer1 = new Ship("d1", 3, 0, 0, 0); - destroyer2 = new Ship("d2", 3, 0, 0, 0); + destroyer1 = new Ship("DESTROYER1", 3, 1, 7, 1); + destroyer2 = new Ship("DESTROYER2", 3, 1, 6,7); - fleet = new ArrayList(); + fleet = new ArrayList(); fleet.add(sub1); fleet.add(sub2); @@ -42,10 +43,11 @@ public Fleet() fleet.add(battleship1); fleet.add(destroyer1); fleet.add(destroyer2); + } /** - * An example of a method - replace this comment with your own + * Size of fleet * * @param y a sample parameter for a method * @return the sum of x and y @@ -69,35 +71,35 @@ public void sink(Ship s) } } - /** * Return an instance of a specific ship * - * @param s A ship + * @param shipID A ship * @return ship */ public Ship getShipInFleet(String shipID) { - Ship ship = new Ship("id", 0, 0, 0, 0); + Ship temp = null; for(Ship s : fleet) { if(s.getShipID().equals(shipID)) { - ship = s; + temp = s; } } - return ship; + return temp; } /** - * Return all ships locations/Prints - * - * @param position where is the ship? - * @return Return ship - - public Ship location(int position) + * Lists all ships + */ + public void getFleet() { - // - return ; - }*/ + Iterator itr = fleet.iterator(); + + while(itr.hasNext()) + { + System.out.println(itr.next()); + } + } } diff --git a/Grid.class b/Grid.class index f2096c37b30d31ab000556427b9d46a7bf6967bc..fbe477c83efab8c1d0034467103b8ec16431837b 100644 GIT binary patch literal 1547 zcma)5U2hvz5IuKy?X@?X)VQ&!6Bp7#A$3}(bxA_=MZqMcjq^bq(vKj~jlHCs+Pl_z z4RIe34*~uIPpB_>2GLY%C3xb6XMP1gA&Lm+u8jggLfE=9bLY;SnK}3FuYWxM3BWbn zH_(sqI8I|iM_TH)rMPZj5>rx4OEDwGtd4hLxM9G+yK%gSVhr!cFlS&MH)Hrf>RUQ) z>sSzoZ23<0s(`w&ajUy42xv{`u`M9zicUMO6U;JV_~JTGie8l`r%H}%FSY8Mw!da= z*62x=yoyy@w|qzLyG|{5=roB@y2&b20tu^HEkAS`^S)P~ui17W5Fai{&y)lgJ6vt9 zFeh{~d8g=kew9YMYs9OLZ&w1xa|L2eCYQr*d&_}Ud9-LX!s6k8CE_=H#|>nC;%;+2 z;&OB>>R1vm%3jN_*z=AYAuglx+tz26i2)3nID?Fd6w)SMMp{S7#4=V)d?>}L6lJUk z49JYpn&obduD0C3soQfq6}!>tuV=2_2--sxt7+#Y>Y9#^OswM$ySU4hXD24^VvY8Y ziF+6%$DM8y$GFRz+Z>oDk`sZ`;fdpouE^QSfp1%Nl6xFam*Z}6qAfcpdbL)aO!5BY zb<(ryeJ;>PW7&6XH?TUL>U4C7ObwS#LWS4!_X6!^V6&#`wb)jw6aUYKc-@hZdjUPv zH5cdjV*B}=RVb2IT8gBW8j@^E6(kgclv(cVa1V^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~F#-APW65imyW$H}}zo|9~N0~Z*N5TD@hA(Lg<*v1gOOrdeo0iHzr(#{m6 bJyWzJ_6wT&g@o$)iR4d8pfJdE4QKxVv0B<( diff --git a/Grid.ctxt b/Grid.ctxt index f6af1d5..a591da6 100644 --- a/Grid.ctxt +++ b/Grid.ctxt @@ -5,10 +5,7 @@ comment0.text=\n\ Constructor\ for\ objects\ of\ class\ Grid\n comment1.params=s comment1.target=void\ addShipFromFleet(Ship) comment1.text=\n\ Add\ Ship\ from\ fleet\n\ \n\ @param\ \ y\ \ \ a\ sample\ parameter\ for\ a\ method\n\ @return\ \ \ \ \ the\ sum\ of\ x\ and\ y\ \n -comment2.params=a -comment2.target=void\ fillArray(int[][]) -comment2.text=\n\ \n -comment3.params=a -comment3.target=void\ printGrid(int[][]) -comment3.text=\n\ Print\ grid\n\ \n\ @param\ \ y\ \ \ a\ sample\ parameter\ for\ a\ method\n\ @return\ \ \ \ \ the\ sum\ of\ x\ and\ y\ \n -numComments=4 +comment2.params= +comment2.target=void\ printGrid() +comment2.text=\n\ Print\ grid\n\ \n\ @param\ \ y\ \ \ a\ sample\ parameter\ for\ a\ method\n\ @return\ \ \ \ \ the\ sum\ of\ x\ and\ y\ \n +numComments=3 diff --git a/Grid.java b/Grid.java index 325c2cb..e85e21a 100644 --- a/Grid.java +++ b/Grid.java @@ -9,10 +9,8 @@ public class Grid { // instance variables - private int grid1[][]; - private int grid2[][]; - int x; - int y; + private int[][] grid1; + private int[][] grid2; int size; /** @@ -23,8 +21,6 @@ public Grid() size = 10; grid1 = new int[size][size]; grid2 = new int[size][size]; - fillArray(grid1); - fillArray(grid2); } /** @@ -35,18 +31,35 @@ public Grid() */ public void addShipFromFleet(Ship s) { - // - } - - /** - * - */ - public void fillArray(int a[][]) - { - // Fill each row with 0 - for (int[] row: a) + //get x + int xCoord = s.getColumn(); + + //get y + int yCoord = s.getRow(); + + //get direction + int direction = s.getOrientation(); + + //get Size + int shipSize = s.getSize(); + + if(direction == 0) + { + for(int x = 0; x < shipSize; x++) + { + grid1[yCoord][xCoord + x] = 1; + } + } + else if(direction == 1) + { + for(int y = 0; y < shipSize; y++) + { + grid1[yCoord + y][xCoord] = 1; + } + } + else { - Arrays.fill(a, 0); + throw new RuntimeException("Empty case."); } } @@ -56,18 +69,25 @@ public void fillArray(int a[][]) * @param y a sample parameter for a method * @return the sum of x and y */ - public void printGrid(int a[][]) + public void printGrid() { + //Loop through rows for(int i = 0; i < size; i++) { + //Loops and prints each column for(int j = 0; j < size; j++) { - if(a[i][j] == 1) - { - grid1[i][j] = x; - } - System.out.print(a[i][j]); + System.out.print(grid1[i][j] == 1 ? "X" : "." ); + System.out.print(" "); + } + System.out.print(" "); + for(int k = 0; k < size; k++) + { + System.out.print(grid2[i][k] == 1 ? "X" : "." ); + System.out.print(" "); } + System.out.println(); } + System.out.println(); } } diff --git a/MissCommand.class b/MissCommand.class index 7b9c00c0c23f6eb3350e48b02dbd6dfd8647aaf5..5a63bae73b36b0f959c950c993b9ca6a8312147f 100644 GIT binary patch delta 55 zcmZ3?wwP_hDkfeP27U%r20;c*21y33$=jLyWlexQ1_mAmMj*+`AjBXHq!}5cfg}@y F3;^`R1^)m5 delta 55 zcmZ3?wwP_hDkfe927U%b20;c@21y3B$=jLyWetEl1_mAmMj*+`AjBXHq!}5cfg}@y F3;^-K1?vC+ diff --git a/MissCommand.java b/MissCommand.java index 264f6f1..4f6852c 100644 --- a/MissCommand.java +++ b/MissCommand.java @@ -29,6 +29,10 @@ public boolean execute(Object o) { if(getSecondWord() == null) { + //convert object + + //sent MISS to other player + System.out.println("Miss"); return true; } diff --git a/Parser.class b/Parser.class index abb060c403c5c05a19267610846f46fdde7c21a9..758ac0a5e6fa8cbe823e417f492d9053f574e3ef 100644 GIT binary patch delta 1078 zcmZva+fP(i6vlsNF6`lWxQ#^xL7)_79H3OjJBlb?O65}2iX-$gNQ)>8I^HksczHH4 znHQVX#5dxDiB*|NI*CbN`p`e1@!dbbf523~eK1W*d^l^Zz0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9=plqesRg_arqfVYO(3XFsN$9Abb(SOdoN9y= zoAhJhX(Ep?v1oykS=`JlrJ2WgGc1^)tkbVAP_B##l3mK0r6My!EVih?4-Ewt3ku}o z1(wXRG~-VZnPFL%{#4$j%okQoQ$0b{cZ74{HJ@wvN2f@LAFG+GRaLANpC&Q!@wF<2 z^i>yFexUIMrHwi$IoUX=0g~Eqy~YY+2X7-+Ay`dB;WBL{so7JkS4xu-*3rR6y4lPz zn)P~q;w-xv6YUNsxJNG!ILSl$iW}Rgy)-FdZc0ZqYm*lppY?634$5m^K{@#;X zGg}GfXi;h{k&n_07`7RyIEL-j?@1Vb4*Bm{V)#Yu9kkBffO^v#5iM-ToRkwNP7^5x p2fw<$@R#e`IWIXeIq)5Od|vi0ja|I_Z=^%tOW&NAyr(G9_6fHdnIixI diff --git a/Parser.java b/Parser.java index 411f369..3d5873f 100644 --- a/Parser.java +++ b/Parser.java @@ -16,8 +16,6 @@ public class Parser private String input; private String w1; private String theRest; - //private String w2; - //private String w3; /** * Constructor for objects of class Parser @@ -34,10 +32,10 @@ public Parser() */ public Command getCommand() { - input = ""; + input = new String(""); //prompt - System.out.print(":: "); + System.out.print(">> "); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); try @@ -60,10 +58,6 @@ public Command getCommand() w1 = null; } - //do a check for the string command - - //do a check for the int command - //store the rest as a string if there are more while(tokenizer.hasMoreTokens()) { @@ -79,22 +73,12 @@ public Command getCommand() { w2 = null; } - - if(tokenizer.hasMoreTokens()) - { - w3 = tokenizer.nextToken(); //Word 3 - } - else - { - w3 = null; - } */ Command command = commands.getCommand(w1); if(command != null) { command.setSecondWord(theRest); - //command.setThirdWord(w3); } return command; @@ -116,14 +100,6 @@ public String getW2() return theRest; } - /** - * Get word 3 as string - - public String getW3() - { - return w3; - }*/ - /** * Get CommandWords */ diff --git a/PlaceCommand.class b/PlaceCommand.class new file mode 100644 index 0000000000000000000000000000000000000000..dfcceae6ac0fbc87f280dd740894fe4fe14341b3 GIT binary patch literal 746 zcmZ9JOK;Oa6ot>kNu0PQY2B7LZ7HEZa;8Fk=)VyV*=3&M ziWl^&2cy&I-1tnDKF--UI)2G$N$-rZ`7Bf~BZIhBrZ_OOx^Qttpf(Ji4_>%%u)+zA zw~dYqA6;{2&~5ZwJj5dbw`@X!Vkm*t(&K%&&?@1RWpm9D7hqA=AM#B#*_2EOzn&Ld zPSfz*h~o6Wrzs}#$Nawr{}d3Y7+{_(o;e5C7Ne)k3+^l39}r!y@(tE!h848AwkQVH zP-UTmb*wUS7jkAjM&!aqVfB_(xn3OgexrKy1vRh!9k%t6!iAwnD`1P!Hf*xBv74Lj w6pa?9rsXEC($-X6!*%WgH*m9P)aP!PYu&G~J}u4bd9qictSu>T<*M8N0EumiH~;_u literal 0 HcmV?d00001 diff --git a/PlaceCommand.ctxt b/PlaceCommand.ctxt new file mode 100644 index 0000000..688a547 --- /dev/null +++ b/PlaceCommand.ctxt @@ -0,0 +1,11 @@ +#BlueJ class context +comment0.params= +comment0.target=PlaceCommand() +comment0.text=\n\ Constructor\ for\ objects\ of\ class\ ShipCommand\n +comment1.params=o +comment1.target=boolean\ execute(java.lang.Object) +comment1.text=\n\ ''SHIP_''\ _\ \n\ \n\ @param\ \ y\ \ \ a\ sample\ parameter\ for\ a\ method\n\ @return\ \ \ \ \ the\ sum\ of\ x\ and\ y\ \n +comment2.params= +comment2.target=java.lang.String\ getName() +comment2.text=\n\ Return\ String\ of\ name\ of\ command\n +numComments=3 diff --git a/PlaceCommand.java b/PlaceCommand.java new file mode 100644 index 0000000..78852cb --- /dev/null +++ b/PlaceCommand.java @@ -0,0 +1,45 @@ + +/** + * Write a description of class ShipCommand here. + * + * @author Jerrett Fowler + * @version 1.0 (September 2013) + */ +public class PlaceCommand extends Command +{ + // instance variables - replace the example below with your own + private String name = "PLACE"; + + /** + * Constructor for objects of class ShipCommand + */ + public PlaceCommand() + { + // + } + + /** + * ''SHIP_'' _ + * + * @param y a sample parameter for a method + * @return the sum of x and y + */ + @Override + public boolean execute(Object o) + { + Ship s = null; + s = (Ship)o; + + System.out.println("Place"); + return false; + } + + /** + * Return String of name of command + */ + @Override + public String getName() + { + return name; + } +} diff --git a/Ship.class b/Ship.class index 47aa680bd53de253d11177bfbab71954ffb0173c..a05ed67d241916a3bf8b5bb0942497f6f87d6c0f 100644 GIT binary patch delta 113 zcmey#^OI*oDl@MPgCv7I5GpdLFeptfV$NgKnf#F1g3)5K6pI_9{p3WJP+oTi4hByK zVFo`2S%!eghgtj>!zT-|x--TDRfo_v_ak1=Sn5UV?56i}t;))LH)bdk7;HP(PKoaH2e?*u zhM2fvp++%rVcePcn~d?h(}oVr;@)$<``vTT`OeAw`S;@|fH5qqXhTdvJb*9;WDKg@ zhgA46tRSJ{Iz|E*#h8j47*}vp!GwZa3MLgyDM%`qmN6sawgi9CD3}t$E4#+Nk;ogx z?S$@>tm1Z3LesQWv>cLr(bxv5^Y#|0Eh|>hOjinl@cEkgQYjVRePDpo* z+|yNK&wY*xF!Z+Rq}^)TqcKnH<9bxxu9R}-q9u}U_2e}yir3JIv#e5IT3*-Cjt*fn zcMW&Yr{OO8B&hm>xz*Xsaym64V^+f)uE?0zuz-||MGg0`My+K!Yfxt&Ov=|n`sNDq4QXYDnGDGXK6&757_dT5un zBm{)dd&>)~`E-*hsQIj7_yoz3v9bxaoDG-l$M=X=Ug~c(=-a~K${!vB+Nwi z1SwxU)!$kVVjJk zBLtO~FVNGfbX>$GdJ-<LN~?IOW7t*=sR}Uwd`5;A4kts9$XX)WC79m zYB0=5ah8LOLkiDsZtpEe8ONMd&UC74bJw-fLV)qjibBOw=v=IROz)v7))a*mB2^r# zEGhFHC|?%$^DS}BD87`-=ytC}t@wjR_@vCpB34&&z1goV?cdHni?6S-E>A$44evYG b&}j`IF5d`W=B|b?`pf?|@qC-jx@&6&UnLnw diff --git a/ShipCommand.ctxt b/ShipCommand.ctxt index fd1c43d..a6141be 100644 --- a/ShipCommand.ctxt +++ b/ShipCommand.ctxt @@ -4,7 +4,7 @@ comment0.target=ShipCommand() comment0.text=\n\ Constructor\ for\ objects\ of\ class\ ShipCommand\n comment1.params=o comment1.target=boolean\ execute(java.lang.Object) -comment1.text=\n\ ''BATTLESHIP''\ |\ ''DESTROYER''\ |\ ''SUBMARINE''\n\ \n\ @param\ \ y\ \ \ a\ sample\ parameter\ for\ a\ method\n\ @return\ \ \ \ \ the\ sum\ of\ x\ and\ y\ \n +comment1.text=\n\ ''BATTLESHIP''\ |\ ''DESTROYER1''\ |\ ''SUBMARINE1''\n\ |\ ''SUBMARINE2''\ |\ ''SUBMARINE3''\ |\ ''DESTROYER2''\n\ @param\ \ y\ \ \ a\ sample\ parameter\ for\ a\ method\n\ @return\ \ \ \ \ the\ sum\ of\ x\ and\ y\ \n comment2.params= comment2.target=java.lang.String\ getName() comment2.text=\n\ Return\ String\ of\ name\ of\ command\n diff --git a/ShipCommand.java b/ShipCommand.java index 8fa08ee..cec15d4 100644 --- a/ShipCommand.java +++ b/ShipCommand.java @@ -7,6 +7,8 @@ */ public class ShipCommand extends Command { + + // instance variables - replace the example below with your own private String name = "SHIP"; @@ -19,16 +21,54 @@ public ShipCommand() } /** - * ''BATTLESHIP'' | ''DESTROYER'' | ''SUBMARINE'' - * + * ''BATTLESHIP'' | ''DESTROYER1'' | ''SUBMARINE1'' + * | ''SUBMARINE2'' | ''SUBMARINE3'' | ''DESTROYER2'' * @param y a sample parameter for a method * @return the sum of x and y */ @Override public boolean execute(Object o) { - System.out.println("Ship"); - return false; + Ship s = null; + s = (Ship)o; + + if(getSecondWord() == null) + { + if(s.getShipID().equals("SUBMARINE1")) + { + System.out.println("SUBMARINE1"); + } + else if(s.getShipID().equals("SUBMARINE2")) + { + System.out.println("SUBMARINE2"); + } + else if(s.getShipID().equals("SUBMARINE3")) + { + System.out.println("SUBMARINE3"); + } + else if(s.getShipID().equals("BATTLESHIP1")) + { + System.out.println("BATTLESHIP1."); + } + else if(s.getShipID().equals("DESTROYER1")) + { + System.out.println("DESTROYER1"); + } + else if(s.getShipID().equals("DESTROYER2")) + { + System.out.println("DESTROYER2"); + } + else + { + System.out.println("No such ship name."); + return false; + } + } + else + { + + } + return true; } /** diff --git a/SunkCommand.class b/SunkCommand.class index f0a5da0b906dd6ad2ff5b3774e9925dc6ac398e8..aef72a422554aa7193143ba474a1868a85b6178b 100644 GIT binary patch delta 452 zcmYjM%TB^j6r9_Z-nLYfii!`gpr957<*_ox4^Z3?7sMaX_)G{3SHw>s#t(3hi5kVk zg>hkA_z`}Jac&{T%{epY&Yd~u*8DbWUq7#J04k_Dh{Cs!vEd-=uq;R{+Q=bqVadTV zRxAV(1&P&e`NnApn7fU`ql?Y%$H{gKqXI@_e{aWyixC%VNT~teC5kReSQm&l&)a^h zeRk}hUivLQ6(u%Ylu@}p5O*E503e_#2O^!AzN}+pTbv8_Xz&6Nc-k}c2T~1j))>Vg zGHBso93GiFkdr0I1ST*!w7TLirOyU^7@tUpdf^?BPW=(4C;PCBo zs`{{zVPuYmc_a~VQV1h`YHe;j#i^zOhT#fLV}|jwp`S<+&LK72r^GH$1tP%{^m|GM SSDBmwwSU({{;o-fs`+2LW-bW; delta 375 zcmYk0%`O9B6o#Mq>3lQOX=yREr9WuP)K5b!U4g_#EbWQJ&brsoG%mot79>VuVQJw8 z>|Ba?XEb7SzW4pkInQ~&ynFB9rz)Re7g?I2F12OruaTs<@06Y>RK4^9 z<4!Z_rx<6dzLT?K3erssZ3XFw-K9n^zY+g(W;aA6W?5HO@@=akS)-nvophYIpGEcL PVE8X$;V)uC9h=o3h?*eP diff --git a/SunkCommand.java b/SunkCommand.java index 15737b7..25b21e4 100644 --- a/SunkCommand.java +++ b/SunkCommand.java @@ -29,7 +29,12 @@ public boolean execute(Object o) { if(getSecondWord() != null) { - System.out.println("Sunk"); + Ship s = null; + s = (Ship)o; + + //if ship's + + System.out.println("You sunk my ship."); return true; } else diff --git a/TalkCommand.class b/TalkCommand.class index a08851645df25af7a8b812acc6852cf096e7c516..d3dfe112fe20227a8baa65a3e1588926ff23262f 100644 GIT binary patch delta 621 zcmYjOO-~b16g{u=rt{H9=?4l_t*t;QQ_JwBl`0Z+WfWq9i6L&BNYj+mLWa?#D}IBF zd*Ysj8Z8MX#+3_yl<~}z7&iBvbKiOQo_pW1IyWEv`Fs8oz%tftq){<3YheUcn_lA48~SHXX*o3P5Bk}q?Aho zq~s}aP7!IRe67WuE3k;mFfc_lO(!!bph8wf9W{QEiv|{AM=R`V@veYt^j%=?ItSIL zReQLBBJI=Eh2aR@M2VKmaWml(-lBH6j)+C;&>c?mnP9kxWSneXT7dq40n@Q+<{v}J BQZoPm literal 1554 zcmZuxT~ixX7=8{(IAPgB38f8wv}>&jK@zc2TWHaeQpF~LHb_mi)@5^`+a|l2&BlRW z@6xsC*XcT0ay?b)H1|}nWA8Ph zVBfJDyLRB}d;FLTpSo>B7@x16ao3>YHPN@!+(+L?hGdECkYwwwI!qxdlET#?} zT6;#-eA`UDy&36otv8m9cdAvd`Z1b$#?Ai4e(%fvT$Y~ouin|Oj{ ziSJC<*b^w~@hr~|txj9jEyoW6?yhl^w`zXJYIfS8)mC2JvaP0Sx9tOE+54ditnjI# zb3}x^!1w@21UP00!Rt5JThP!`4{)xG3#lr{_v#P*pg!z!)DBfsV8r!?Xw*lKT*$`c z)BGARXqr#=O)+)!Yg*%?nNNcHnsI%CZu4`A_rlDhcB{qd1r`VS9TVlh+==05puv&K zJ-}El^k0p7y3Bz(1gxd2HuQ-9S7#S*@qdx!e}q72#!*X9Cl4v#mvCF?u+um??{z1 zqm>iL+6mINml!*Sag6bm diff --git a/TalkCommand.java b/TalkCommand.java index e770072..fd7dbe5 100644 --- a/TalkCommand.java +++ b/TalkCommand.java @@ -1,4 +1,5 @@ import java.io.*; +import java.util.*; /** * Write a description of class TalkCommand here. @@ -29,26 +30,16 @@ public TalkCommand() @Override public boolean execute(Object o) { - if(getSecondWord() == null) + if(getSecondWord() != null) { Player p = null; p = (Player)o; - String input = ""; - BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + String input = new String(getSecondWord()); + String[] inputArray = input.split(" ", 2); - try - { - input = reader.readLine(); - } - catch(java.io.IOException exc) - { - System.out.println("Error reading: " + exc.getMessage()); - } + System.out.println(inputArray[1]); - - System.out.println(input); - - //handle using the string command + //handle using the command return true; } else diff --git a/package.bluej b/package.bluej index cefcef5..ba50192 100644 --- a/package.bluej +++ b/package.bluej @@ -149,6 +149,18 @@ dependency53.type=UsesDependency dependency54.from=CommandWords dependency54.to=HelpCommand dependency54.type=UsesDependency +dependency55.from=ShipCommand +dependency55.to=Ship +dependency55.type=UsesDependency +dependency56.from=PlaceCommand +dependency56.to=Ship +dependency56.type=UsesDependency +dependency57.from=Battleship +dependency57.to=Ship +dependency57.type=UsesDependency +dependency58.from=SunkCommand +dependency58.to=Ship +dependency58.type=UsesDependency dependency6.from=CommandWords dependency6.to=SupportsCommand dependency6.type=UsesDependency @@ -161,22 +173,22 @@ dependency8.type=UsesDependency dependency9.from=CommandWords dependency9.to=EndCommand dependency9.type=UsesDependency -package.editor.height=651 -package.editor.width=1028 -package.editor.x=1464 -package.editor.y=227 -package.numDependencies=54 -package.numTargets=26 +package.editor.height=611 +package.editor.width=958 +package.editor.x=1566 +package.editor.y=128 +package.numDependencies=58 +package.numTargets=27 package.showExtends=true package.showUses=true project.charset=UTF-8 -target1.editor.height=717 -target1.editor.width=870 -target1.editor.x=1950 -target1.editor.y=32 +target1.editor.height=831 +target1.editor.width=771 +target1.editor.x=657 +target1.editor.y=22 target1.height=50 target1.name=Command -target1.naviview.expanded=true +target1.naviview.expanded=false target1.showInterface=false target1.type=AbstractTarget target1.width=90 @@ -192,44 +204,44 @@ target10.naviview.expanded=false target10.showInterface=false target10.type=ClassTarget target10.width=130 -target10.x=500 -target10.y=520 +target10.x=470 +target10.y=470 target11.editor.height=827 target11.editor.width=755 target11.editor.x=8 target11.editor.y=23 target11.height=50 target11.name=HelpCommand -target11.naviview.expanded=false +target11.naviview.expanded=true target11.showInterface=false target11.type=ClassTarget target11.width=120 -target11.x=810 -target11.y=350 -target12.editor.height=700 +target11.x=780 +target11.y=290 +target12.editor.height=829 target12.editor.width=900 -target12.editor.x=308 -target12.editor.y=38 +target12.editor.x=11 +target12.editor.y=22 target12.height=50 target12.name=Grid target12.naviview.expanded=false target12.showInterface=false target12.type=ClassTarget target12.width=80 -target12.x=160 -target12.y=390 +target12.x=10 +target12.y=90 target13.editor.height=700 target13.editor.width=900 -target13.editor.x=380 -target13.editor.y=39 +target13.editor.x=1594 +target13.editor.y=124 target13.height=50 target13.name=StringCommand target13.naviview.expanded=false target13.showInterface=false target13.type=ClassTarget target13.width=130 -target13.x=810 -target13.y=460 +target13.x=780 +target13.y=350 target14.editor.height=700 target14.editor.width=900 target14.editor.x=531 @@ -240,8 +252,8 @@ target14.naviview.expanded=false target14.showInterface=false target14.type=ClassTarget target14.width=130 -target14.x=660 -target14.y=220 +target14.x=630 +target14.y=170 target15.editor.height=700 target15.editor.width=900 target15.editor.x=0 @@ -252,20 +264,20 @@ target15.naviview.expanded=false target15.showInterface=false target15.type=ClassTarget target15.width=110 -target15.x=500 -target15.y=340 -target16.editor.height=700 -target16.editor.width=900 -target16.editor.x=64 -target16.editor.y=39 +target15.x=470 +target15.y=290 +target16.editor.height=900 +target16.editor.width=666 +target16.editor.x=2386 +target16.editor.y=33 target16.height=50 target16.name=ShipCommand target16.naviview.expanded=false target16.showInterface=false target16.type=ClassTarget target16.width=120 -target16.x=810 -target16.y=280 +target16.x=780 +target16.y=230 target17.editor.height=700 target17.editor.width=900 target17.editor.x=97 @@ -276,8 +288,8 @@ target17.naviview.expanded=false target17.showInterface=false target17.type=ClassTarget target17.width=120 -target17.x=810 -target17.y=220 +target17.x=780 +target17.y=170 target18.editor.height=700 target18.editor.width=676 target18.editor.x=595 @@ -288,32 +300,32 @@ target18.naviview.expanded=false target18.showInterface=false target18.type=ClassTarget target18.width=80 -target18.x=280 -target18.y=50 -target19.editor.height=835 -target19.editor.width=861 -target19.editor.x=15 -target19.editor.y=22 +target18.x=250 +target18.y=10 +target19.editor.height=831 +target19.editor.width=873 +target19.editor.x=208 +target19.editor.y=24 target19.height=50 target19.name=Battleship target19.naviview.expanded=false target19.showInterface=false target19.type=ClassTarget target19.width=90 -target19.x=50 +target19.x=80 target19.y=170 target2.editor.height=832 target2.editor.width=612 -target2.editor.x=1642 -target2.editor.y=109 +target2.editor.x=1935 +target2.editor.y=105 target2.height=50 target2.name=EndCommand target2.naviview.expanded=false target2.showInterface=false target2.type=ClassTarget target2.width=110 -target2.x=500 -target2.y=460 +target2.x=470 +target2.y=410 target20.editor.height=835 target20.editor.width=587 target20.editor.x=849 @@ -324,8 +336,8 @@ target20.naviview.expanded=false target20.showInterface=false target20.type=ClassTarget target20.width=120 -target20.x=500 -target20.y=220 +target20.x=470 +target20.y=170 target21.editor.height=700 target21.editor.width=809 target21.editor.x=466 @@ -336,20 +348,20 @@ target21.naviview.expanded=false target21.showInterface=false target21.type=ClassTarget target21.width=140 -target21.x=500 -target21.y=280 -target22.editor.height=700 +target21.x=470 +target21.y=230 +target22.editor.height=831 target22.editor.width=657 -target22.editor.x=619 -target22.editor.y=23 +target22.editor.x=761 +target22.editor.y=22 target22.height=50 target22.name=Ship target22.naviview.expanded=false target22.showInterface=false target22.type=ClassTarget target22.width=80 -target22.x=120 -target22.y=500 +target22.x=140 +target22.y=350 target23.editor.height=700 target23.editor.width=900 target23.editor.x=380 @@ -360,56 +372,68 @@ target23.naviview.expanded=false target23.showInterface=false target23.type=ClassTarget target23.width=110 -target23.x=810 -target23.y=520 -target24.editor.height=835 -target24.editor.width=784 -target24.editor.x=649 -target24.editor.y=22 +target23.x=780 +target23.y=410 +target24.editor.height=900 +target24.editor.width=581 +target24.editor.x=1489 +target24.editor.y=38 target24.height=50 -target24.name=CommandWords -target24.naviview.expanded=true +target24.name=PlaceCommand +target24.naviview.expanded=false target24.showInterface=false target24.type=ClassTarget -target24.width=130 -target24.x=310 -target24.y=170 -target25.editor.height=700 -target25.editor.width=900 -target25.editor.x=187 -target25.editor.y=39 +target24.width=120 +target24.x=780 +target24.y=470 +target25.editor.height=835 +target25.editor.width=784 +target25.editor.x=2051 +target25.editor.y=22 target25.height=50 -target25.name=HitCommand -target25.naviview.expanded=false +target25.name=CommandWords +target25.naviview.expanded=true target25.showInterface=false target25.type=ClassTarget -target25.width=110 -target25.x=660 -target25.y=460 -target26.editor.height=720 -target26.editor.width=620 -target26.editor.x=487 -target26.editor.y=22 +target25.width=130 +target25.x=310 +target25.y=110 +target26.editor.height=700 +target26.editor.width=900 +target26.editor.x=187 +target26.editor.y=39 target26.height=50 -target26.name=Fleet +target26.name=HitCommand target26.naviview.expanded=false target26.showInterface=false target26.type=ClassTarget -target26.width=80 -target26.x=30 -target26.y=440 +target26.width=110 +target26.x=630 +target26.y=410 +target27.editor.height=831 +target27.editor.width=620 +target27.editor.x=642 +target27.editor.y=22 +target27.height=50 +target27.name=Fleet +target27.naviview.expanded=false +target27.showInterface=false +target27.type=ClassTarget +target27.width=80 +target27.x=140 +target27.y=410 target3.editor.height=722 target3.editor.width=707 -target3.editor.x=615 -target3.editor.y=34 +target3.editor.x=265 +target3.editor.y=45 target3.height=50 target3.name=Parser target3.naviview.expanded=false target3.showInterface=false target3.type=ClassTarget target3.width=90 -target3.x=140 -target3.y=50 +target3.x=120 +target3.y=10 target4.editor.height=700 target4.editor.width=900 target4.editor.x=380 @@ -420,8 +444,8 @@ target4.naviview.expanded=false target4.showInterface=false target4.type=ClassTarget target4.width=120 -target4.x=660 -target4.y=400 +target4.x=630 +target4.y=350 target5.editor.height=835 target5.editor.width=727 target5.editor.x=2486 @@ -432,44 +456,44 @@ target5.naviview.expanded=false target5.showInterface=false target5.type=ClassTarget target5.width=80 -target5.x=180 -target5.y=300 +target5.x=230 +target5.y=270 target6.editor.height=825 target6.editor.width=844 -target6.editor.x=277 -target6.editor.y=22 +target6.editor.x=411 +target6.editor.y=24 target6.height=50 target6.name=FireCommand target6.naviview.expanded=false target6.showInterface=false target6.type=ClassTarget target6.width=110 -target6.x=660 -target6.y=340 -target7.editor.height=700 +target6.x=630 +target6.y=290 +target7.editor.height=829 target7.editor.width=900 -target7.editor.x=380 -target7.editor.y=39 +target7.editor.x=527 +target7.editor.y=24 target7.height=50 target7.name=SunkCommand target7.naviview.expanded=false target7.showInterface=false target7.type=ClassTarget target7.width=120 -target7.x=660 -target7.y=520 -target8.editor.height=700 -target8.editor.width=900 -target8.editor.x=380 -target8.editor.y=39 +target7.x=630 +target7.y=470 +target8.editor.height=831 +target8.editor.width=721 +target8.editor.x=695 +target8.editor.y=22 target8.height=50 target8.name=TalkCommand target8.naviview.expanded=false target8.showInterface=false target8.type=ClassTarget target8.width=120 -target8.x=660 -target8.y=280 +target8.x=630 +target8.y=230 target9.editor.height=700 target9.editor.width=900 target9.editor.x=0 @@ -480,5 +504,5 @@ target9.naviview.expanded=false target9.showInterface=false target9.type=ClassTarget target9.width=110 -target9.x=500 -target9.y=400 +target9.x=470 +target9.y=350