From 587ccc6340d1e8fa017cc33a8ac847feb565e869 Mon Sep 17 00:00:00 2001 From: Justin Senn Date: Mon, 6 Feb 2023 18:11:34 +0100 Subject: [PATCH 01/51] update --- src/main/java/Snake/TextView.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/main/java/Snake/TextView.java diff --git a/src/main/java/Snake/TextView.java b/src/main/java/Snake/TextView.java new file mode 100644 index 0000000..f8adcc7 --- /dev/null +++ b/src/main/java/Snake/TextView.java @@ -0,0 +1,13 @@ +package Snake; + +import java.awt.*; + +public class TextView implements Drawable +{ + + @Override + public void draw(Graphics g) + { + + } +} From 6da135760b1d6c57ea327825f5de977a7eaa2872 Mon Sep 17 00:00:00 2001 From: Justin Senn Date: Mon, 6 Feb 2023 18:14:04 +0100 Subject: [PATCH 02/51] update --- src/main/java/Snake/TextView.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/Snake/TextView.java b/src/main/java/Snake/TextView.java index f8adcc7..29746ac 100644 --- a/src/main/java/Snake/TextView.java +++ b/src/main/java/Snake/TextView.java @@ -4,6 +4,30 @@ import java.awt.*; public class TextView implements Drawable { + public enum AnchorType { Left, Center, Right }; + + private String text; + + private Point position; + + private boolean visible; + + private AnchorType anchor; + + public TextView(String text, Point position) + { + this(text, position, true); + } + + public TextView(String text, Point position, boolean visible) + { + this.text = text; + this.position = position; + this.visible = visible; + this.anchor = AnchorType.Center; + } + + @Override public void draw(Graphics g) From 30ee3005f7c14a787b720e8a87216fbd405d61ba Mon Sep 17 00:00:00 2001 From: Justin Senn Date: Mon, 6 Feb 2023 18:17:33 +0100 Subject: [PATCH 03/51] update --- src/main/java/Snake/TextView.java | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main/java/Snake/TextView.java b/src/main/java/Snake/TextView.java index 29746ac..4fd6078 100644 --- a/src/main/java/Snake/TextView.java +++ b/src/main/java/Snake/TextView.java @@ -27,11 +27,38 @@ public class TextView implements Drawable this.anchor = AnchorType.Center; } + public void setText(String newText) + { + text = newText; + } + + public void setVisibility(boolean visibility) + { + visible = visibility; + } + + public void setAnchor(AnchorType newAnchor) + { + anchor = newAnchor; + } @Override public void draw(Graphics g) { + if(visible) + { + FontMetrics fontMetrics = g.getFontMetrics(); + int x = position.x; + int y = position.y + fontMetrics.getHeight(); + + if (anchor == AnchorType.Center) + x -= fontMetrics.stringWidth(text); + else if (anchor == AnchorType.Right) + x -= fontMetrics.stringWidth(text); + g.setColor(Color.WHITE); + g.drawString(text, x, y); + } } } From f66be06f005b6bc89d21ba499caa644467b4b0a4 Mon Sep 17 00:00:00 2001 From: Justin Senn Date: Mon, 6 Feb 2023 18:18:48 +0100 Subject: [PATCH 04/51] refactoring: --- src/main/java/Snake/TextView.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/Snake/TextView.java b/src/main/java/Snake/TextView.java index 4fd6078..e68bacf 100644 --- a/src/main/java/Snake/TextView.java +++ b/src/main/java/Snake/TextView.java @@ -50,10 +50,10 @@ public class TextView implements Drawable { FontMetrics fontMetrics = g.getFontMetrics(); int x = position.x; - int y = position.y + fontMetrics.getHeight(); + int y = position.y + fontMetrics.getHeight() / 2; if (anchor == AnchorType.Center) - x -= fontMetrics.stringWidth(text); + x -= fontMetrics.stringWidth(text) / 2; else if (anchor == AnchorType.Right) x -= fontMetrics.stringWidth(text); From 7ec0f4b68463621b793c861897c251ee8d9ac706 Mon Sep 17 00:00:00 2001 From: Justin Senn Date: Mon, 6 Feb 2023 19:47:25 +0100 Subject: [PATCH 05/51] update --- src/main/java/Snake/Controller.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/main/java/Snake/Controller.java diff --git a/src/main/java/Snake/Controller.java b/src/main/java/Snake/Controller.java new file mode 100644 index 0000000..52bc4a6 --- /dev/null +++ b/src/main/java/Snake/Controller.java @@ -0,0 +1,4 @@ +package Snake; + +public class Controller { +} From 5d680e3ebb3c4c06949fa1ed081fffdd5e922af1 Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Mon, 6 Feb 2023 19:59:50 +0100 Subject: [PATCH 06/51] Add AIGridGui Class --- src/main/java/BattleShip/AIGridGUI.java | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/main/java/BattleShip/AIGridGUI.java diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java new file mode 100644 index 0000000..1e9c686 --- /dev/null +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -0,0 +1,6 @@ +package BattleShip; +import javax.swing.*; + +public class AIGridGUI extends JPanel { + +} From 1be645b9e797d99a57cbc509ab9f82671fd74714 Mon Sep 17 00:00:00 2001 From: Justin Senn Date: Mon, 6 Feb 2023 20:43:56 +0100 Subject: [PATCH 07/51] update --- build-project.sh | 5 ++++- src/main/java/Snake/Controller.java | 2 ++ target/hellsgamers-1.0-SNAPSHOT.jar | Bin 1807 -> 17151 bytes target/maven-archiver/pom.properties | 2 +- .../compile/default-compile/createdFiles.lst | 21 ++++++++++++++++++ .../compile/default-compile/inputFiles.lst | 18 ++++++++++++++- .../default-testCompile/inputFiles.lst | 0 7 files changed, 45 insertions(+), 3 deletions(-) delete mode 100644 target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst diff --git a/build-project.sh b/build-project.sh index cc1f786..6dcd456 100644 --- a/build-project.sh +++ b/build-project.sh @@ -1 +1,4 @@ -#!/bin/bash \ No newline at end of file +cd hellsgamers +mvn clean install +read -p //enter to exit + diff --git a/src/main/java/Snake/Controller.java b/src/main/java/Snake/Controller.java index 52bc4a6..43058fe 100644 --- a/src/main/java/Snake/Controller.java +++ b/src/main/java/Snake/Controller.java @@ -1,4 +1,6 @@ package Snake; public class Controller { + + } diff --git a/target/hellsgamers-1.0-SNAPSHOT.jar b/target/hellsgamers-1.0-SNAPSHOT.jar index 3ae873c6e59a16958a145ed327552f5dd16b39f3..4d7fbd081e2ea176f3ec6b55b03262d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D$7En+}>!gpjj~-)JxpD7#P;EfOr5{ C`QeHH diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties index d4eaa29..4df9572 100644 --- a/target/maven-archiver/pom.properties +++ b/target/maven-archiver/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven -#Sun Jan 29 13:17:20 CET 2023 +#Mon Feb 06 20:43:15 CET 2023 groupId=Hellsgamers artifactId=hellsgamers version=1.0-SNAPSHOT diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst index 44ba78e..cb38d8f 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -1 +1,22 @@ +Snake\TextView.class +MenuPanel.class +PingPong\Score.class +PingPong\GamePanel.class +Snake\Window.class +Snake\Snake$1.class +MenuPanel$GameFrame.class +PingPong\Ball.class +Snake\TextView$AnchorType.class +MenuPanel$AL.class Main.class +PingPong\Paddle.class +Snake\Apple.class +Snake\Snake.class +PingPong\GameFrame.class +Snake\Controller.class +Snake\Drawable.class +MenuFrame.class +Snake\Snake$SnakeDirection.class +Snake\SnakeView.class +Snake\AppleView.class +Snake\GameView.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst index 66c2fd5..8dba2b3 100644 --- a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -1 +1,17 @@ -C:\Users\Berkan\IdeaProjects\hellsgamers\src\main\java\Main.java +C:\Users\senni\IdeaProjects\hellsgamers\src\main\java\MenuPanel.java +C:\Users\senni\IdeaProjects\hellsgamers\src\main\java\PingPong\Paddle.java +C:\Users\senni\IdeaProjects\hellsgamers\src\main\java\PingPong\Ball.java +C:\Users\senni\IdeaProjects\hellsgamers\src\main\java\Snake\AppleView.java +C:\Users\senni\IdeaProjects\hellsgamers\src\main\java\Snake\Controller.java +C:\Users\senni\IdeaProjects\hellsgamers\src\main\java\PingPong\GamePanel.java +C:\Users\senni\IdeaProjects\hellsgamers\src\main\java\Snake\Snake.java +C:\Users\senni\IdeaProjects\hellsgamers\src\main\java\MenuFrame.java +C:\Users\senni\IdeaProjects\hellsgamers\src\main\java\Snake\Apple.java +C:\Users\senni\IdeaProjects\hellsgamers\src\main\java\Snake\Window.java +C:\Users\senni\IdeaProjects\hellsgamers\src\main\java\Main.java +C:\Users\senni\IdeaProjects\hellsgamers\src\main\java\Snake\SnakeView.java +C:\Users\senni\IdeaProjects\hellsgamers\src\main\java\Snake\TextView.java +C:\Users\senni\IdeaProjects\hellsgamers\src\main\java\PingPong\Score.java +C:\Users\senni\IdeaProjects\hellsgamers\src\main\java\Snake\GameView.java +C:\Users\senni\IdeaProjects\hellsgamers\src\main\java\PingPong\GameFrame.java +C:\Users\senni\IdeaProjects\hellsgamers\src\main\java\Snake\Drawable.java diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst deleted file mode 100644 index e69de29..0000000 From 48ff5b4fce43e55b88dc4acd77533fcbed01deae Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Mon, 6 Feb 2023 20:49:05 +0100 Subject: [PATCH 08/51] Add some Implementation Methode to AIGridGUI --- src/main/java/BattleShip/AIGridGUI.java | 64 +++++++++++++++++++++++++ team.md | 2 +- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 1e9c686..cb1b9a4 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -1,6 +1,70 @@ package BattleShip; + import javax.swing.*; +import javax.swing.border.Border; +import java.awt.*; +import java.util.ArrayList; +import java.util.*; public class AIGridGUI extends JPanel { + ArrayList buttons = new ArrayList(); + ArrayList allShips = new ArrayList(); + // public ArrayList listeners = new ArrayList(); + + int[] testLocations; + int numOfGuesses = 0; + public String text; + int rows; + int columns; + boolean endGame = false; + boolean[] cellsGuessed; + boolean[] cellsHit; + boolean[] cellsKilled; + boolean randomGuess = true; + int f; // it is the first + Color Red = new Color(100, 0, 0); // + Border loweredBevel = BorderFactory.createLoweredBevelBorder(); + Border defaultBorder; + Ship shipToPlace; + boolean vertical = false; + boolean clear; + boolean shipsPlaced = false; + Ship destroyer = new Ship(2, "destroyer"); + Ship cruiser = new Ship(3, "cruiser"); + Ship submarine = new Ship(3, "submarine"); + Ship battleship = new Ship(4, "battleship"); + Ship aircraftCarrier = new Ship(5, "aircraft carrier"); + ArrayList directions = new ArrayList(); + Direction up = new Direction(); + Direction down = new Direction(); + Direction right = new Direction(); + Direction left = new Direction(); + + public AIGridGUI(int r, int c) { + + rows = r; + columns = c; + + //Create arrays to keep track of which cells have been guessed, hit, and killed/sunk. + + cellsGuessed = new boolean[(rows * columns)]; + cellsHit = new boolean[(rows * columns)]; + cellsKilled = new boolean[(rows * columns)]; + for(int i = 0; i < (rows * columns); i++) { + cellsGuessed[i] = false; + cellsHit[i] = false; + cellsKilled[i] = false; + } + + //Add all ships to an ArrayList to allow for cycling through all ships. + + allShips.add(destroyer); + allShips.add(cruiser); + allShips.add(submarine); + allShips.add(battleship); + allShips.add(aircraftCarrier); + + + } } diff --git a/team.md b/team.md index 969138d..5690043 100644 --- a/team.md +++ b/team.md @@ -1,4 +1,4 @@ - Berkan Sarp, fdai4616 - Justin Senn, fdai7107 - Eren Esen, fdai4581 -- \ No newline at end of file +- Brice Tchoumi, fdai6138 \ No newline at end of file From b9530e5089495f45d15d65bf99fd46333de090e9 Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Mon, 6 Feb 2023 20:49:51 +0100 Subject: [PATCH 09/51] Add some Implementation Methode to AIGridGUI --- target/classes/BattleShip/AIGridGUI.class | Bin 0 -> 2331 bytes target/classes/BattleShip/BSButton.class | Bin 0 -> 785 bytes target/classes/BattleShip/BShip.class | Bin 0 -> 262 bytes target/classes/BattleShip/Direction.class | Bin 0 -> 678 bytes target/classes/BattleShip/Ship.class | Bin 0 -> 873 bytes target/classes/Snake/AppleView.class | Bin 0 -> 971 bytes target/classes/Snake/GameView.class | Bin 0 -> 1549 bytes target/classes/Snake/Window.class | Bin 0 -> 2033 bytes 8 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 target/classes/BattleShip/AIGridGUI.class create mode 100644 target/classes/BattleShip/BSButton.class create mode 100644 target/classes/BattleShip/BShip.class create mode 100644 target/classes/BattleShip/Direction.class create mode 100644 target/classes/BattleShip/Ship.class create mode 100644 target/classes/Snake/AppleView.class create mode 100644 target/classes/Snake/GameView.class create mode 100644 target/classes/Snake/Window.class diff --git a/target/classes/BattleShip/AIGridGUI.class b/target/classes/BattleShip/AIGridGUI.class new file mode 100644 index 0000000000000000000000000000000000000000..a21b7becd014c42309c30f774136d8ffce22a165 GIT binary patch literal 2331 zcmah~Npl-T6#m+hEk*9cj+{NQvqEfT5o94DO6*up>?n3(6FW9e*hVvLdy=unj7E0M z9tiu+kt0|Rv3C}bjF=a_vQuy*BQ8)6Nu$YVdxi%0vm_^BT`03 zSuc^)A>x+j>HS5m+#s`w%CEPLN(+ss6aVcHLtvihd_I0mkGRF z`n=hhu9!_d4ojr*2#@a7Z5P=7fNe)4j_Sk5=T#88w&m#~9hZ2_RHUd2JK|Zka$-0s z&{B6_y6AD75?JG?Vi@>~iWNG6)4D=u1U7Z%Dy8r&LS-}zh?q>JVm%V4a8_Xb(7(cE z;>hxT?4aZpRiHCDCy~Y3IQsdUVktjsF^tlN3lja>a8V$UHz3lvYRizsMQypv%dp(Q z4y>tgmu&@sTM0QL@r3?+%d)X=#WpH2ra_f(+(6l(OAN*^z8a_JmQ4vjl@uElPx1*=&@9uIDL7 zcj&yt0&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attleShip/BShip.class b/target/classes/BattleShip/BShip.class new file mode 100644 index 0000000000000000000000000000000000000000..5809f278ff7e8939575c60289d36030ff7ab2d11 GIT binary patch literal 262 zcmZ9GI}XAy5JYG5ArQXe26R9{4#1}Xi3&jhqIZHt9EAi0!@a1GC^!IzLaZYyZ0UJt z*1MYb=lKFKMaPE)+k?}9iwdEWh?@vfksX6gn8-*IDif6{JtNrt!QMlaKh1^Ksociu z9Lx;~<fZLVKk$xxSu4S?olZveRAVkx2KVP)7euN5|@7djE^Y1b>@fi%2e&nfA-| uBNGZec%0Q7;>&57HC92X0eAQS-Py31T>Zr20c6E@pIxCqi_+q-j!s4^6xk&yb>JK5II^I9~zx3cp|ceVoM8?C%0^5!D^>VXE(2MCg zL4}Tt!;{&hA0}^ueq?B-gCOb!iPYy+(NZHxeWlKte0C68Vl3beLv><=R2t3eJvk^J zbc}f8Oj{r$uU>P+@Z1#6$T67CVihI=`K}5E<2S+ONTGUEJFME`3=8S2lu=aJ&JWUk6t=g75zYzvqxzcHMtBhiiS%hB4tPeMZK& nw0CnD+O%=4Y`$cVzU^ZRb=D65Yf)bf_kffnu93T8#%cZmSa^Wb literal 0 HcmV?d00001 diff --git a/target/classes/Snake/AppleView.class b/target/classes/Snake/AppleView.class new file mode 100644 index 0000000000000000000000000000000000000000..dde14d22361212c9c69b30b0015d13983ba24d70 GIT binary patch literal 971 zcmZ8gYi|-k6g>mmE{`dXMX9x|?*|VHzF*W7YCg^|m#f$F%_tU-(2?XwA zTQ#1iW<&voWpqrZ6Lo223A)biyRlQ#1J0{ui>;!e?F5t z3!wOyv7%#@;}R~<>fLfI$E81c_o{Y^dEBqWa23~dT<5rfn+)kd*c;dEcV&A(!ijqV zGE3~w=bK9AZH^rBq`f1&k7L(rs$Jx`bJE^ZOeKyo?h@oDX<6Hcrp2I>d&)l@_er(y zTFo_wX3HWMv>Yu_+H&@(N;ae|-X45u3HQCfZYWc%rs+ymPnw$7m83h}ICBOS-^ZQc z9OAYZPAhGnXc@9I=AM{PQ6gA}Au}~TSYwFoItOlByp~FGA~^GsGL!y#f$kf_J&K09 z9CQf{b<~u@)StrxiVvy!K;I$Ci-lvb!f)t%;qWn{N8p9!BN*RlDTGH94QLb-6q5v( zLYCrV>SXSBeUDgj?Sz8(qIB1cjlxBdkq16XXHt>grg*8dhg`O95|*9__}M Kca!#p@bW*~Zn?n# literal 0 HcmV?d00001 diff --git a/target/classes/Snake/GameView.class b/target/classes/Snake/GameView.class new file mode 100644 index 0000000000000000000000000000000000000000..323b53df5257f47cb346b60d1854cab8906b5841 GIT binary patch literal 1549 zcmZ8hT~`}b6x}x&7)XZl(GqH*m3}BmXi4$28j3=&F*Q&$m}L+X?^x5 z_~I|{#h1Elu)3DZXMc!4!sSx;olJ(*m9=ipoO|v*`<%1y{o|isegkkDy9vY)H(^*9 zz@Wgy1Nl%s%C(Mdr;)q6DIL`m7+kU)+g}!lr!!R(Lt$7>9{ag9`%pP8+jSB!k|c$q05veK5oWH;sW(Rm%2wva(qV5s5QVG~42<6O6J0}JfAtdquMNTVq^mwUSp zRL#$4cJ%OWT3Ey@EcZy-j$d#Ok6cGNzCfyvdC`+c`*y7rv~m`&S$G|9Fsbb;Px`t! zsdT1~V=46KlemSqOuTI&kEPz+gED#{0_MJKZKy{~Nqy|-6U!Ff!Mhxb6S&Xyu>0AY zSdBEX=E-BpfhMtnH4E?QdW<@q2^8_ZiIRo8(36Wsy5+jf1Dh$w8&reZlkKJ-`J#MU zprMyTE@IunhE}=JdhFB$hAVc%k$&5w^5*)gkLI~l?rOHjFTb4U;euP|fzh(Zire;T>W;1HkMy`L=q}?j#Tnxp5yOO5 zXkby(5V#lEn=okex^w-Io^NQ!`M;1ofyn*}b9;LF1j8LzS)+rA?2kxwFvE@6?Gs#i zimTa~r930LPkn7@CTZ7?`>K0r-%qaxGJh)_*+IB+*{1fpCG5%bnxo>^=Eif;5$swxGnHIRyJHI}tbYJkxL(5?-#}|F@kMj7 zHihI$X#L_Z8w5?XTH>nE<`1Wx>sqEu!XpkKohkytsE6=tffELP`7cuH$RRU$Gpz^rh0F zkG1b-O%rfqKAZ=d8qh8JA)hG%$qWdbyb< zD}{C@9zrS%HUNdX`<7#sm`OSx!w3@(i@ryq^0wYj;4(%fi7}Ft$}(a*tGsI96}(DH zN_8`ZuH|M&R+dueX{>B%uIl@)lfX4Z1ZBd&YnT*bearLbe1}W~9G&zlbeI<7jDgn! z<6Wy-(KL?ZO@)q}xL%QLM+Nt~fw!e~G3k{)@Z)%wMl0eH8pUw)>`+L5$_d;+M2<^x z%owtZc&ob1@19x1gfruNptGLn*EId6Hk-0RAy|HQ6vh3cyi5;)BP-{U6b>}Nz$S=k!TE{50GX0Q@; zy4XDV!BEn*gYU@kE^@N?h@4q7zAP**ScB&L8K-BPE zp=U$B(L?msFkl|x^2XrMA+9{fI4{>W4v~Hi^HiKNe}$QRqlULAOeNo;aD*E)yY*mF zz$POB()6U*)o^>A+PfQZYUf^HK2V6G2quN`8nWwVSKp+Oy5!GorT4Z|$0rNQk&GWa!;}2lQGrhwh3dI*Q|H0mB;2k4f!hme*#8&NOyQdV literal 0 HcmV?d00001 From e3802df79b5b69c8b6feb620b29cfa60db144fbc Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Mon, 6 Feb 2023 21:09:31 +0100 Subject: [PATCH 10/51] Update Implementation Methode AIGridGUI --- src/main/java/BattleShip/AIGridGUI.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index cb1b9a4..b017b6c 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -64,7 +64,25 @@ public class AIGridGUI extends JPanel { allShips.add(battleship); allShips.add(aircraftCarrier); + //Add all directions to an ArrayList to allow for comparing and sorting directions. + directions.add(up); + directions.add(down); + directions.add(right); + directions.add(left); + //Make grid that consists of r rows and c columns of buttons. + + GridLayout g = new GridLayout(rows,columns); + this.setLayout(g); + + for(int i = 0; i < (rows * columns); i++) { + BSButton b = new BSButton(); + b.setGridLocation(i); + buttons.add(b); + this.add(b); + } + + defaultBorder = buttons.get(0).getBorder(); } } From 29f7ebc26f765da449aed07adc2854c95d453f44 Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Mon, 6 Feb 2023 21:25:53 +0100 Subject: [PATCH 11/51] Update Implementation Methode AIGridGUI --- src/main/java/BattleShip/AIGridGUI.java | 61 ++++++++++++++++++++++ target/classes/BattleShip/AIGridGUI.class | Bin 2331 -> 2901 bytes 2 files changed, 61 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index b017b6c..0bfc9f9 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -85,4 +85,65 @@ public class AIGridGUI extends JPanel { defaultBorder = buttons.get(0).getBorder(); } + public void autoPlaceShips() { + + //If ships are to be placed automatically, randomly place each ship. + + for(Ship s : allShips) { + int shipLength = s.getLength(); + int clearSpace = 0; + testLocations = new int[shipLength]; + + //Randomly select starting position to place ship and check if sufficient space to place ship. + + while(clearSpace < shipLength) { + + //Randomly choose whether to place ship vertically or horizontally and choose location of ship. + + boolean vert = new Random().nextBoolean(); + int x; + int y; + + if(vert) { + + x = (int) (Math.random() * (columns)); + y = (int) (Math.random() * (rows - shipLength)); + for(int i = 0; i < shipLength; i++) { + testLocations[i] = x + (columns*(y+i)); + } + } else { + x = (int) (Math.random() * (columns - shipLength)); + y = (int) (Math.random() * (rows)); + for(int i = 0; i < shipLength; i++) { + testLocations[i] = x + i + (columns*y); + } + } + + //Check if the location is clear. + + clearSpace = 0; + for(int i = 0; i < shipLength; i++) { + if(buttons.get(testLocations[i]).getCellContents() == null) { + clearSpace++; + } + } + } + + //Set the contents of the chosen cells to contain the ship. + + for(int i = 0; i < shipLength; i++) { + buttons.get(testLocations[i]).setCellContents(s); + } + + testLocations = null; + } + + // + + + + text = "Ready to start the game."; + shipsPlaced = true; + } + } diff --git a/target/classes/BattleShip/AIGridGUI.class b/target/classes/BattleShip/AIGridGUI.class index a21b7becd014c42309c30f774136d8ffce22a165..e603c494a8fd0bf61d7e252dc389dea1f4b294da 100644 GIT binary patch delta 858 zcmZuuTTc^F5dMbUZDm(( zaJ?g5Kn2AcQA?D>7#~c~#24d>FZvtwjYM&}Mc~1loSE;;eCL}va|Uw0=E@)cymdiy2W#Z{gv}xl|df4<8&X=DL%5dVGg7dgQ5JI|1aIspN z*`|d<-l|}$-e?y4QjPR0xQI3UDkl1kNRuAPF>!-7=s+!LUA&Il^kVvBM6|8Y?U%(LC4=A=aFY1evfl}&3 z8TF!^ECgs6l{AVfdW~v&kDWAy8v24-`o^&zsH2~#$1n?&^S{r)gL^zVftf3C9}ghW z7&h85F*OB@U^F!`Mh}@sHhRP;gX>gd4Bp4w&l6^>f;hu^q7zv}%$r8RZ*)5mqiJm5 Li%*%8foFdKR1Vu@ delta 301 zcmcaAHd~16)W2Q(7#J9A876Mz5@DI_%Q}~jHzhSKu{5W|DZeNswP^ASRu48-4Np(a zu*rICCX?&fG$tQnv)8Qz>SAK30+K=u{0xi?5Pmg~U&BxfBpDb)8N`4jBSRfS{bW6M zTf+u0pMgP@K@BXg&tL$i8=-U)g9Dgv%pe7(n_h=m2uGfNK6TXfSjF?PUh3X6Rz*2AK?G r^#H{f!K_{&i;1BRC@jRl^dG2!g`I($kr62Qi$NWzrXMK7#4rH>@Axw# From dd5ac1e70856d41bca258827c7d86c6f4428cf44 Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Mon, 6 Feb 2023 21:30:40 +0100 Subject: [PATCH 12/51] Update Implementation Methode AIGridGUI --- src/main/java/BattleShip/AIGridGUI.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 0bfc9f9..fc1e823 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -138,9 +138,15 @@ public class AIGridGUI extends JPanel { testLocations = null; } - // - + //Mark all cells containing a ship and disable all cells in the grid. + for (BSButton bsb : buttons) { + if(bsb.getCellContents() != null) { + bsb.setBackground(Color.blue); + bsb.setBorder(loweredBevel); + } + bsb.setEnabled(false); + } text = "Ready to start the game."; shipsPlaced = true; From 0beb11e56f380a2d8f417fd321536ee3e6fb1d65 Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Mon, 6 Feb 2023 21:34:55 +0100 Subject: [PATCH 13/51] Update Implementation Methode AIGridGUI --- src/main/java/BattleShip/AIGridGUI.java | 4 ++++ target/classes/Snake/Controller.class | Bin 0 -> 267 bytes target/classes/Snake/TextView$AnchorType.class | Bin 0 -> 1148 bytes target/classes/Snake/TextView.class | Bin 0 -> 1969 bytes 4 files changed, 4 insertions(+) create mode 100644 target/classes/Snake/Controller.class create mode 100644 target/classes/Snake/TextView$AnchorType.class create mode 100644 target/classes/Snake/TextView.class diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index fc1e823..ea4014d 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -152,4 +152,8 @@ public class AIGridGUI extends JPanel { shipsPlaced = true; } + public boolean getEndGame() { + + return endGame; + } } diff --git a/target/classes/Snake/Controller.class b/target/classes/Snake/Controller.class new file mode 100644 index 0000000000000000000000000000000000000000..5bee98bb578a0da944c4bb962b9e4ed1bd74d766 GIT binary patch literal 267 zcmZ8b%WlFj5S-0}Ku8wyu`X z%1`Hif6RR{OptJ3e~2$fW*jgpIu69MFVH6o0a8Y910jZtS@({)J}@IZG6u+h0cv12 Al>h($ literal 0 HcmV?d00001 diff --git a/target/classes/Snake/TextView$AnchorType.class b/target/classes/Snake/TextView$AnchorType.class new file mode 100644 index 0000000000000000000000000000000000000000..fe89e53a26ef30de777f97360bbc5aee8ce0ade5 GIT binary patch literal 1148 zcmaJ<|4$NO9DZInIJnLvG7Us4vjk1a(ySn-W4hdKx^>3p`st)sJUd_7aajFVg z&7b?DTA%mz9555u`0#n&=kxvf^Y_PZ0IyKe5n;&K!ui09+x&A-b@`{sRZ-h-_}gDT z@+25E6EVceT6`~H7`3ismn1!5A}Q(d3Ks$QC3MY%DWTXKx4s`pZyy_&8aH*MObp=`<*9iM!5N0~1?#{$a*CcK>cy?y16~VC21amON5(`Jqg1Iw zSQD*7DtY91ExxtKu$b?Pu6RzfS?U7pz;{Kx)LlU)Q2ED9jN=Z?SayXQEHeyurwSuC z3e^N+22DGbKr#VS{(WHLA*STus*NVYc)rkYbSiSe)GCelH1(k63clGo+~xkZv+EI3 z{7>~lpLH^%twzo9s*dl<3}G5gIER!ieR&CV{9xauW|OvC7f#Ufi5JZms&wvh%?p<> z+Z8BRRqoTma*4sP8!f-a*IhZoz=ite8_ht+bGl-$<`~QkA-J!O#;Gr( zBiWUCTJs30TU*IU;R0kyk;;+`fmBwCj~Fq+^Oz!jfxHQ_@?*3y@EteKkp4;@!!-TI z)tgTIEM`Lf0wM}E(ro$^!)IWUAL-#gBE&prVHR`hos>f?S#cgw`U3j&Ozs4^Z|b?b zTqj&dQMQi9iZh=wq>REwiqHrJM&iG~cA{-W?H#QR-QJ0{X~~zTNZ<+8KA(C$44(T* zvFW?f6WlvSR5=rxa&+a~k15AE#pE#tWUIZK(ZbfAVu9WwSj01Bm+*qDls>}}Uan;R E0Zqi};Q#;t literal 0 HcmV?d00001 diff --git a/target/classes/Snake/TextView.class b/target/classes/Snake/TextView.class new file mode 100644 index 0000000000000000000000000000000000000000..f8a960d0e1d2be1b4cfe6bcd09e8098c9c77ed08 GIT binary patch literal 1969 zcmZ`)TU#1e6kP`gMsPG<(5OVKsahDU*5)3RBsDRTqDiC0*4{G00F%(c4<<4Gl>UMA zx%ndbzC82?^!N0kPx-pe83f|xfjPH**4}&VbvFNe{O~t`6_g_gpi75lAc&Aa- z?S>7E;G%&3%Beeh6K$3+!h?~duvtK+ptNR+!&1~+8K15 z5I>HD4%0vq^SsysQ|vOM*ZgIq)q;UVX(A3ISi;vjt{AwAYXZ^Moep4uFk@J^ol@E7 zKO=A5FmMyM1bXVKm^)6vD+>&tQRW1Fjv-}WS!N!5DsjR{;x{J5o9Kl z$mz(oBz&LtmJ-738P@Fr_{vS>D8$ujfl|1TbzFP% z9V$-An_)s98*7p?fsqbsk7cQBdy1X19BFgXp&jNUN&-Xe!xn@<@0MrfUu;?P z)t9xrz2?aG*L&PV7NjPrvrW6sM<976Z$`#-?b>R^s@H8UBkjkCX+E=V2z(2TGxi8} zs(|bQYUC?dBVQrM5bc84;CGX&N4(L+vD-|}YwsccQkIYTm2D10&=JKG&Zc}je21r8 z@rLpv)J%E`C|rpyaSyoGIL6HP(9Pr#40HYn{pQ3GqUKwS9$~WWYMeoVL24L&q6AIwm(0$Dbg^l@JD>B7Jdld zlR}meIqaOmiZO+gShK{MI|u6r#wD?S#O^6964SwhAD2n2hv*-$k_}96aNhq8U!?u<%lQVr3Ra$7*SMY}`EM{ZG0(Zt!1Z9Ikp2^+{>kk( z=xd!6(#f}2X<#)eO(%x61|G`1yCCJUfF6FAD32?UoivJTn86M1-(;V=g>~F!C6<}< z3T)g_`CMhB26^}uzmf4M`DWK9-V8e;o3pBNu~mg4p21?4d-T(Xu8&CTSP~-o9|m|Q X&)onD#0Ky2uL?!ZB5D>u>F(J7!TO7m literal 0 HcmV?d00001 From 1d55539da14ee4a400b9b5d6dff406d874d41f2e Mon Sep 17 00:00:00 2001 From: Justin Senn Date: Mon, 6 Feb 2023 21:49:47 +0100 Subject: [PATCH 14/51] update --- src/main/java/Snake/Controller.java | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/main/java/Snake/Controller.java b/src/main/java/Snake/Controller.java index 43058fe..329f303 100644 --- a/src/main/java/Snake/Controller.java +++ b/src/main/java/Snake/Controller.java @@ -1,6 +1,36 @@ package Snake; + +import javax.swing.*; +import java.awt.event.ActionEvent; + public class Controller { + private enum GameState { Running }; + private GameView gameView; + private Snake snakeModel; + private boolean inputHandled; + private GameState gameState; + + private class MoveAction extends AbstractAction + { + + private Snake.SnakeDirection direction; + + MoveAction(Snake.SnakeDirection direction) + { + this.direction = direction; + } + @Override + public void actionPerformed(ActionEvent e) + { + if(inputHandled && gameState == GameState.Running) + { + snakeModel.setDirection(direction); + inputHandled = false; + } + } + } + } From 50c194c3337545bd47bd32739934c957db3b40c4 Mon Sep 17 00:00:00 2001 From: Justin Senn Date: Mon, 6 Feb 2023 21:51:02 +0100 Subject: [PATCH 15/51] update --- src/main/java/Snake/Controller.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/Snake/Controller.java b/src/main/java/Snake/Controller.java index 329f303..6fb4a14 100644 --- a/src/main/java/Snake/Controller.java +++ b/src/main/java/Snake/Controller.java @@ -12,6 +12,19 @@ public class Controller { private boolean inputHandled; private GameState gameState; + private void initializeInputHandling() + { + final int CONDITION = JComponent.WHEN_IN_FOCUSED_WINDOW; + gameView.getInputMap(CONDITION).put(KeyStroke.getKeyStroke("W"), "move up"); + gameView.getInputMap(CONDITION).put(KeyStroke.getKeyStroke("A"), "move left"); + gameView.getInputMap(CONDITION).put(KeyStroke.getKeyStroke("S"), "move down"); + gameView.getInputMap(CONDITION).put(KeyStroke.getKeyStroke("D"), "move right"); + + gameView.getActionMap().put("move up", new MoveAction(Snake.SnakeDirection.UP)); + gameView.getActionMap().put("move left", new MoveAction(Snake.SnakeDirection.LEFT)); + gameView.getActionMap().put("move down", new MoveAction(Snake.SnakeDirection.DOWN)); + gameView.getActionMap().put("move right", new MoveAction(Snake.SnakeDirection.RIGHT)); + } private class MoveAction extends AbstractAction { From 6a8f0f3c1d8d02ab738e69a0e4502f5a098251ec Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Mon, 6 Feb 2023 21:51:19 +0100 Subject: [PATCH 16/51] Update Implementation Methode AIGridGUI --- src/main/java/BattleShip/AIGridGUI.java | 29 ++++++++++++++++++++++ target/classes/BattleShip/AIGridGUI.class | Bin 2901 -> 4913 bytes 2 files changed, 29 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index ea4014d..dbefd40 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -156,4 +156,33 @@ public class AIGridGUI extends JPanel { return endGame; } + + public void go() { + //Play a turn by making a guess at a cell. + + int guessLocation = 0; + boolean gameOver = true; + numOfGuesses++; + BSButton b = null; + Ship s = null; + boolean killed = false; + boolean isClear = false; + + if(randomGuess) { + //Find out the maximum ship length of the surviving ships. + int minClearSpace = 0; + for(Ship sh : allShips) { + if(!sh.isKilled() && sh.getLength() > minClearSpace) { + minClearSpace = sh.getLength(); + } + } + + //Create an array of all possible cells and shuffle the order of the cells. Potential guesses are drawn from this array. + + int[] guesses = new int[(rows * columns)]; + for(int i = 0; i < rows * columns; i++) { + guesses[i] = i; + } + } + } } diff --git a/target/classes/BattleShip/AIGridGUI.class b/target/classes/BattleShip/AIGridGUI.class index e603c494a8fd0bf61d7e252dc389dea1f4b294da..9814b983104401ef6f2a20478b7940a270f0e162 100644 GIT binary patch delta 2266 zcmZuy32;+Y6g@9Xf0F*Pr&7vNhJk5IX?4Uh!{T78BOp))97aHp-}aM~rb$hHSsXEA zWkAsZHOh`46biC04P_AvA|SW`iaW|CqM#xu0+z<}ep+PI&g8xO-#hod`|dgS^+fXK zZmz=(JNE$SC$QO-Zx6emV4jNkSRmjiG4!Bj1cCy|=^2A3YLm2_3ZulAGq7>JPa+m! zv4SNk-oR3UR{wP$|!Fquf|Ku`U z^A`uoTv!LI95$)gEVE6N$L9qCK3(&>uoc@B)Pz+;v0b2<>CJ>ZIYTsgY(mfsVxIq? z3zgWRVkdS9G-q!4y3dy%@Ef|{UK(JURnH|$3M?~s?IN$>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L6kuZNHQ|aW|%Wsip!R9?&JtAdBJ%M4j@SeV+JWOJ%4fsmn}O)_kzi1xD>e= zfqGaOYJud!%|EzUm>3sL{>yXPe=$(G2Ln69e+CVPB|xK@84oc?Ff3(Q#=y$Bn!yw- z#sakOGsAL*6(FO5td&4@j9}I(Ad87{F+%{uYKAoo%nWNMi}NY7uLCM$VptCVQKmpm From 4c5bbea894e20904081f20dc3a306e22cedc0ab5 Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Mon, 6 Feb 2023 21:57:43 +0100 Subject: [PATCH 17/51] Update Implementation Methode AIGridGUI --- src/main/java/BattleShip/AIGridGUI.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index dbefd40..5afe8d4 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -183,6 +183,13 @@ public class AIGridGUI extends JPanel { for(int i = 0; i < rows * columns; i++) { guesses[i] = i; } + Random rand = new Random(); + for(int i = 0; i < guesses.length; i++) { + int randInt = rand.nextInt(guesses.length); + int randGuess = guesses[randInt]; + guesses[randInt] = guesses[i]; + guesses[i] = randGuess; + } } } } From 6594ea59d624b694cc8cbbab9b772054caf7a3e3 Mon Sep 17 00:00:00 2001 From: Justin Senn Date: Mon, 6 Feb 2023 21:59:56 +0100 Subject: [PATCH 18/51] update --- src/main/java/Snake/Controller.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main/java/Snake/Controller.java b/src/main/java/Snake/Controller.java index 6fb4a14..23b6cfa 100644 --- a/src/main/java/Snake/Controller.java +++ b/src/main/java/Snake/Controller.java @@ -9,6 +9,9 @@ public class Controller { private enum GameState { Running }; private GameView gameView; private Snake snakeModel; + private SnakeView snakeView; + private Apple appleModel; + private AppleView appleView; private boolean inputHandled; private GameState gameState; @@ -25,6 +28,31 @@ public class Controller { gameView.getActionMap().put("move down", new MoveAction(Snake.SnakeDirection.DOWN)); gameView.getActionMap().put("move right", new MoveAction(Snake.SnakeDirection.RIGHT)); } + + private void selectApplesPosition() + { + do + { + appleModel.selectGridPosition(gameView.getGridSize()); + } while(!isApplePositionIsValid()); + appleView.setPosition(appleModel.getPosition()); + } + private boolean isApplePositionIsValid() + { + var snakeSegments = snakeModel.getBodySegments(); + for(var segmentPosition: snakeSegments) + { + if(segmentPosition.equals(appleModel.getPosition())) + return false; + } + return true; + } + private void updateSnakeViewPosition() + { + snakeView.setPositions(snakeModel.getBodySegments()); + } + + private class MoveAction extends AbstractAction { From 963b9a27d79af82c74117bf9f72e942633a533bd Mon Sep 17 00:00:00 2001 From: Justin Senn Date: Mon, 6 Feb 2023 22:04:32 +0100 Subject: [PATCH 19/51] update --- src/main/java/Snake/Controller.java | 53 ++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/src/main/java/Snake/Controller.java b/src/main/java/Snake/Controller.java index 23b6cfa..625ed14 100644 --- a/src/main/java/Snake/Controller.java +++ b/src/main/java/Snake/Controller.java @@ -3,17 +3,23 @@ package Snake; import javax.swing.*; import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; public class Controller { - private enum GameState { Running }; + private enum GameState { Running, Paused, PlayerLosed }; private GameView gameView; private Snake snakeModel; private SnakeView snakeView; private Apple appleModel; private AppleView appleView; + private TextView scoreView; + private TextView messageView; + private boolean inputHandled; + private Timer timer; private GameState gameState; + private int score; private void initializeInputHandling() { @@ -28,7 +34,52 @@ public class Controller { gameView.getActionMap().put("move down", new MoveAction(Snake.SnakeDirection.DOWN)); gameView.getActionMap().put("move right", new MoveAction(Snake.SnakeDirection.RIGHT)); } + private void addButtonActionListeners(Window window) + { + window.addStartActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + if(gameState == GameState.Paused) + { + messageView.setVisibility(false); + gameState = GameState.Running; + timer.start(); + } + else if(gameState == GameState.PlayerLosed) + { + messageView.setVisibility(false); + restartGame(); + } + } + }); + window.addPauseActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + if(gameState == GameState.Running) + { + messageView.setText("Game Paused."); + messageView.setVisibility(true); + gameView.repaint(); + gameState = GameState.Paused; + timer.stop(); + } + } + }); + } + private void restartGame() + { + snakeModel.reset(); + score = 0; + scoreView.setText("Score: " + Integer.toString(score)); + selectApplesPosition(); + gameState = GameState.Running; + timer.start(); + } private void selectApplesPosition() { do From af93a2a3189904721e6b3f2d11730a2586f31041 Mon Sep 17 00:00:00 2001 From: Justin Senn Date: Mon, 6 Feb 2023 22:11:42 +0100 Subject: [PATCH 20/51] update --- src/main/java/Snake/Controller.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/java/Snake/Controller.java b/src/main/java/Snake/Controller.java index 625ed14..2c5ec16 100644 --- a/src/main/java/Snake/Controller.java +++ b/src/main/java/Snake/Controller.java @@ -103,6 +103,31 @@ public class Controller { snakeView.setPositions(snakeModel.getBodySegments()); } + private void timerTick() + { + snakeModel.update(); + inputHandled = true; + checkIfAppleWasEaten(); + if(snakeModel.isSelfColliding()) + { + messageView.setText("You Lose! Click 'Start Game' to play agaiin."); + messageView.setVisibility(true); + gameState = GameState.PlayerLosed; + timer.stop(); + } + updateSnakeViewPosition(); + gameView.repaint(); + } + private void checkIfAppleWasEaten() + { + if(appleModel.getPosition().equals(snakeModel.getHeadPosition())) + { + score += 1; + scoreView.setText("Score: " + Integer.toString(score)); + snakeModel.grow(); + selectApplesPosition(); + } + } private class MoveAction extends AbstractAction { From cc83727a1da6f81307175433f7b3cb4fb4d9ca65 Mon Sep 17 00:00:00 2001 From: Justin Senn Date: Mon, 6 Feb 2023 22:14:13 +0100 Subject: [PATCH 21/51] update --- src/main/java/Snake/Controller.java | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/main/java/Snake/Controller.java b/src/main/java/Snake/Controller.java index 2c5ec16..3ae5372 100644 --- a/src/main/java/Snake/Controller.java +++ b/src/main/java/Snake/Controller.java @@ -2,6 +2,7 @@ package Snake; import javax.swing.*; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -21,6 +22,42 @@ public class Controller { private GameState gameState; private int score; + Controller(Window window, Snake snakeModel, SnakeView snakeView, Apple appleModel, AppleView appleView) + { + gameView = window.getGameView(); + this.snakeModel = snakeModel; + this.snakeView = snakeView; + this.appleModel = appleModel; + this.appleView = appleView; + + scoreView = new TextView("Scores: 9", new Point(15, 15)); + messageView = new TextView("Click 'Start Game' to Begin . (W-up, S-down, A-left, D-Right)", + new Point(gameView.getWidth()/2, gameView.getHeight() - 15)); + + scoreView.setAnchor(TextView.AnchorType.Left); + + gameView.addView(scoreView); + gameView.addView(messageView); + + initializeInputHandling(); + addButtonActionListeners(window); + + timer = new Timer(10, new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + timerTick(); + } + }); + + gameState = GameState.Paused; + inputHandled = true; + score = 0; + + selectApplesPosition(); + updateSnakeViewPosition(); + } private void initializeInputHandling() { final int CONDITION = JComponent.WHEN_IN_FOCUSED_WINDOW; From 5797e52424dc81a416260f7ac5ae28d3df45de3b Mon Sep 17 00:00:00 2001 From: Justin Senn Date: Mon, 6 Feb 2023 22:15:07 +0100 Subject: [PATCH 22/51] refactoring: --- src/main/java/Snake/Controller.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/Snake/Controller.java b/src/main/java/Snake/Controller.java index 3ae5372..b310d5e 100644 --- a/src/main/java/Snake/Controller.java +++ b/src/main/java/Snake/Controller.java @@ -30,7 +30,7 @@ public class Controller { this.appleModel = appleModel; this.appleView = appleView; - scoreView = new TextView("Scores: 9", new Point(15, 15)); + scoreView = new TextView("Scores: 0", new Point(15, 15)); messageView = new TextView("Click 'Start Game' to Begin . (W-up, S-down, A-left, D-Right)", new Point(gameView.getWidth()/2, gameView.getHeight() - 15)); @@ -147,7 +147,7 @@ public class Controller { checkIfAppleWasEaten(); if(snakeModel.isSelfColliding()) { - messageView.setText("You Lose! Click 'Start Game' to play agaiin."); + messageView.setText("You Lose! Click 'Start Game' to play again."); messageView.setVisibility(true); gameState = GameState.PlayerLosed; timer.stop(); From ae063b839a8aad70fc4ddc151f53bbd8b5e32a83 Mon Sep 17 00:00:00 2001 From: Justin Senn Date: Mon, 6 Feb 2023 22:16:03 +0100 Subject: [PATCH 23/51] refactoring: --- src/main/java/Snake/Controller.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Snake/Controller.java b/src/main/java/Snake/Controller.java index b310d5e..e751b57 100644 --- a/src/main/java/Snake/Controller.java +++ b/src/main/java/Snake/Controller.java @@ -42,7 +42,7 @@ public class Controller { initializeInputHandling(); addButtonActionListeners(window); - timer = new Timer(10, new ActionListener() + timer = new Timer(100, new ActionListener() { @Override public void actionPerformed(ActionEvent e) From 282dbaeba6069a9d626f57e43cb03717f02a439a Mon Sep 17 00:00:00 2001 From: Justin Senn Date: Mon, 6 Feb 2023 22:17:27 +0100 Subject: [PATCH 24/51] update --- src/main/java/Snake/Game.java | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/main/java/Snake/Game.java diff --git a/src/main/java/Snake/Game.java b/src/main/java/Snake/Game.java new file mode 100644 index 0000000..3131df2 --- /dev/null +++ b/src/main/java/Snake/Game.java @@ -0,0 +1,5 @@ +package Snake; + +public class Game { + +} From ba218b5315ea6b009a1be236f794db48c05e51ba Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Mon, 6 Feb 2023 22:19:42 +0100 Subject: [PATCH 25/51] Update Implementation Methode AIGridGUI --- src/main/java/BattleShip/AIGridGUI.java | 31 ++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 5afe8d4..3f059a4 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -156,7 +156,6 @@ public class AIGridGUI extends JPanel { return endGame; } - public void go() { //Play a turn by making a guess at a cell. @@ -190,6 +189,36 @@ public class AIGridGUI extends JPanel { guesses[randInt] = guesses[i]; guesses[i] = randGuess; } + + int numCellsTried = 0; + + //Test potential guesses and mark clear if criteria met. + while(!isClear && numCellsTried < guesses.length) { + guessLocation = guesses[numCellsTried]; + numCellsTried++; + + //If the cell has not already been guessed, test whether there are enough clear spaces in at least one direction. + if(!cellsGuessed[guessLocation]) { + + int u = guessLocation; + int upCount = -1; + while(u >= 0 && !cellsHit[u]) { + u = moveUp(u); + upCount++; + } + } + } + } + } + + //Return the location of a cell one space in the given direction, or return -1 if out of bounds. + + public int moveUp(int u) { + int dirUp = u - columns; + if(dirUp < 0) { + return -1; + } else { + return dirUp; } } } From 8b0beb2cc31a5eb050592b3445561c89bff3e792 Mon Sep 17 00:00:00 2001 From: Justin Senn Date: Mon, 6 Feb 2023 22:22:10 +0100 Subject: [PATCH 26/51] update --- src/main/java/Snake/Game.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/Snake/Game.java b/src/main/java/Snake/Game.java index 3131df2..9de31b4 100644 --- a/src/main/java/Snake/Game.java +++ b/src/main/java/Snake/Game.java @@ -1,5 +1,24 @@ package Snake; public class Game { + public Game() { + final int VIEW_SIZE = 100; + final int GRID_SIZE = 10; + final int CELL_SIZE = VIEW_SIZE / GRID_SIZE; + + Window gameWindow = new Window(VIEW_SIZE, GRID_SIZE); + + Snake snakeModel = new Snake(GRID_SIZE); + SnakeView snakeView = new SnakeView(CELL_SIZE); + + Apple appleModel = new Apple(); + AppleView appleView = new AppleView(CELL_SIZE); + + GameView gameView = gameWindow.getGameView(); + gameView.addView(snakeView); + gameView.addView(appleView); + + new Controller(gameWindow, snakeModel, snakeView, appleModel, appleView); + } } From a92cb1c8e0b633338738b1fa05aef1436afcccc4 Mon Sep 17 00:00:00 2001 From: Justin Senn Date: Mon, 6 Feb 2023 22:22:42 +0100 Subject: [PATCH 27/51] refactoring: --- src/main/java/Snake/Game.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/Snake/Game.java b/src/main/java/Snake/Game.java index 9de31b4..bc0faf4 100644 --- a/src/main/java/Snake/Game.java +++ b/src/main/java/Snake/Game.java @@ -3,8 +3,8 @@ package Snake; public class Game { public Game() { - final int VIEW_SIZE = 100; - final int GRID_SIZE = 10; + final int VIEW_SIZE = 250; + final int GRID_SIZE = 25; final int CELL_SIZE = VIEW_SIZE / GRID_SIZE; Window gameWindow = new Window(VIEW_SIZE, GRID_SIZE); From 6d2cda9390dbd2c8857250fd9a5de30edb4bc2f2 Mon Sep 17 00:00:00 2001 From: Justin Senn Date: Mon, 6 Feb 2023 22:23:01 +0100 Subject: [PATCH 28/51] refactoring: --- src/main/java/Snake/Game.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/Snake/Game.java b/src/main/java/Snake/Game.java index bc0faf4..f020037 100644 --- a/src/main/java/Snake/Game.java +++ b/src/main/java/Snake/Game.java @@ -3,8 +3,8 @@ package Snake; public class Game { public Game() { - final int VIEW_SIZE = 250; - final int GRID_SIZE = 25; + final int VIEW_SIZE = 500; + final int GRID_SIZE = 50; final int CELL_SIZE = VIEW_SIZE / GRID_SIZE; Window gameWindow = new Window(VIEW_SIZE, GRID_SIZE); From cb07a19bb574ac96849a74cc9db4d97f99e7e9bb Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Mon, 6 Feb 2023 22:26:02 +0100 Subject: [PATCH 29/51] Update Implementation Methode AIGridGUI --- src/main/java/BattleShip/AIGridGUI.java | 14 ++++++++++++++ target/classes/BattleShip/AIGridGUI.class | Bin 4913 -> 5755 bytes 2 files changed, 14 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 3f059a4..d251e69 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -206,6 +206,12 @@ public class AIGridGUI extends JPanel { u = moveUp(u); upCount++; } + int d = guessLocation; + int downCount = -1; + while(d >= 0 && !cellsHit[d]) { + d = moveDown(d); + downCount++; + } } } } @@ -221,4 +227,12 @@ public class AIGridGUI extends JPanel { return dirUp; } } + public int moveDown(int d) { + int dirDown = d + columns; + if(dirDown >= (rows*columns)) { + return -1; + } else { + return dirDown; + } + } } diff --git a/target/classes/BattleShip/AIGridGUI.class b/target/classes/BattleShip/AIGridGUI.class index 9814b983104401ef6f2a20478b7940a270f0e162..115b6fe9b747cb90f44537c3218542e750f2ea3f 100644 GIT binary patch delta 1596 zcmZWpZERCj7=GS++uruxw(C~9wRFms8H6cpxLK3ACDWPcj5?!`h$ah5TC>U4jeVd$ zG);6rG$xwRXyT?A0hy5sSq4J}&S-{FK#c=rl{)i16$Vc~l(eo#lQ zw)VA&6&*@+%!_d)ax2jt?T;si#*A%plhN6fjN8T@h3@Q0bae@&hi-d1>e_phTZs!i zahllw={26hQioC&Z@X3COZK$YC0bj%mUp%!;_2r-6#-|w zrE^6GeR5aa={=rh1wS$$4L@_p34^&v zDu7?$HgnA>!dajIU!>#2vDh#=L6dXD)3}YslNsYs$dv zL1p6V!=rO{jkZcP&&aYmTG2OqJQ}mKm^WngBT89&$g1c=ZfVFG#&wDtqcLBvpF|S_v;BiCfo>ONGZqtXV2L&|@l9;)n+RYtf*4@w-$Dd$ zvn3fe;~m`27B0s&wr`LFumh_xj3==Z&v1VZyRa^W5!QD%P4`gsJ-mxiyieI)e1MNJ zhQmZh@DXq7Cpdxq4B!Aq^i%fsGjZT^G4X}?@TCNBP!`~jT#v)D1Yb!xuf6KpKFnhf z5w@`w9wa#mYPLM&3yTn?EYjwRM(D*$D7TMI($tAgnMJZ%67iHYMdBp#k?b0A5&2Of zJ~4<4X0}({*ut@0hxOuNU>+vWEEZ2qH5_w;qe+=~DdR&VOT<^n`PLASV*BFhoSJLx zxh17U#cxl4M8c9oNVu5u0w(fI`*zT7i&y~EZ$@57rLDFe5?_V+OQP=u`t=Aj-o z^fFWrc16@w=wi@A^i=%;-5a~-bg?WmO{edi8G2d!+k1WATHjiGzImk4f3P@y7icq# z_~YJ~ml!s7GFfZa`s?gLf6cPTN;*7IOjCiOczedQQ8t&_Zo=zOZdU zn^)w$v`2&bATFKD5ye+ygF)OeIXhbZuwz2>&3F`O;x*O8%srO#hPSw8fc4Q^9LzND zcpsJ)`XHW(&_^N1^s|jmOcEn+AEg?+&y+=NW>Wi&+H_TB`@%M-NzuuwsAPhzwDLvr zGIr6(S0Rt{|Fie?7TQU$ks-cmDwi{278O}KN{T7!Bc3be3{z6XXkeP}LUC3w&kt?J zsWz>;OlvAfzB@~^ Date: Mon, 6 Feb 2023 23:03:27 +0100 Subject: [PATCH 30/51] Update Implementation Methode AIGridGUI --- src/main/java/BattleShip/AIGridGUI.java | 16 ++++++++++++++++ target/classes/BattleShip/AIGridGUI.class | Bin 5755 -> 6013 bytes target/classes/Snake/Controller.class | Bin 267 -> 5899 bytes 3 files changed, 16 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index d251e69..4a3c5dc 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -212,6 +212,13 @@ public class AIGridGUI extends JPanel { d = moveDown(d); downCount++; } + + int r = guessLocation; + int rightCount = -1; + while(r >= 0 && !cellsHit[r]) { + r = moveRight(r); + rightCount++; + } } } } @@ -235,4 +242,13 @@ public class AIGridGUI extends JPanel { return dirDown; } } + + public int moveRight(int r) { + int dirRight = r + 1; + if((dirRight >= (rows * columns)) || (dirRight % columns == 0)) { + return -1; + } else { + return dirRight; + } + } } diff --git a/target/classes/BattleShip/AIGridGUI.class b/target/classes/BattleShip/AIGridGUI.class index 115b6fe9b747cb90f44537c3218542e750f2ea3f..44a5878775297156ba84e24b650a39c70c6c8fb5 100644 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Cz?xLs4imDzCoU>BcjBZHI+5$CZ*rXE zo#5{;X%_WM(zvebhQqk2>b5lAnT6abkh}9C?-R&<`H(#Vc_4tK@le%m$FR4Drh4=c zKAgsrLQKGS2jFK4!S@B=gN5J+0`MUpoHK9)A&Px5g!!vkY%qM5`PHFJ;QsQCL6X?&9R$L0PrX?!-v zzTDWhoxZ&SlM&BjQIqvcP2iUz)s(fjM+V}lb7_w1G``@6595!|S0BcgkK&u)#Qq%< zQ3vn?3A2N^GL08=yr;t=g{%3SB>xm6%3~xAGkSLLgU?PQi}tx>)#bh$DA^lGP)oW~ z`A?_(G>u=7;cxexe3^h5a*)O!)A)<<9Ao0S%0$q$EC|;z#;zy7x90Jw_4%k~!57X& zGFS!-pW>5*-}$6VmH*Ywy!vm)yd#R`Zx6z}VP}61bJjIv7^~18l#F?D|H&7NpX7_h zMuI8S0JxDm$xR3|Pv+xREa0NNh^w+>MVOq!s8mbUGUJ=`1Kmr}pe|O+DNGBo#4bLh zl@O7)0%Kmocnhyus_5)jC~J}I{(0qPpk5rFXV$MxJQ@cjy!u*WbCfm zvZVF~q*fU+YJy)q(#j{RrtHBio-C_YXNmiHSDaQeA_vs0ObDoRq{Q%Kd|K7#JTsr= z8Mu?ta2K_^88aUbU4e%fab>&FAE8V@ox9?Fw)RiW3Guyk=c3^c#lcO;gQ zp+o~O)oC>^Exwr>>0z`MUn!Mul+ZPpjS|5*DShuf%v61Z)#y>i={~0GV`#?yJc*VT zO4Ll(ub^^8YNcAmtL)l)xhx&$c6ymwO-L!FUBmx%Y6G8I`P|CE^U~!t{PgAjIUIX8 fE}z2p%2g*_u#e+m7tfCd=g0l4+N3tC9@P8~gzM;p delta 133 zcmeCy>t^CQ^>5cc1_lOO27!rO`eN)19E=PC!Fh? Date: Mon, 6 Feb 2023 23:13:04 +0100 Subject: [PATCH 31/51] Update Implementation Methode AIGridGUI --- src/main/java/BattleShip/AIGridGUI.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 4a3c5dc..984fd96 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -219,6 +219,13 @@ public class AIGridGUI extends JPanel { r = moveRight(r); rightCount++; } + + int l = guessLocation; + int leftCount = -1; + while(l >= 0 && !cellsHit[l]) { + l = moveLeft(l); + leftCount++; + } } } } @@ -251,4 +258,12 @@ public class AIGridGUI extends JPanel { return dirRight; } } + public int moveLeft(int l) { + int dirLeft = l - 1; + if((dirLeft < 0) || (l % columns == 0)) { + return -1; + } else { + return dirLeft; + } + } } From ca2a7838abac8216157303b81e10168b6e0a72b1 Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Mon, 6 Feb 2023 23:43:51 +0100 Subject: [PATCH 32/51] Update Implementation Methode AIGridGUI --- src/main/java/BattleShip/AIGridGUI.java | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 984fd96..e67f2de 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -226,8 +226,35 @@ public class AIGridGUI extends JPanel { l = moveLeft(l); leftCount++; } + + if((upCount + downCount + 1) >= minClearSpace || (rightCount + leftCount + 1) >= minClearSpace) { + isClear = true; + } } } + } else { + //If nonrandom guess (locked onto a particular ship that has been hit but not killed), determine where to guess. + + int attempts = 1; + + while(!isClear) { + attempts++; + + if(attempts == 1) { + + //Starting from the location of the first hit on the ship, test each direction to determine how many consecutive hits have been made in that direction. + + int u = f; + int upCount = -1; + while(u >= 0 && cellsHit[u] && !cellsKilled[u]) { + u = moveUp(u); + upCount++; + } + up.setCell(u); + up.setCount(upCount); + } + } + } } From 2ebf65ff1bf8d7cdaebbf02d5543ba840076ad1d Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Mon, 6 Feb 2023 23:56:58 +0100 Subject: [PATCH 33/51] Update Implementation Methode AIGridGUI --- src/main/java/BattleShip/AIGridGUI.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index e67f2de..f9a75ef 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -252,6 +252,15 @@ public class AIGridGUI extends JPanel { } up.setCell(u); up.setCount(upCount); + + int d = f; + int downCount = -1; + while(d >= 0 && cellsHit[d] && !cellsKilled[d]) { + d = moveDown(d); + downCount++; + } + down.setCell(d); + down.setCount(downCount); } } From 9251c50cb02fa520741a6fa1b35c08eb76dd7519 Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 00:01:39 +0100 Subject: [PATCH 34/51] Update Implementation Methode AIGridGUI --- src/main/java/BattleShip/AIGridGUI.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index f9a75ef..4108b81 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -261,6 +261,15 @@ public class AIGridGUI extends JPanel { } down.setCell(d); down.setCount(downCount); + + int r = f; + int rightCount = -1; + while(r >= 0 && cellsHit[r] && !cellsKilled[r]) { + r = moveRight(r); + rightCount++; + } + right.setCell(r); + right.setCount(rightCount); } } From 7001d7fb1d77934c7250ec8fdfa760512c2acf05 Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 00:05:04 +0100 Subject: [PATCH 35/51] Update Implementation AIGridGUI class --- src/main/java/BattleShip/AIGridGUI.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 4108b81..59ffb6a 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -270,6 +270,15 @@ public class AIGridGUI extends JPanel { } right.setCell(r); right.setCount(rightCount); + + int l = f; + int leftCount = -1; + while(l >= 0 && cellsHit[l] && !cellsKilled[l]) { + l = moveLeft(l); + leftCount++; + } + left.setCell(l); + left.setCount(leftCount); } } From 599ce9dde8b6ba68386a35532379b9a93b54a047 Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 00:25:30 +0100 Subject: [PATCH 36/51] Update Implementation AIGridGUI class --- src/main/java/BattleShip/AIGridGUI.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 59ffb6a..3ae73be 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -279,6 +279,12 @@ public class AIGridGUI extends JPanel { } left.setCell(l); left.setCount(leftCount); + + //Determine which direction had the most consecutive hits and try to continue in that direction. + + DirectionCompare dc = new DirectionCompare(); + Collections.sort(directions, dc); + guessLocation = directions.get(0).getCell(); } } @@ -320,4 +326,11 @@ public class AIGridGUI extends JPanel { return dirLeft; } } + //Implement comparator to compare directions. + + class DirectionCompare implements Comparator { + public int compare(Direction one, Direction two) { + return ((Integer) two.getCount()).compareTo((Integer) one.getCount()); + } + } } From 90fb04ca002e7745dfc7cdf5481b15c72e50c5ca Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 00:41:49 +0100 Subject: [PATCH 37/51] Update Implementation AIGridGUI class --- src/main/java/BattleShip/AIGridGUI.java | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 3ae73be..d802f03 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -286,6 +286,32 @@ public class AIGridGUI extends JPanel { Collections.sort(directions, dc); guessLocation = directions.get(0).getCell(); } + + //If first guess is not clear or is out of bounds, continue trying other directions until one is found that works. + + if(attempts == 1) { + guessLocation = directions.get(1).getCell(); + } + + if(attempts == 2) { + guessLocation = directions.get(2).getCell(); + } + + if(attempts == 3) { + guessLocation = directions.get(3).getCell(); + } + + if(attempts > 4) { + guessLocation = new Random().nextInt(cellsGuessed.length); + } + + //Test whether the guess is valid and in an unguessed space. + + if(guessLocation >= 0) { + if(!cellsGuessed[guessLocation]) { + isClear = true; + } + } } } From cbdc91630f2aa6a0670ec1fdfd43de61cb0dcd45 Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 01:02:04 +0100 Subject: [PATCH 38/51] Update Implementation AIGridGUI class --- src/main/java/BattleShip/AIGridGUI.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index d802f03..57aaab0 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -315,6 +315,26 @@ public class AIGridGUI extends JPanel { } } + + //Mark the guess on the grid. + + cellsGuessed[guessLocation] = true; + b = buttons.get(guessLocation); + s = b.getCellContents(); + b.setBorder(loweredBevel); + + if(s == null) { + //If no ship in that cell, mark as a miss. + text = "Other player missed. Your turn."; + b.setBackground(Color.BLUE); + } else { + //Check if guess killed a ship. + killed = s.counter(); + if(killed) { + text = "Your " + s.getName() + " was sunk. Your turn."; + boolean unkilledCells = false; + } + } } //Return the location of a cell one space in the given direction, or return -1 if out of bounds. From d64957ee58f24a401f9159cd523f763083e5436c Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 01:06:52 +0100 Subject: [PATCH 39/51] Update Implementation AIGridGUI class --- src/main/java/BattleShip/AIGridGUI.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 57aaab0..042c5ba 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -333,6 +333,22 @@ public class AIGridGUI extends JPanel { if(killed) { text = "Your " + s.getName() + " was sunk. Your turn."; boolean unkilledCells = false; + for(BSButton bu : buttons) { + //Mark killed cells. + if(bu.getCellContents() == s) { + bu.setBackground(Red); + cellsKilled[bu.getGridLocation()] = true; + } + //Mark if any cell remains that has been hit but not yet killed. If so, lock onto that cell. + if(cellsHit[bu.getGridLocation()] && !cellsKilled[bu.getGridLocation()]) { + f = bu.getGridLocation(); + unkilledCells = true; + } + } + //If all hit cells have been killed, return to random guessing. + if(!unkilledCells) { + randomGuess = true; + } } } } From a7ef8c818e2c6d4bbfd34e90d5ec17d96c6de1fd Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 01:09:36 +0100 Subject: [PATCH 40/51] Update Implementation AIGridGUI class --- src/main/java/BattleShip/AIGridGUI.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 042c5ba..783cc30 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -349,6 +349,16 @@ public class AIGridGUI extends JPanel { if(!unkilledCells) { randomGuess = true; } + } else { + //If cell hit but not killed, mark cell appropriately. + text = "Other player got a hit. Your turn."; + b.setBackground(Color.red); + //If previously random guessing, switch to locking onto the hit cell. + if(randomGuess) { + f = b.getGridLocation(); + randomGuess = false; + } + cellsHit[guessLocation] = true; } } } From 186ea8c1f2ecfd06d8e0b237e5b7204557d664ac Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 01:14:12 +0100 Subject: [PATCH 41/51] Update Implementation AIGridGUI class --- src/main/java/BattleShip/AIGridGUI.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 783cc30..f682b1c 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -361,6 +361,19 @@ public class AIGridGUI extends JPanel { cellsHit[guessLocation] = true; } } + + //Mark game as not over unless all ships killed. + for(Ship sh : allShips) { + if(!sh.isKilled()) { + gameOver = false; + } + } + + //Game over message. + if(gameOver) { + text = "You Lost in " + numOfGuesses + " guesses."; + endGame = true; + } } //Return the location of a cell one space in the given direction, or return -1 if out of bounds. From 3167f700f18f44f6caf91ff1ca09ece111ad9a5d Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 01:35:46 +0100 Subject: [PATCH 42/51] Update Implementation AIGridGUI class --- src/main/java/BattleShip/AIGridGUI.java | 34 +++++++++++++++++++++- target/classes/BattleShip/AIGridGUI.class | Bin 6013 -> 9291 bytes 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index f682b1c..845abf4 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -3,13 +3,15 @@ package BattleShip; import javax.swing.*; import javax.swing.border.Border; import java.awt.*; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; import java.util.ArrayList; import java.util.*; public class AIGridGUI extends JPanel { ArrayList buttons = new ArrayList(); ArrayList allShips = new ArrayList(); - // public ArrayList listeners = new ArrayList(); + public ArrayList listeners = new ArrayList(); int[] testLocations; int numOfGuesses = 0; @@ -152,6 +154,18 @@ public class AIGridGUI extends JPanel { shipsPlaced = true; } + public void placeShips() { + + //Add listeners to all cells in grid to listen for ship placement. + + for(int i = 0; i < buttons.size(); i++) { + listeners.add(new SetShipsListener()); + buttons.get(i).addMouseListener(listeners.get(i)); + } + + shipToPlace = allShips.get(0); + text = "Place " + shipToPlace.getName() + ". Right click to toggle horizontal/vertical."; + } public boolean getEndGame() { return endGame; @@ -418,4 +432,22 @@ public class AIGridGUI extends JPanel { return ((Integer) two.getCount()).compareTo((Integer) one.getCount()); } } + + //Listen for mouse actions to place ships. + + class SetShipsListener implements MouseListener { + public void mouseEntered(MouseEvent e) { + + } + + public void mouseReleased(MouseEvent e) { + + } + + public void mouseExited(MouseEvent e) { + + } + public void mouseClicked(MouseEvent e) {} + public void mousePressed(MouseEvent e) {} + } } diff --git a/target/classes/BattleShip/AIGridGUI.class b/target/classes/BattleShip/AIGridGUI.class index 44a5878775297156ba84e24b650a39c70c6c8fb5..5cba1940b6fdddb930a50d7a13ea07accf960d52 100644 GIT binary patch literal 9291 zcmai434B!LwLjXln(R}%Oge?B zRB;s9m1%5A#*?WaO{Hlfo#_xneQRs$tc|jLrbYEM3nE$PM48InW8^nA2kA7LZPFZz z=29b5b)i_7CR0%-wIb4$Nv3u)P3%fJk&M%p+~uU4=u&5=6L%q)CfCnWh;s_*R685p zWhJH4Et*dYaP)Y=cBYztvF%KY!g6^3PA8R#bw%QGq>os1wvtF%#Jx5i>2jhbH8YhJ zXi-$*hv85l>ZCKNGJu6MgLAWLWRJns3*H3qAZB1-XnUmoZ}Xzh5|w@$-e$%!b#u^?y+1i%}vVj zKV{LabQ_M}?PTQmtsbN@Vow0V!R;2^A?_Rioa=<5y}K;>jQC(l)Y%cq#=RB6yU(Ki z^jYX2mT^)MxVt!rhg${DR&Tz!nC_;}n{)BIz~G<=_x;c#G_~ z*P<`deK>zYO;_b`kLA0GzGTst=_@YZZBC*))1z>x`1ngKYFie5}fki*0AGyYy z3(j>e?8#%ZyX`rP{*#_ZU;&xsiAX2BO^kKRtc`wp5s`nL6N&B)Ws;$ECX&j8GCfYH z8!2k8Sk+4w{gnO-;2EXc$^w`4!m3!<&n)`6Xx2!_u5e8H1=I8bndMXNv<@dD0!&My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1Vl~4N>xDRiDS&az_W!W1z*EA)MTvv9%m0eroD;2yKrfAXKyZg8ryhR(l&3k)?mVUQHgW6#YYTdfS Y$DdYD7}mg$z&eSMQ>lqOut!z@8`R30f&c&j From ceca0a72877993fa5271a3bb495de4d45818ae37 Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 01:40:54 +0100 Subject: [PATCH 43/51] Update Implementation AIGridGUI class --- src/main/java/BattleShip/AIGridGUI.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 845abf4..03c5596 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -437,7 +437,9 @@ public class AIGridGUI extends JPanel { class SetShipsListener implements MouseListener { public void mouseEntered(MouseEvent e) { - + //Highlight cell when mouse entered. + BSButton cell = (BSButton) e.getSource(); + highlightCells(cell, 0); } public void mouseReleased(MouseEvent e) { @@ -450,4 +452,10 @@ public class AIGridGUI extends JPanel { public void mouseClicked(MouseEvent e) {} public void mousePressed(MouseEvent e) {} } + + public void highlightCells(BSButton b, int x) { + BSButton cell = b; + int actionToTake = x; + clear = true; + } } From cd138ac8978f3d459256df77fc989deeb46dd890 Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 01:44:26 +0100 Subject: [PATCH 44/51] Update Implementation AIGridGUI class --- src/main/java/BattleShip/AIGridGUI.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 03c5596..db4a1a2 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -443,7 +443,8 @@ public class AIGridGUI extends JPanel { } public void mouseReleased(MouseEvent e) { - + //If mouse released on cell clear for ship placement, place ship and mark appropriater cells. + BSButton cell = (BSButton) e.getSource(); } public void mouseExited(MouseEvent e) { @@ -457,5 +458,15 @@ public class AIGridGUI extends JPanel { BSButton cell = b; int actionToTake = x; clear = true; + + //Check whether sufficient spaces are clear to place the ship. + if(vertical) { + for(int i = 0; i < shipToPlace.getLength(); i++) { + int testing = cell.getGridLocation() + (i * columns); + if(testing > (rows * columns) || buttons.get(testing).getCellContents() != null) { + clear = false; + } + } + } } } From f304f64e0f3323f488aed3112c5239fe08e284cc Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 01:46:49 +0100 Subject: [PATCH 45/51] Update Implementation AIGridGUI class --- src/main/java/BattleShip/AIGridGUI.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index db4a1a2..1ba45bf 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -445,6 +445,25 @@ public class AIGridGUI extends JPanel { public void mouseReleased(MouseEvent e) { //If mouse released on cell clear for ship placement, place ship and mark appropriater cells. BSButton cell = (BSButton) e.getSource(); + if(e.getButton() == MouseEvent.BUTTON1 && clear) { + highlightCells(cell, 1); + if(allShips.indexOf(shipToPlace) < (allShips.size() - 1)) { + //If more ships still to place, switch to next ship to be placed. + int nextShip = allShips.indexOf(shipToPlace) + 1; + shipToPlace = allShips.get(nextShip); + text = "Place " + shipToPlace.getName() + ". Right click to toggle horizontal/vertical."; + } else { + //If no more ships to place, disable cells and start gameplay. + for(int i = 0; i < buttons.size(); i++) { + BSButton bsb = buttons.get(i); + bsb.removeMouseListener(listeners.get(i)); + bsb.setEnabled(false); + } + text = "Ready to start the game."; + shipsPlaced = true; + } + clear = false; + } } public void mouseExited(MouseEvent e) { From e84238bea8c0ed4474bc09613c581b1fe190cc0a Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 01:50:07 +0100 Subject: [PATCH 46/51] Update Implementation AIGridGUI class --- src/main/java/BattleShip/AIGridGUI.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 1ba45bf..067352c 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -464,6 +464,17 @@ public class AIGridGUI extends JPanel { } clear = false; } + + if(e.getButton() == MouseEvent.BUTTON3) { + //Toggle whether ship placement is vertical or horizontal. + vertical = !vertical; + for(BSButton bsb : buttons) { + if(bsb.getCellContents() == null) { + bsb.setBorder(defaultBorder); + } + } + highlightCells(cell, 0); + } } public void mouseExited(MouseEvent e) { From 422b6270834427dbd52b60d1894e7a012b44d1e6 Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 01:58:56 +0100 Subject: [PATCH 47/51] Update Implementation AIGridGUI class --- src/main/java/BattleShip/AIGridGUI.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 067352c..0137f24 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -475,6 +475,17 @@ public class AIGridGUI extends JPanel { } highlightCells(cell, 0); } + + if(e.getButton() == MouseEvent.BUTTON3) { + //Toggle whether ship placement is vertical or horizontal. + vertical = !vertical; + for(BSButton bsb : buttons) { + if(bsb.getCellContents() == null) { + bsb.setBorder(defaultBorder); + } + } + highlightCells(cell, 0); + } } public void mouseExited(MouseEvent e) { From 7aa576245ca3c0a7a9b059b7da8771be21251f7c Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 02:04:58 +0100 Subject: [PATCH 48/51] Update Implementation AIGridGUI class --- src/main/java/BattleShip/AIGridGUI.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 0137f24..0af94b9 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -489,7 +489,9 @@ public class AIGridGUI extends JPanel { } public void mouseExited(MouseEvent e) { - + //Unhighlight cells when mouse exited. + BSButton cell = (BSButton) e.getSource(); + highlightCells(cell, 2); } public void mouseClicked(MouseEvent e) {} public void mousePressed(MouseEvent e) {} From 350462421e9589f955441f60477301b4278c96dd Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 02:39:16 +0100 Subject: [PATCH 49/51] Update Implementation AIGridGUI class --- src/main/java/BattleShip/AIGridGUI.java | 29 +++++++++++++++++++++- target/classes/BattleShip/AIGridGUI.class | Bin 9291 -> 10055 bytes 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 0af94b9..dcb864b 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -26,7 +26,10 @@ public class AIGridGUI extends JPanel { int f; // it is the first Color Red = new Color(100, 0, 0); // Border loweredBevel = BorderFactory.createLoweredBevelBorder(); + Border raisedbevel = BorderFactory.createRaisedBevelBorder(); Border defaultBorder; + //empty = BorderFactory.createEmptyBorder(4, 4, 4, 4); + Border compound = BorderFactory.createCompoundBorder(); Ship shipToPlace; boolean vertical = false; boolean clear; @@ -499,7 +502,7 @@ public class AIGridGUI extends JPanel { public void highlightCells(BSButton b, int x) { BSButton cell = b; - int actionToTake = x; + int action = x; clear = true; //Check whether sufficient spaces are clear to place the ship. @@ -511,5 +514,29 @@ public class AIGridGUI extends JPanel { } } } + + if(clear) { + if(vertical) { + + for(int i = 0; i < shipToPlace.getLength(); i++) { + BSButton bsb = buttons.get(cell.getGridLocation() + (i * columns)); + //If mouse entered, highlight cells via lowered bevel. + if(action == 1) { + bsb.setBorder(raisedbevel); + } else { + //If mouse released, place ship and color ship cells. + if(action == 2) { + bsb.setCellContents(shipToPlace); + bsb.setBackground(Color.gray); + bsb.setBorder(raisedbevel); + } else { + //If mouse exited, unhighlight cells. + bsb.setBorder(compound); + } + } + } + } + } } + } diff --git a/target/classes/BattleShip/AIGridGUI.class b/target/classes/BattleShip/AIGridGUI.class index 5cba1940b6fdddb930a50d7a13ea07accf960d52..487df6c0615f20130b48fcd178b7409992e0ea4b 100644 GIT binary patch literal 10055 zcmai43wTu3wO;F-lbo5!$&(x)B*36NBP3LGtO-y_5R8O?gol74lguF*n9Rg^@K9T- zrd2N%Tk4~LZIN2jsG^_h0**nM{K& zYp=c5-fOStp8W94+Yt6G@Mj!Zh8h^LtB*0WG*6e{HwRR{@RI2M!jDFIemWDC$A14Ae7Bo%aw zMPsRo$%B9KhEJe4<4`ffpsi@kpXatupBx zrV_QI@V0b)b0U^V251sZ7U@iZAf~spw9Hs7%cog1on}BJE1U>ZnR|@fqQ(H7M>9>D zWlZMth9aE3kPfx7 z-knxb`hZ2}(;OTYtk{c}w3-{9OWb^P`r$rIb_dq0? zbUM>f*o;Y=M%vZF>{Ngp*8rmyZKf?uTBaB0&OcNRS6x7lMRCD1B8hEr*=nyv*9xE@ z8SUy$3nXPxTA{?8O$xBpqHSVpMl!KY8Q%_zt`mUSnTTb2;tFnh#v?52 zUD(oaJly3Zp&}-I8szg-qp7_~`L6)&AzeOqTXYY723H7*ihH6nESCi_P4}4YlXL86 zs?B4hY$EQ&aR&ETuK$2NDWDwxvle}hK9A#fIcYh5i-)O{*b{*4;695Eib4B<=USrN z-u)JRQ7o)D;%o|MV&06nAa71Dt9&P2;TReDU5j{i?oAecn9-*&# z0mAkCSrpuTcR1DNY{w1}A=b%?uUYgceI4hID{y6&_Q-uNrU8ov>9D)+Rwv$-?p8FE z=l+I8kJAzCJ`HGo3N(g(6K`K@Bkf^`#4HZSoCe#Y>{wpN+e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klR!4X$f%@H~1Gmy_Qi)%_k(^DSOWZ*vE|!y9o=ckuk$M}Oor{e^F&zw#}3 z)4Y}5OV%Y7@9h3$d-u;t5(KPt@jfwRS#F(mJ?C+su=-POj5>Iiy|2Q?(4AqTS4=YIpE7 zZ9mV@?&X=<*Z4H;FwfSW7ih0@SbK}l(%$1HZG@ZkQeLcA@j3c5UZ&Uc za{Y8(p`XR=`eI(Iui^{zwY*Nhkk{)M^F}?&oAd;4(X+f&zk)B)Z{Umd8+n`l72d8N z;)wnjck16`M}LiX=zrjD{T+_!f8<{MZyeX(=Y)QO`wbsoW>}my#&O1|;j9tjUB*nl z(pbSCGuH4`##+9{=-}&&O*~*kd5;m}>m_q>2E`Q03_c$vM1T?~AtW;fpy!F)hF&qW zUBRo-lOL+)snsB~doQn1t8dc*6hc^qcCUr@s;LAzzKSnEuN2zdrpoLx=y)rNrD`gN zcAN264Xhh+Ay|)IC7p`bnGNWf)Qh*)jiBj=#f|VL6juTDyUJ#)2BGC?imo5Jo~q~u z_-$B|&<*mturZ-qtToa-ims*2M=36JOSH?ti_k6AGT=q%mT8A^$}PMVT;0X@@I{z2 z^{>z}z8GaxK);dtc^fJT(^vuQA|bzIaxcqkMh{p7x|yK3VCTyiGkKSjs|;}x1WLbFvN#;BzBxTTmBh&1;oX~(I|#9QW3nsi($ zwFl8_l-lb!O=GS-j_Pdecftth0}!{BQDodDJBefsRa(KCSIHemDZ(?3)1(i4r9?!@ zSg-+Ds;a8&qf{9_j{mrzO1=f4bd;up+oKfFrWUzn<`j%=hy_1jcomcb@;Z)OCN)8C zbW!bR$)|m_R%$8tDq0CS5#NLh+|8hQ3vB39s;&yT+dPQ_fzm!62Jt^eqL96&B#Bz< z7`A{UejxEkCa_aTPE;hfFOpF0R!9d Date: Tue, 7 Feb 2023 02:43:41 +0100 Subject: [PATCH 50/51] Update Implementation AIGridGUI class --- src/main/java/BattleShip/AIGridGUI.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index dcb864b..0a4a986 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -538,5 +538,8 @@ public class AIGridGUI extends JPanel { } } } + public boolean Ships() { + return shipsPlaced; + } } From 556ba4544941fe30859fcbbf79f64a17fe76bd5a Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 02:45:38 +0100 Subject: [PATCH 51/51] Update Implementation AIGridGUI class --- src/main/java/BattleShip/AIGridGUI.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 0a4a986..ddcae2f 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -542,4 +542,8 @@ public class AIGridGUI extends JPanel { return shipsPlaced; } + public String Text() { + return text; + } + }