diff --git a/.idea/hellsgamers.iml b/.idea/hellsgamers.iml index 72c76be..74774b6 100644 --- a/.idea/hellsgamers.iml +++ b/.idea/hellsgamers.iml @@ -14,13 +14,13 @@ - - + + - + - - - + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_5_9_2.xml b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_5_8_1.xml similarity index 58% rename from .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_5_9_2.xml rename to .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_5_8_1.xml index 1b189a7..987e7d4 100644 --- a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_5_9_2.xml +++ b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_5_8_1.xml @@ -1,13 +1,13 @@ - + - + - + - + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_9_2.xml b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_8_1.xml similarity index 55% rename from .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_9_2.xml rename to .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_8_1.xml index e5cf963..4910ca9 100644 --- a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_9_2.xml +++ b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_8_1.xml @@ -1,13 +1,13 @@ - + - + - + - + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_9_2.xml b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_8_1.xml similarity index 65% rename from .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_9_2.xml rename to .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_8_1.xml index b181218..85ab9ad 100644 --- a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_9_2.xml +++ b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_8_1.xml @@ -1,13 +1,13 @@ - + - + - + - + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_params_5_9_2.xml b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_params_5_8_1.xml similarity index 65% rename from .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_params_5_9_2.xml rename to .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_params_5_8_1.xml index 3ee66e9..8675273 100644 --- a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_params_5_9_2.xml +++ b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_params_5_8_1.xml @@ -1,13 +1,13 @@ - + - + - + - + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_9_2.xml b/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_8_1.xml similarity index 65% rename from .idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_9_2.xml rename to .idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_8_1.xml index 38b9aa2..3417208 100644 --- a/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_9_2.xml +++ b/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_8_1.xml @@ -1,13 +1,13 @@ - + - + - + - + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_9_2.xml b/.idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_8_1.xml similarity index 65% rename from .idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_9_2.xml rename to .idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_8_1.xml index ecbd84e..f19b408 100644 --- a/.idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_9_2.xml +++ b/.idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_8_1.xml @@ -1,13 +1,13 @@ - + - + - + - + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 0acf85b..45a3e86 100644 --- a/pom.xml +++ b/pom.xml @@ -12,6 +12,20 @@ 17 + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M5 + + false + + + + + + junit @@ -22,7 +36,7 @@ org.junit.jupiter junit-jupiter - RELEASE + 5.8.1 test diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index f9d96dc..e12948f 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -1,11 +1,9 @@ package BattleShip; import javax.swing.*; -import javax.swing.border.Border; +import javax.swing.border.*; import java.awt.*; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.util.ArrayList; +import java.awt.event.*; import java.util.*; //refractoring test diff --git a/src/main/java/BattleShip/BShip.java b/src/main/java/BattleShip/BShip.java index 032d572..89cd601 100644 --- a/src/main/java/BattleShip/BShip.java +++ b/src/main/java/BattleShip/BShip.java @@ -150,6 +150,7 @@ public class BShip { } } else { textArea.setText(grid2.getText()); + } if(grid1.getClicked()) { textArea.setText(grid1.getText()); @@ -169,7 +170,7 @@ public class BShip { grid1.setClicked(); } - } + } } } @@ -182,8 +183,7 @@ public class BShip { synchronized (lock) { try { lock.wait(); - } catch (InterruptedException e) { - } + } catch (InterruptedException e) {} } } grid1.enableCells(); diff --git a/src/main/java/MenuPanel.java b/src/main/java/MenuPanel.java index c685056..95560f9 100644 --- a/src/main/java/MenuPanel.java +++ b/src/main/java/MenuPanel.java @@ -1,11 +1,12 @@ -import PingPong.GamePanel; +import BattleShip.BShip; +import PingPong.*; import javax.swing.*; import java.awt.*; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; + public class MenuPanel extends JPanel { @@ -21,28 +22,34 @@ public class MenuPanel extends JPanel { super.paintComponent(g); draw(g); } - public void draw(Graphics g) { - g.setColor(Color.WHITE); - g.setFont(new Font("Consolas", Font.BOLD, 70)); - g.drawString("GAME MENU", 330, 100); - g.setFont(new Font("Consolas", Font.BOLD, 30)); - g.drawString("Press 'ENTER' to start the game", 265, 200); - g.setFont(new Font("Consolas", Font.PLAIN, 10)); - g.drawString("Created by Hells Gamers", 450, 450); + public void draw(Graphics g) { + g.setColor(Color.WHITE); + g.setFont(new Font("Consolas", Font.BOLD, 70)); + g.drawString("GAME MENU", 330, 100); + g.setFont(new Font("Consolas", Font.BOLD, 30)); + g.drawString("Press 1 to start Pong Game", 265, 200); + g.drawString("Press 2 to start BattleShip", 265, 250); + g.drawString("Press 3 to start Snake Game", 265, 300); + + g.setFont(new Font("Consolas", Font.PLAIN, 10)); + g.drawString("Created by HellsGamers", 450, 450); - } + } public class AL extends KeyAdapter { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_1) { - new GameFrame(); - + new PingPong.GameFrame(); } + if (e.getKeyCode() == KeyEvent.VK_2) { + BShip game = new BShip(); + game.startGame(); + } + if (e.getKeyCode() == KeyEvent.VK_3) { + new Snake.Game(); -} - } - - private class GameFrame { + } + } } } \ No newline at end of file diff --git a/src/main/java/PingPong/GameFrame.java b/src/main/java/PingPong/GameFrame.java index 6f87f8e..f7c6dbd 100644 --- a/src/main/java/PingPong/GameFrame.java +++ b/src/main/java/PingPong/GameFrame.java @@ -5,7 +5,7 @@ import java.awt.*; public class GameFrame extends JFrame { GamePanel panel; - GameFrame(){ + public GameFrame(){ panel = new GamePanel(); this.add(panel); this.setTitle("2D Ping-Pong"); diff --git a/src/main/java/PingPong/GamePanel.java b/src/main/java/PingPong/GamePanel.java index d731f9b..13f574c 100644 --- a/src/main/java/PingPong/GamePanel.java +++ b/src/main/java/PingPong/GamePanel.java @@ -4,6 +4,7 @@ import javax.swing.*; import java.awt.*; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; +import java.util.Random; public class GamePanel extends JPanel implements Runnable { @@ -14,7 +15,7 @@ public class GamePanel extends JPanel implements Runnable { static final int PADDLE_HEIGHT = 100; public static final Dimension SCREEN = new Dimension(FRAME_WIDTH, FRAME_HEIGHT); - + Random random; Ball ball; Paddle paddle_1; Paddle paddle_2; @@ -98,10 +99,6 @@ public class GamePanel extends JPanel implements Runnable { } } - - - - public void run() { long lastTime = System.nanoTime(); double amountOfTicks = 60.0; @@ -158,12 +155,12 @@ public class GamePanel extends JPanel implements Runnable { paddle_1.pressed(e); paddle_2.pressed(e); } - } - public void keyReleased(KeyEvent e) { - paddle_1.released(e); - paddle_2.released(e); - } + public void keyReleased(KeyEvent e) { + paddle_1.released(e); + paddle_2.released(e); + } + } diff --git a/src/test_/java/CollisionCheckerTest.java b/src/test_/java/CollisionCheckerTest.java new file mode 100644 index 0000000..767bda1 --- /dev/null +++ b/src/test_/java/CollisionCheckerTest.java @@ -0,0 +1,124 @@ +import PingPong.CollisionChecker; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.awt.*; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + + + class CollisionCheckerTest { + CollisionChecker collisionChecker; + + @BeforeEach + public void before() { + collisionChecker = new CollisionChecker(); + } + @Test + void WhenBallYCoordinateIsLessOrEqualThanZero_didTouchTopOrBottomEdge_ReturnsTrue() { + // arrange + Integer ballYCoordinate = -1; + Integer maxHeight = 123; + + // act + Boolean result = collisionChecker.didTouchTopOrBottomEdge(ballYCoordinate, maxHeight); + + //assert + assertTrue(result); + } + @Test + void WhenBallYCoordinateIsMoreOrEqualToMaxHeight_didTouchTopOrBottomEdge_ReturnsTrue() { + // arrange + Integer ballYCoordinate = 124; + Integer maxHeight = 123; + + // act + Boolean result = collisionChecker.didTouchTopOrBottomEdge(ballYCoordinate, maxHeight); + + //assert + assertTrue(result); + } + @Test + void WhenBallYCoordinateIsMoreThanZeroAndLessThanMaxHeight_didTouchTopOrBottomEdge_ReturnsFalse() { + // arrange + Integer ballYCoordinate = 75; + Integer maxHeight = 123; + + // act + Boolean result = collisionChecker.didTouchTopOrBottomEdge(ballYCoordinate, maxHeight); + + //assert + assertFalse(result); + } + @Test + void WhenBallRectangleIntersectsWithPaddleRectangle_didTouchPaddle_ReturnsTrue() { + // arrange + Rectangle ballRectangle = new Rectangle(1,1,1,1); + Rectangle paddleRectangle = new Rectangle(1,1,5,5); + + //act + Boolean result = collisionChecker.didTouchPaddle(ballRectangle, paddleRectangle); + + //assert + assertTrue(result); + } + @Test + void WhenBallRectangleDoesNotIntersectsWithPaddleRectangle_didTouchPaddle_ReturnsFalse() { + // arrange + Rectangle ballRectangle = new Rectangle(1,1,1,1); + Rectangle paddleRectangle = new Rectangle(15,15,1,1); + + //act + Boolean result = collisionChecker.didTouchPaddle(ballRectangle, paddleRectangle); + + //assert + assertFalse(result); + } + @Test + void WhenBallXCoordinateIsLessOrEqualThanZero_didTouchLeftEdge_ReturnsTrue() { + // arrange + Integer ballXCoordinate = -5; + + //act + Boolean result = collisionChecker.didTouchLeftEdge(ballXCoordinate); + + //assert + assertTrue(result); + } + @Test + void WhenBallXCoordinateIsMoreThanZero_didTouchLeftEdge_ReturnsTrue() { + // arrange + Integer ballXCoordinate = 10; + + //act + Boolean result = collisionChecker.didTouchLeftEdge(ballXCoordinate); + + //assert + assertFalse(result); + } + @Test + void WhenBallXCoordinateIsMoreOrEqualToMaxWidth_didTouchRightEdge_ReturnsTrue() { + // arrange + Integer ballXCoordinate = 124; + Integer maxWidth = 123; + + // act + Boolean result = collisionChecker.didTouchRightEdge(ballXCoordinate, maxWidth); + + //assert + assertTrue(result); + } + @Test + void WhenBallXCoordinateIsLessThanMaxWidth_didTouchRightEdge_ReturnsFalse() { + // arrange + Integer ballXCoordinate = 75; + Integer maxWidth = 123; + + // act + Boolean result = collisionChecker.didTouchRightEdge(ballXCoordinate, maxWidth); + + //assert + assertFalse(result); + } +} diff --git a/target/classes/BattleShip/AIGridGUI$DirectionCompare.class b/target/classes/BattleShip/AIGridGUI$DirectionCompare.class index a226425..411fa71 100644 Binary files a/target/classes/BattleShip/AIGridGUI$DirectionCompare.class and b/target/classes/BattleShip/AIGridGUI$DirectionCompare.class differ diff --git a/target/classes/BattleShip/AIGridGUI$SetShipsListener.class b/target/classes/BattleShip/AIGridGUI$SetShipsListener.class index a43d2b1..9334499 100644 Binary files a/target/classes/BattleShip/AIGridGUI$SetShipsListener.class and b/target/classes/BattleShip/AIGridGUI$SetShipsListener.class differ diff --git a/target/classes/BattleShip/AIGridGUI.class b/target/classes/BattleShip/AIGridGUI.class index 7c2fc5b..f16ca3f 100644 Binary files a/target/classes/BattleShip/AIGridGUI.class and b/target/classes/BattleShip/AIGridGUI.class differ diff --git a/target/classes/BattleShip/BShip$IncomingGuessReader.class b/target/classes/BattleShip/BShip$IncomingGuessReader.class new file mode 100644 index 0000000..79ec450 Binary files /dev/null and b/target/classes/BattleShip/BShip$IncomingGuessReader.class differ diff --git a/target/classes/BattleShip/BShip$ShipsPlacedReader.class b/target/classes/BattleShip/BShip$ShipsPlacedReader.class new file mode 100644 index 0000000..85b7f4d Binary files /dev/null and b/target/classes/BattleShip/BShip$ShipsPlacedReader.class differ diff --git a/target/classes/MenuPanel$AL.class b/target/classes/MenuPanel$AL.class index 7046c06..c4c17e1 100644 Binary files a/target/classes/MenuPanel$AL.class and b/target/classes/MenuPanel$AL.class differ diff --git a/target/classes/MenuPanel$GameFrame.class b/target/classes/MenuPanel$GameFrame.class deleted file mode 100644 index a8279a0..0000000 Binary files a/target/classes/MenuPanel$GameFrame.class and /dev/null differ diff --git a/target/classes/MenuPanel.class b/target/classes/MenuPanel.class index 2fbc45a..c217b1f 100644 Binary files a/target/classes/MenuPanel.class and b/target/classes/MenuPanel.class differ diff --git a/target/classes/PingPong/GameFrame.class b/target/classes/PingPong/GameFrame.class index bf5657e..4de88ca 100644 Binary files a/target/classes/PingPong/GameFrame.class and b/target/classes/PingPong/GameFrame.class differ diff --git a/target/classes/PingPong/GamePanel$AL.class b/target/classes/PingPong/GamePanel$AL.class index 8592c1a..1cb4ecc 100644 Binary files a/target/classes/PingPong/GamePanel$AL.class and b/target/classes/PingPong/GamePanel$AL.class differ diff --git a/target/classes/PingPong/GamePanel.class b/target/classes/PingPong/GamePanel.class index 194c31a..c989c25 100644 Binary files a/target/classes/PingPong/GamePanel.class and b/target/classes/PingPong/GamePanel.class differ diff --git a/target/hellsgamers-1.0-SNAPSHOT.jar b/target/hellsgamers-1.0-SNAPSHOT.jar index ea3a279..0adfec4 100644 Binary files a/target/hellsgamers-1.0-SNAPSHOT.jar and b/target/hellsgamers-1.0-SNAPSHOT.jar differ diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties index e6bd5fe..a3f66d2 100644 --- a/target/maven-archiver/pom.properties +++ b/target/maven-archiver/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven -#Wed Feb 08 20:10:52 CET 2023 +#Wed Feb 08 21:32:53 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 3ecedd5..c11ae49 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 @@ -21,6 +21,8 @@ BattleShip\AIGridGUI$DirectionCompare.class BattleShip\AIGridGUI.class Snake\Snake$SnakeDirection.class Snake\SnakeView.class +BattleShip\BShip$IncomingGuessReader.class +BattleShip\BShip$ShipsPlacedReader.class Snake\AppleView.class Snake\Controller$3.class Snake\TextView.class diff --git a/target/test-classes/BShipTest.class b/target/test-classes/BShipTest.class new file mode 100644 index 0000000..277a7c9 Binary files /dev/null and b/target/test-classes/BShipTest.class differ diff --git a/target/test-classes/CollisionCheckerTest.class b/target/test-classes/CollisionCheckerTest.class new file mode 100644 index 0000000..1b6f82b Binary files /dev/null and b/target/test-classes/CollisionCheckerTest.class differ diff --git a/target/test-classes/ShipTest.class b/target/test-classes/ShipTest.class new file mode 100644 index 0000000..2f24884 Binary files /dev/null and b/target/test-classes/ShipTest.class differ diff --git a/target/test-classes/SnakeTest.class b/target/test-classes/SnakeTest.class new file mode 100644 index 0000000..1c96711 Binary files /dev/null and b/target/test-classes/SnakeTest.class differ