Browse Source

Merge remote-tracking branch 'origin/main'

main
Thoumi Ngonga Brice 2 years ago
parent
commit
81c786fda7
  1. 12
      .idea/hellsgamers.iml
  2. 8
      .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_5_8_1.xml
  3. 8
      .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_8_1.xml
  4. 8
      .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_8_1.xml
  5. 8
      .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_params_5_8_1.xml
  6. 8
      .idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_8_1.xml
  7. 8
      .idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_8_1.xml
  8. 16
      pom.xml
  9. 6
      src/main/java/BattleShip/AIGridGUI.java
  10. 6
      src/main/java/BattleShip/BShip.java
  11. 25
      src/main/java/MenuPanel.java
  12. 2
      src/main/java/PingPong/GameFrame.java
  13. 11
      src/main/java/PingPong/GamePanel.java
  14. 124
      src/test_/java/CollisionCheckerTest.java
  15. BIN
      target/classes/BattleShip/AIGridGUI$DirectionCompare.class
  16. BIN
      target/classes/BattleShip/AIGridGUI$SetShipsListener.class
  17. BIN
      target/classes/BattleShip/AIGridGUI.class
  18. BIN
      target/classes/BattleShip/BShip$IncomingGuessReader.class
  19. BIN
      target/classes/BattleShip/BShip$ShipsPlacedReader.class
  20. BIN
      target/classes/MenuPanel$AL.class
  21. BIN
      target/classes/MenuPanel$GameFrame.class
  22. BIN
      target/classes/MenuPanel.class
  23. BIN
      target/classes/PingPong/GameFrame.class
  24. BIN
      target/classes/PingPong/GamePanel$AL.class
  25. BIN
      target/classes/PingPong/GamePanel.class
  26. BIN
      target/hellsgamers-1.0-SNAPSHOT.jar
  27. 2
      target/maven-archiver/pom.properties
  28. 2
      target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
  29. BIN
      target/test-classes/BShipTest.class
  30. BIN
      target/test-classes/CollisionCheckerTest.class
  31. BIN
      target/test-classes/ShipTest.class
  32. BIN
      target/test-classes/SnakeTest.class

12
.idea/hellsgamers.iml

@ -14,13 +14,13 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.13.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter:5.9.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.9.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter:5.8.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.8.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.9.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.8.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.1.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-params:5.9.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.9.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.9.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-params:5.8.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.8.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.8.1" level="project" />
</component>
</module>

8
.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_5_9_2.xml → .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_5_8_1.xml

@ -1,13 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.junit.jupiter:junit-jupiter:5.9.2">
<library name="Maven: org.junit.jupiter:junit-jupiter:5.8.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.9.2/junit-jupiter-5.9.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.8.1/junit-jupiter-5.8.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.9.2/junit-jupiter-5.9.2-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.8.1/junit-jupiter-5.8.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.9.2/junit-jupiter-5.9.2-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.8.1/junit-jupiter-5.8.1-sources.jar!/" />
</SOURCES>
</library>
</component>

8
.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_9_2.xml → .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_8_1.xml

@ -1,13 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.junit.jupiter:junit-jupiter-api:5.9.2">
<library name="Maven: org.junit.jupiter:junit-jupiter-api:5.8.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.9.2/junit-jupiter-api-5.9.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.8.1/junit-jupiter-api-5.8.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.9.2/junit-jupiter-api-5.9.2-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.8.1/junit-jupiter-api-5.8.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.9.2/junit-jupiter-api-5.9.2-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.8.1/junit-jupiter-api-5.8.1-sources.jar!/" />
</SOURCES>
</library>
</component>

8
.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_9_2.xml → .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_8_1.xml

@ -1,13 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.junit.jupiter:junit-jupiter-engine:5.9.2">
<library name="Maven: org.junit.jupiter:junit-jupiter-engine:5.8.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.9.2/junit-jupiter-engine-5.9.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.8.1/junit-jupiter-engine-5.8.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.9.2/junit-jupiter-engine-5.9.2-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.8.1/junit-jupiter-engine-5.8.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.9.2/junit-jupiter-engine-5.9.2-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.8.1/junit-jupiter-engine-5.8.1-sources.jar!/" />
</SOURCES>
</library>
</component>

8
.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_params_5_9_2.xml → .idea/libraries/Maven__org_junit_jupiter_junit_jupiter_params_5_8_1.xml

@ -1,13 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.junit.jupiter:junit-jupiter-params:5.9.2">
<library name="Maven: org.junit.jupiter:junit-jupiter-params:5.8.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.9.2/junit-jupiter-params-5.9.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.8.1/junit-jupiter-params-5.8.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.9.2/junit-jupiter-params-5.9.2-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.8.1/junit-jupiter-params-5.8.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.9.2/junit-jupiter-params-5.9.2-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.8.1/junit-jupiter-params-5.8.1-sources.jar!/" />
</SOURCES>
</library>
</component>

8
.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_9_2.xml → .idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_8_1.xml

@ -1,13 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.junit.platform:junit-platform-commons:1.9.2">
<library name="Maven: org.junit.platform:junit-platform-commons:1.8.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.9.2/junit-platform-commons-1.9.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.8.1/junit-platform-commons-1.8.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.9.2/junit-platform-commons-1.9.2-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.8.1/junit-platform-commons-1.8.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.9.2/junit-platform-commons-1.9.2-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.8.1/junit-platform-commons-1.8.1-sources.jar!/" />
</SOURCES>
</library>
</component>

8
.idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_9_2.xml → .idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_8_1.xml

@ -1,13 +1,13 @@
<component name="libraryTable">
<library name="Maven: org.junit.platform:junit-platform-engine:1.9.2">
<library name="Maven: org.junit.platform:junit-platform-engine:1.8.1">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.9.2/junit-platform-engine-1.9.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.8.1/junit-platform-engine-1.8.1.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.9.2/junit-platform-engine-1.9.2-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.8.1/junit-platform-engine-1.8.1-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.9.2/junit-platform-engine-1.9.2-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.8.1/junit-platform-engine-1.8.1-sources.jar!/" />
</SOURCES>
</library>
</component>

16
pom.xml

@ -12,6 +12,20 @@
<maven.compiler.target>17</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<skipTests>false</skipTests>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
@ -22,7 +36,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<version>5.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>

6
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

6
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();

25
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 {
@ -26,9 +27,12 @@ public class MenuPanel extends JPanel {
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.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 Hells Gamers", 450, 450);
g.drawString("Created by HellsGamers", 450, 450);
}
@ -36,13 +40,16 @@ public class MenuPanel extends JPanel {
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 {
}
}
}
}

2
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");

11
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);
}
}

124
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);
}
}

BIN
target/classes/BattleShip/AIGridGUI$DirectionCompare.class

BIN
target/classes/BattleShip/AIGridGUI$SetShipsListener.class

BIN
target/classes/BattleShip/AIGridGUI.class

BIN
target/classes/BattleShip/BShip$IncomingGuessReader.class

BIN
target/classes/BattleShip/BShip$ShipsPlacedReader.class

BIN
target/classes/MenuPanel$AL.class

BIN
target/classes/MenuPanel$GameFrame.class

BIN
target/classes/MenuPanel.class

BIN
target/classes/PingPong/GameFrame.class

BIN
target/classes/PingPong/GamePanel$AL.class

BIN
target/classes/PingPong/GamePanel.class

BIN
target/hellsgamers-1.0-SNAPSHOT.jar

2
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

2
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

BIN
target/test-classes/BShipTest.class

BIN
target/test-classes/CollisionCheckerTest.class

BIN
target/test-classes/ShipTest.class

BIN
target/test-classes/SnakeTest.class

Loading…
Cancel
Save