From 40701ac566b0bdd7ec3b8078fd5b2ea26dda94ea Mon Sep 17 00:00:00 2001 From: fdai4581 Date: Tue, 7 Feb 2023 21:15:48 +0100 Subject: [PATCH 01/28] update --- src/main/java/BattleShip/GridGUI.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/BattleShip/GridGUI.java b/src/main/java/BattleShip/GridGUI.java index 7756d31..155bfee 100644 --- a/src/main/java/BattleShip/GridGUI.java +++ b/src/main/java/BattleShip/GridGUI.java @@ -1,5 +1,8 @@ package BattleShip; +import javax.swing.*; +import javax.swing.border.Border; +import java.awt.*; import java.util.ArrayList; import java.util.Random; @@ -11,6 +14,10 @@ public class GridGUI { int numOfGuesses = 0; int rows; int columns; + boolean clicked = false; + boolean endGame = false; + Color darkRed = new Color(100, 80, 0); + Border loweredBevel = BorderFactory.createLoweredBevelBorder(); Ship destroyer = new Ship(2, "destroyer"); Ship cruiser = new Ship(3, "cruiser"); From e9510b0b95121129012c4a1c207b9303e54bff1e Mon Sep 17 00:00:00 2001 From: fdai4581 Date: Tue, 7 Feb 2023 21:17:53 +0100 Subject: [PATCH 02/28] refactoring: color change --- src/main/java/BattleShip/GridGUI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/BattleShip/GridGUI.java b/src/main/java/BattleShip/GridGUI.java index 155bfee..425a0bc 100644 --- a/src/main/java/BattleShip/GridGUI.java +++ b/src/main/java/BattleShip/GridGUI.java @@ -16,7 +16,7 @@ public class GridGUI { int columns; boolean clicked = false; boolean endGame = false; - Color darkRed = new Color(100, 80, 0); + Color darkRed = new Color(100, 0, 0); Border loweredBevel = BorderFactory.createLoweredBevelBorder(); Ship destroyer = new Ship(2, "destroyer"); From cf64f311ce329cfb1abddb011f91e0a290988786 Mon Sep 17 00:00:00 2001 From: fdai4581 Date: Tue, 7 Feb 2023 21:21:47 +0100 Subject: [PATCH 03/28] update --- src/main/java/BattleShip/GridGUI.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/BattleShip/GridGUI.java b/src/main/java/BattleShip/GridGUI.java index 425a0bc..26550b1 100644 --- a/src/main/java/BattleShip/GridGUI.java +++ b/src/main/java/BattleShip/GridGUI.java @@ -3,6 +3,8 @@ package BattleShip; import javax.swing.*; import javax.swing.border.Border; import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.Random; @@ -70,4 +72,9 @@ public class GridGUI { } } } + public class MyCellListener implements ActionListener { + public void actionPerformed(ActionEvent a) { + + } + } } \ No newline at end of file From e708788bcfef2a3d49e29cccf94c38b86b52f580 Mon Sep 17 00:00:00 2001 From: fdai4581 Date: Tue, 7 Feb 2023 21:23:31 +0100 Subject: [PATCH 04/28] update --- src/main/java/BattleShip/GridGUI.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/BattleShip/GridGUI.java b/src/main/java/BattleShip/GridGUI.java index 26550b1..cf58c54 100644 --- a/src/main/java/BattleShip/GridGUI.java +++ b/src/main/java/BattleShip/GridGUI.java @@ -74,7 +74,13 @@ public class GridGUI { } public class MyCellListener implements ActionListener { public void actionPerformed(ActionEvent a) { - + if(!clicked) { + BSButton cell = (BSButton) a.getSource(); + Ship s = cell.getCellContents(); + boolean killed = false; + numOfGuesses++; + boolean gameOver = true; + } } } } \ No newline at end of file From 399b0c82f127cc3bf1fb3aaa798ca7b3b0b3c300 Mon Sep 17 00:00:00 2001 From: fdai4581 Date: Tue, 7 Feb 2023 21:27:39 +0100 Subject: [PATCH 05/28] update --- src/main/java/BattleShip/GridGUI.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/java/BattleShip/GridGUI.java b/src/main/java/BattleShip/GridGUI.java index cf58c54..b1b4a38 100644 --- a/src/main/java/BattleShip/GridGUI.java +++ b/src/main/java/BattleShip/GridGUI.java @@ -14,6 +14,7 @@ public class GridGUI { ArrayList allShips = new ArrayList(); int[] testLocations; int numOfGuesses = 0; + String text = ""; int rows; int columns; boolean clicked = false; @@ -80,6 +81,30 @@ public class GridGUI { boolean killed = false; numOfGuesses++; boolean gameOver = true; + cell.setEnabled(false); + cell.setBorder(loweredBevel); + + if(s == null) { + //Mark cell as missed. + text = "You missed. Other player's turn..."; + cell.setBackground(Color.lightGray); + } else { + killed = s.counter(); + if(killed) { + //Mark all of the ship's cells as killed. + text = "You sunk the " + s.getName() + "! Other player's turn..."; + for(BSButton bu : buttons) { + if(bu.getCellContents() == s) { + bu.setBackground(darkRed); + } + } + } else { + //Mark cell as hit. + text = "You got a hit. Other player's turn..."; + cell.setBackground(Color.red); + } + } + } } } From 2312ee54d4bdf1cbef74fb52f9213b2b99681d6a Mon Sep 17 00:00:00 2001 From: fdai4581 Date: Tue, 7 Feb 2023 21:30:35 +0100 Subject: [PATCH 06/28] update --- src/main/java/BattleShip/GridGUI.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/BattleShip/GridGUI.java b/src/main/java/BattleShip/GridGUI.java index b1b4a38..d94c26a 100644 --- a/src/main/java/BattleShip/GridGUI.java +++ b/src/main/java/BattleShip/GridGUI.java @@ -104,7 +104,11 @@ public class GridGUI { cell.setBackground(Color.red); } } - + for(Ship sh : allShips) { + if(!sh.isKilled()) { + gameOver = false; + } + } } } } From 511bfc72f45aa855676c2266f25993d89fce1f75 Mon Sep 17 00:00:00 2001 From: fdai4581 Date: Tue, 7 Feb 2023 21:32:46 +0100 Subject: [PATCH 07/28] update --- src/main/java/BattleShip/GridGUI.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/BattleShip/GridGUI.java b/src/main/java/BattleShip/GridGUI.java index d94c26a..158f734 100644 --- a/src/main/java/BattleShip/GridGUI.java +++ b/src/main/java/BattleShip/GridGUI.java @@ -109,7 +109,15 @@ public class GridGUI { gameOver = false; } } + if(gameOver) { + text = "You win! You took " + numOfGuesses + " guesses."; + endGame = true; + } + + clicked = true; } } } -} \ No newline at end of file +} + + From 5a864fbea6108d3033124c046c112987c103244a Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 21:33:16 +0100 Subject: [PATCH 08/28] Refratoring Color Red to Darkred --- src/main/java/BattleShip/AIGridGUI.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index ddcae2f..8918acd 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -24,7 +24,7 @@ public class AIGridGUI extends JPanel { boolean[] cellsKilled; boolean randomGuess = true; int f; // it is the first - Color Red = new Color(100, 0, 0); // + Color darkRed = new Color(100, 0, 0); // Border loweredBevel = BorderFactory.createLoweredBevelBorder(); Border raisedbevel = BorderFactory.createRaisedBevelBorder(); Border defaultBorder; @@ -353,7 +353,7 @@ public class AIGridGUI extends JPanel { for(BSButton bu : buttons) { //Mark killed cells. if(bu.getCellContents() == s) { - bu.setBackground(Red); + bu.setBackground(darkRed); cellsKilled[bu.getGridLocation()] = true; } //Mark if any cell remains that has been hit but not yet killed. If so, lock onto that cell. From d475d3834d01841c42ba6241018f4af88f0db6da Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 21:43:17 +0100 Subject: [PATCH 09/28] Refratoring int f to firstHit --- src/main/java/BattleShip/AIGridGUI.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 8918acd..bf9c8ac 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -23,7 +23,7 @@ public class AIGridGUI extends JPanel { boolean[] cellsHit; boolean[] cellsKilled; boolean randomGuess = true; - int f; // it is the first + int firstHit; Color darkRed = new Color(100, 0, 0); // Border loweredBevel = BorderFactory.createLoweredBevelBorder(); Border raisedbevel = BorderFactory.createRaisedBevelBorder(); @@ -261,7 +261,7 @@ public class AIGridGUI extends JPanel { //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 u = firstHit; int upCount = -1; while(u >= 0 && cellsHit[u] && !cellsKilled[u]) { u = moveUp(u); @@ -270,7 +270,7 @@ public class AIGridGUI extends JPanel { up.setCell(u); up.setCount(upCount); - int d = f; + int d = firstHit; int downCount = -1; while(d >= 0 && cellsHit[d] && !cellsKilled[d]) { d = moveDown(d); @@ -279,7 +279,7 @@ public class AIGridGUI extends JPanel { down.setCell(d); down.setCount(downCount); - int r = f; + int r = firstHit; int rightCount = -1; while(r >= 0 && cellsHit[r] && !cellsKilled[r]) { r = moveRight(r); @@ -288,7 +288,7 @@ public class AIGridGUI extends JPanel { right.setCell(r); right.setCount(rightCount); - int l = f; + int l = firstHit; int leftCount = -1; while(l >= 0 && cellsHit[l] && !cellsKilled[l]) { l = moveLeft(l); @@ -358,7 +358,7 @@ public class AIGridGUI extends JPanel { } //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(); + firstHit = bu.getGridLocation(); unkilledCells = true; } } @@ -372,7 +372,7 @@ public class AIGridGUI extends JPanel { b.setBackground(Color.red); //If previously random guessing, switch to locking onto the hit cell. if(randomGuess) { - f = b.getGridLocation(); + firstHit = b.getGridLocation(); randomGuess = false; } cellsHit[guessLocation] = true; From 7152084ac6ed16a3b51732a1b76b12955f969ea8 Mon Sep 17 00:00:00 2001 From: fdai4581 Date: Tue, 7 Feb 2023 21:47:11 +0100 Subject: [PATCH 10/28] update --- src/main/java/BattleShip/GridGUI.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/BattleShip/GridGUI.java b/src/main/java/BattleShip/GridGUI.java index 158f734..f7023f5 100644 --- a/src/main/java/BattleShip/GridGUI.java +++ b/src/main/java/BattleShip/GridGUI.java @@ -73,6 +73,8 @@ public class GridGUI { } } } + public boolean getClicked() {return clicked;} + public class MyCellListener implements ActionListener { public void actionPerformed(ActionEvent a) { if(!clicked) { From 4f5368ed0e71868fcbc086cbf0a4ed37eb21e4a9 Mon Sep 17 00:00:00 2001 From: fdai4581 Date: Tue, 7 Feb 2023 21:48:57 +0100 Subject: [PATCH 11/28] update --- src/main/java/BattleShip/GridGUI.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/BattleShip/GridGUI.java b/src/main/java/BattleShip/GridGUI.java index f7023f5..45401c3 100644 --- a/src/main/java/BattleShip/GridGUI.java +++ b/src/main/java/BattleShip/GridGUI.java @@ -74,7 +74,9 @@ public class GridGUI { } } public boolean getClicked() {return clicked;} - + public void setClicked() { + clicked = false; + } public class MyCellListener implements ActionListener { public void actionPerformed(ActionEvent a) { if(!clicked) { From 7f5ab5a893c2b8d397b7495803c4bd4b2c1cf5c6 Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 21:50:00 +0100 Subject: [PATCH 12/28] Refratoring attemps --- src/main/java/BattleShip/AIGridGUI.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index bf9c8ac..c012d19 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -252,7 +252,7 @@ public class AIGridGUI extends JPanel { } else { //If nonrandom guess (locked onto a particular ship that has been hit but not killed), determine where to guess. - int attempts = 1; + int attempts = 0; while(!isClear) { attempts++; @@ -306,15 +306,15 @@ public class AIGridGUI extends JPanel { //If first guess is not clear or is out of bounds, continue trying other directions until one is found that works. - if(attempts == 1) { + if(attempts == 2) { guessLocation = directions.get(1).getCell(); } - if(attempts == 2) { + if(attempts == 3) { guessLocation = directions.get(2).getCell(); } - if(attempts == 3) { + if(attempts == 4) { guessLocation = directions.get(3).getCell(); } From 4123340fdc06863ab6dad7d3dba48bfb87cd7ba0 Mon Sep 17 00:00:00 2001 From: fdai4581 Date: Tue, 7 Feb 2023 21:50:06 +0100 Subject: [PATCH 13/28] update --- src/main/java/BattleShip/GridGUI.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/BattleShip/GridGUI.java b/src/main/java/BattleShip/GridGUI.java index 45401c3..9b8c21a 100644 --- a/src/main/java/BattleShip/GridGUI.java +++ b/src/main/java/BattleShip/GridGUI.java @@ -77,6 +77,9 @@ public class GridGUI { public void setClicked() { clicked = false; } + public boolean getEndGame() { + return endGame; + } public class MyCellListener implements ActionListener { public void actionPerformed(ActionEvent a) { if(!clicked) { From bc5ef191b585d44bd19d6b69db9a76ba461a7774 Mon Sep 17 00:00:00 2001 From: fdai4581 Date: Tue, 7 Feb 2023 21:51:27 +0100 Subject: [PATCH 14/28] update --- src/main/java/BattleShip/GridGUI.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/BattleShip/GridGUI.java b/src/main/java/BattleShip/GridGUI.java index 9b8c21a..5a9b32a 100644 --- a/src/main/java/BattleShip/GridGUI.java +++ b/src/main/java/BattleShip/GridGUI.java @@ -80,6 +80,11 @@ public class GridGUI { public boolean getEndGame() { return endGame; } + public void setEndGame() { + for(JButton j : buttons){ + j.setEnabled(false); + } + } public class MyCellListener implements ActionListener { public void actionPerformed(ActionEvent a) { if(!clicked) { From 03356df8d2fa3c38c80c7daa98d6ecc966f53f56 Mon Sep 17 00:00:00 2001 From: fdai4581 Date: Tue, 7 Feb 2023 21:54:35 +0100 Subject: [PATCH 15/28] update --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6f03192..b3a5105 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,17 @@ # HellsGamers -Pong Game developed by Eren Esen, Berkan Sarp, Justin Senn, Brice Tchoumi +"3-Games" developed by Eren Esen, Berkan Sarp, Justin Senn, Brice Tchoumi Pong game is a two-player table tennis-themed console game. The game involves two paddles and a moving ball. The players have to move paddles in an upwards or downwards direction and save the ball from getting hit onto the wall. If the ball hits the wall then it’s a score for another player. The game ends at 20 Points. + +Battleship is a strategy type guessing game for two players. It is played on ruled grids on which each +player's fleet of warships are marked. The locations of the fleets are concealed from the other player. Players +alternate turns calling "shots" at the other player's ships, and the objective of the game is to destroy the +opposing player's fleet. + +Snake is an action video game in which the player maneuvers the end of a growing snake, often represented as a snake. +The objective of the game is to pick up the randomly appearing "apples" that are offered as food. As the snake grows +with each bite, maneuvering becomes increasingly difficult as the playing field becomes more crowded. You lose as soon +as you collide with yourself. \ No newline at end of file From 4d75a8bc8149cf8892465300e679e31f3c612c93 Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 21:58:04 +0100 Subject: [PATCH 16/28] Refratoring background color --- src/main/java/BattleShip/AIGridGUI.java | 2 +- target/classes/BattleShip/AIGridGUI.class | Bin 10192 -> 10203 bytes 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index c012d19..6f5522f 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -343,7 +343,7 @@ public class AIGridGUI extends JPanel { if(s == null) { //If no ship in that cell, mark as a miss. text = "Other player missed. Your turn."; - b.setBackground(Color.BLUE); + b.setBackground(Color.lightGray); } else { //Check if guess killed a ship. killed = s.counter(); diff --git a/target/classes/BattleShip/AIGridGUI.class b/target/classes/BattleShip/AIGridGUI.class index 0daa0ac17b3cf55e9f076a35f945f57470089c4b..a8a030ffb1c8da233f5ee849fe7fbe3c3ee18a24 100644 GIT binary patch delta 33 ocmccMf7^e97b7csN@7v=W^cwH9Go0!nMK7V9+@SZUAekt0o8E}`Tzg` delta 22 dcmccZf5Cr)7b7F{W`D*X988R9n*+GIWdUGp2WkKS From 0d5981c697d2863ffa11c4e74bce4c277e396a18 Mon Sep 17 00:00:00 2001 From: fdai4581 Date: Tue, 7 Feb 2023 22:01:38 +0100 Subject: [PATCH 17/28] refactoring: --- src/main/java/BattleShip/GridGUI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/BattleShip/GridGUI.java b/src/main/java/BattleShip/GridGUI.java index 5a9b32a..f3c5a52 100644 --- a/src/main/java/BattleShip/GridGUI.java +++ b/src/main/java/BattleShip/GridGUI.java @@ -8,7 +8,7 @@ import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.Random; -public class GridGUI { +public class GridGUI extends JPanel { ArrayList buttons = new ArrayList(); ArrayList allShips = new ArrayList(); From 3a4b85e9b39ee0f29f669ac99e77379dd7c5f87b Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 22:04:48 +0100 Subject: [PATCH 18/28] Refratoring background color --- src/main/java/BattleShip/AIGridGUI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 6f5522f..feb217f 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -527,7 +527,7 @@ public class AIGridGUI extends JPanel { //If mouse released, place ship and color ship cells. if(action == 2) { bsb.setCellContents(shipToPlace); - bsb.setBackground(Color.gray); + bsb.setBackground(Color.blue); bsb.setBorder(raisedbevel); } else { //If mouse exited, unhighlight cells. From 94921c2e2fcb77326b6406a3c35d9bff536df995 Mon Sep 17 00:00:00 2001 From: fdai4581 Date: Tue, 7 Feb 2023 22:09:23 +0100 Subject: [PATCH 19/28] update --- src/main/java/BattleShip/GridGUI.java | 3 +++ target/classes/BattleShip/AIGridGUI.class | Bin 10192 -> 10203 bytes 2 files changed, 3 insertions(+) diff --git a/src/main/java/BattleShip/GridGUI.java b/src/main/java/BattleShip/GridGUI.java index f3c5a52..fad5698 100644 --- a/src/main/java/BattleShip/GridGUI.java +++ b/src/main/java/BattleShip/GridGUI.java @@ -130,6 +130,9 @@ public class GridGUI extends JPanel { } } } + public void enableCells() { + + } } diff --git a/target/classes/BattleShip/AIGridGUI.class b/target/classes/BattleShip/AIGridGUI.class index 0daa0ac17b3cf55e9f076a35f945f57470089c4b..6004fa592f963b98e8a4b15d28de5379c37905e7 100644 GIT binary patch delta 74 zcmV-Q0JZxOPNNIGlMGBx10Ryw<8$1CC1)u;D gDzpG%1d~7=6b=Qp0Gz-8Wwrq$JQW8AvrQd?3YxGMZ2$lO delta 63 zcmV-F0Kos-PtZ@WN&x`_vrhr|2m%3Svrr145dj3V@f$n=2?U@35-PL+Vg!>R9TW}) Vwg8;K0A;oTBRmxc2D4Zlg9>Sq5z_zw From 7192b71d35f3278b9e7fe849482c05d0bde01912 Mon Sep 17 00:00:00 2001 From: fdai4581 Date: Tue, 7 Feb 2023 22:10:10 +0100 Subject: [PATCH 20/28] update --- src/main/java/BattleShip/GridGUI.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/BattleShip/GridGUI.java b/src/main/java/BattleShip/GridGUI.java index fad5698..bc07ee9 100644 --- a/src/main/java/BattleShip/GridGUI.java +++ b/src/main/java/BattleShip/GridGUI.java @@ -131,7 +131,9 @@ public class GridGUI extends JPanel { } } public void enableCells() { - + for(BSButton bsb : buttons) { + bsb.setEnabled(true); + } } } From edb74ada3b2623d989955dfb12dbd026ba35d67f Mon Sep 17 00:00:00 2001 From: fdai4581 Date: Tue, 7 Feb 2023 22:10:57 +0100 Subject: [PATCH 21/28] update --- src/main/java/BattleShip/GridGUI.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/BattleShip/GridGUI.java b/src/main/java/BattleShip/GridGUI.java index bc07ee9..5d2d702 100644 --- a/src/main/java/BattleShip/GridGUI.java +++ b/src/main/java/BattleShip/GridGUI.java @@ -135,6 +135,9 @@ public class GridGUI extends JPanel { bsb.setEnabled(true); } } + public String getText() { + return text; + } } From de2e54110e1009ebfe269d430b7d18eb94a86101 Mon Sep 17 00:00:00 2001 From: fdai4581 Date: Tue, 7 Feb 2023 22:18:25 +0100 Subject: [PATCH 22/28] update --- src/main/java/BattleShip/GridGUI.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/BattleShip/GridGUI.java b/src/main/java/BattleShip/GridGUI.java index 5d2d702..8edf0cf 100644 --- a/src/main/java/BattleShip/GridGUI.java +++ b/src/main/java/BattleShip/GridGUI.java @@ -32,7 +32,14 @@ public class GridGUI extends JPanel { rows = r; columns = c; } + public void build() { + allShips.add(destroyer); + allShips.add(cruiser); + allShips.add(submarine); + allShips.add(battleship); + allShips.add(aircraftCarrier); + } public void setShipLocations() { From 02356f36d60b527eeef4cdf794bafc2935efc259 Mon Sep 17 00:00:00 2001 From: fdai4581 Date: Tue, 7 Feb 2023 22:19:39 +0100 Subject: [PATCH 23/28] update --- src/main/java/BattleShip/GridGUI.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/BattleShip/GridGUI.java b/src/main/java/BattleShip/GridGUI.java index 8edf0cf..f825fc6 100644 --- a/src/main/java/BattleShip/GridGUI.java +++ b/src/main/java/BattleShip/GridGUI.java @@ -39,6 +39,25 @@ public class GridGUI extends JPanel { allShips.add(submarine); allShips.add(battleship); allShips.add(aircraftCarrier); + + for(int i = 1; i < (rows * columns); i++) { + BSButton b = new BSButton(); + b.setEnabled(false); + b.setGridLocation(i); + buttons.add(b); + } + + setShipLocations(); + + GridLayout g = new GridLayout(rows,columns); + this.setLayout(g); + + //Add listeners to all cells in grid to listen for guesses. + + for (BSButton bsb : buttons) { + bsb.addActionListener(new MyCellListener()); + this.add(bsb); + } } public void setShipLocations() { From 50d6952457adf206b737b95eefc9dd9086ff0935 Mon Sep 17 00:00:00 2001 From: fdai4581 Date: Tue, 7 Feb 2023 22:20:17 +0100 Subject: [PATCH 24/28] refactoring: --- src/main/java/BattleShip/GridGUI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/BattleShip/GridGUI.java b/src/main/java/BattleShip/GridGUI.java index f825fc6..f4bc7ff 100644 --- a/src/main/java/BattleShip/GridGUI.java +++ b/src/main/java/BattleShip/GridGUI.java @@ -40,7 +40,7 @@ public class GridGUI extends JPanel { allShips.add(battleship); allShips.add(aircraftCarrier); - for(int i = 1; i < (rows * columns); i++) { + for(int i = 0; i < (rows * columns); i++) { BSButton b = new BSButton(); b.setEnabled(false); b.setGridLocation(i); From 1194d1212b9d91ee33bdfe7ed38f7a95a59c251d Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 22:24:12 +0100 Subject: [PATCH 25/28] Refratoring set Border to loweredbevel --- src/main/java/BattleShip/AIGridGUI.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index feb217f..ce216fa 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -522,13 +522,13 @@ public class AIGridGUI extends JPanel { BSButton bsb = buttons.get(cell.getGridLocation() + (i * columns)); //If mouse entered, highlight cells via lowered bevel. if(action == 1) { - bsb.setBorder(raisedbevel); + bsb.setBorder(loweredBevel); } else { //If mouse released, place ship and color ship cells. if(action == 2) { bsb.setCellContents(shipToPlace); bsb.setBackground(Color.blue); - bsb.setBorder(raisedbevel); + bsb.setBorder(loweredBevel); } else { //If mouse exited, unhighlight cells. bsb.setBorder(compound); From fa8af110fbea120fbe41a4a1f1468b47c88df800 Mon Sep 17 00:00:00 2001 From: fdai4581 Date: Tue, 7 Feb 2023 22:26:10 +0100 Subject: [PATCH 26/28] update --- src/main/java/BattleShip/GridGUI.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/BattleShip/GridGUI.java b/src/main/java/BattleShip/GridGUI.java index f4bc7ff..76f4037 100644 --- a/src/main/java/BattleShip/GridGUI.java +++ b/src/main/java/BattleShip/GridGUI.java @@ -97,7 +97,13 @@ public class GridGUI extends JPanel { } } } + for(int i = 0; i < shipLength; i++) { + buttons.get(testLocations[i]).setCellContents(s); + } + + testLocations = null; } + } public boolean getClicked() {return clicked;} public void setClicked() { From 3dc521082cecc2fde345638e9e4b24583dad28df Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 22:45:00 +0100 Subject: [PATCH 27/28] Refratoring (add new Methode) --- src/main/java/BattleShip/AIGridGUI.java | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index ce216fa..9109210 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -26,7 +26,7 @@ public class AIGridGUI extends JPanel { int firstHit; Color darkRed = new Color(100, 0, 0); // Border loweredBevel = BorderFactory.createLoweredBevelBorder(); - Border raisedbevel = BorderFactory.createRaisedBevelBorder(); + //Border raisedbevel = BorderFactory.createRaisedBevelBorder(); Border defaultBorder; //empty = BorderFactory.createEmptyBorder(4, 4, 4, 4); Border compound = BorderFactory.createCompoundBorder(); @@ -535,6 +535,25 @@ public class AIGridGUI extends JPanel { } } } + }else { + + for(int i = 0; i < shipToPlace.getLength(); i++) { + BSButton bsb = buttons.get(cell.getGridLocation() + i); + if(action == 0) { + //If mouse entered, highlight cells via lowered bevel. + bsb.setBorder(loweredBevel); + } else { + //If mouse released, place ship and color ship cells. + if(action == 1) { + bsb.setCellContents(shipToPlace); + bsb.setBackground(Color.blue); + bsb.setBorder(loweredBevel); + } else { + //If mouse exited, unhighlight cells. + bsb.setBorder(defaultBorder); + } + } + } } } } From 80d0f1f890f8352c62d2069b2adac5c25cfcb01a Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 22:56:50 +0100 Subject: [PATCH 28/28] Refratoring change methode action --- src/main/java/BattleShip/AIGridGUI.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 9109210..f19e441 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -502,7 +502,7 @@ public class AIGridGUI extends JPanel { public void highlightCells(BSButton b, int x) { BSButton cell = b; - int action = x; + int actionToTake = x; clear = true; //Check whether sufficient spaces are clear to place the ship. @@ -521,11 +521,11 @@ public class AIGridGUI extends JPanel { 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) { + if(actionToTake == 0) { bsb.setBorder(loweredBevel); } else { //If mouse released, place ship and color ship cells. - if(action == 2) { + if(actionToTake == 1) { bsb.setCellContents(shipToPlace); bsb.setBackground(Color.blue); bsb.setBorder(loweredBevel); @@ -539,12 +539,12 @@ public class AIGridGUI extends JPanel { for(int i = 0; i < shipToPlace.getLength(); i++) { BSButton bsb = buttons.get(cell.getGridLocation() + i); - if(action == 0) { + if(actionToTake == 0) { //If mouse entered, highlight cells via lowered bevel. bsb.setBorder(loweredBevel); } else { //If mouse released, place ship and color ship cells. - if(action == 1) { + if(actionToTake == 1) { bsb.setCellContents(shipToPlace); bsb.setBackground(Color.blue); bsb.setBorder(loweredBevel);