Browse Source

Merge remote-tracking branch 'origin/main'

main
fdai4581 2 years ago
parent
commit
0991bfabb1
  1. 5
      .idea/hellsgamers.iml
  2. 100
      src/main/java/PingPong/GamePanel.java
  3. 5
      src/main/java/PingPong/Score.java
  4. 0
      src/test_/java/AIGridGUITest.java
  5. 0
      src/test_/java/SnakeTest.java
  6. BIN
      target/classes/PingPong/GamePanel$AL.class
  7. BIN
      target/classes/PingPong/GamePanel.class
  8. BIN
      target/classes/PingPong/Score.class
  9. BIN
      target/hellsgamers-1.0-SNAPSHOT.jar
  10. 2
      target/maven-archiver/pom.properties
  11. 5
      target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
  12. 20
      target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst

5
.idea/hellsgamers.iml

@ -6,9 +6,8 @@
<content url="file://$MODULE_DIR$"> <content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/test_" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/test_/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test_/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test_/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" /> <excludeFolder url="file://$MODULE_DIR$/target" />
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />

100
src/main/java/PingPong/GamePanel.java

@ -4,7 +4,6 @@ import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.KeyAdapter; import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.util.Random;
public class GamePanel extends JPanel implements Runnable { public class GamePanel extends JPanel implements Runnable {
@ -22,16 +21,105 @@ public class GamePanel extends JPanel implements Runnable {
Score score; Score score;
Image image; Image image;
Graphics graphics; Graphics graphics;
CollisionChecker collisionChecker;
Thread gameThread;
public GamePanel() {
newPaddle();
newBall();
score = new Score(FRAME_WIDTH, FRAME_HEIGHT);
collisionChecker = new CollisionChecker();
this.setFocusable(true);
this.addKeyListener(new AL());
this.setPreferredSize(SCREEN);
gameThread = new Thread(this);
gameThread.start();
}
public void checkCollision() {
//Reflection of Ball when it touches top and bottom edges!
if(collisionChecker.didTouchTopOrBottomEdge(ball.y, FRAME_HEIGHT-BALL_DIAMETER)) {
ball.setYDirection(-ball.yVelocity);
}
if(collisionChecker.didTouchPaddle(ball, new Rectangle(paddle_1.x, paddle_1.y1, paddle_1.width, paddle_1.height))) {
ball.xVelocity = Math.abs(ball.xVelocity);
ball.xVelocity++;
if (ball.yVelocity > 0)
ball.yVelocity++;
else
ball.yVelocity--;
ball.setXDirection(ball.xVelocity);
ball.setYDirection(ball.yVelocity);
}
if(collisionChecker.didTouchPaddle(ball, new Rectangle(paddle_2.x, paddle_2.y2, paddle_2.width, paddle_2.height))) {
ball.xVelocity = Math.abs(ball.xVelocity);
ball.xVelocity++;
if (ball.yVelocity > 0)
ball.yVelocity++;
else
ball.yVelocity--;
ball.setXDirection(-ball.xVelocity);
ball.setYDirection(ball.yVelocity);
}
if (paddle_1.y1 <= 0)
paddle_1.y1 = 0;
if (paddle_1.y1 >= (FRAME_HEIGHT-PADDLE_HEIGHT))
paddle_1.y1 = FRAME_HEIGHT-PADDLE_HEIGHT;
if (paddle_2.y2 <= 0)
paddle_2.y2 = 0;
if (paddle_2.y2 >= (FRAME_HEIGHT-PADDLE_HEIGHT))
paddle_2.y2 = FRAME_HEIGHT-PADDLE_HEIGHT;
if(collisionChecker.didTouchLeftEdge(ball.x)) {
score.player_2++;
newPaddle();
newBall();
}
if(collisionChecker.didTouchRightEdge(ball.x, FRAME_WIDTH-BALL_DIAMETER)) {
score.player_1++;
newPaddle();
newBall();
}
if(score.player_1 == 20){
score.player_1 = 0;
score.player_2 = 0;
newPaddle();
newBall();
}
if(score.player_2 == 20) {
score.player_1 = 0;
score.player_2 = 0;
newPaddle();
newBall();
}
}
public void run() {
public void run() {
long lastTime = System.nanoTime();
double amountOfTicks = 60.0;
double nanoseconds = 1000000000 / amountOfTicks;
double delta = 0;
while (true) {
long now = System.nanoTime();
delta += (now - lastTime) / nanoseconds;
lastTime = now;
if (delta >= 1) {
move();
checkCollision();
repaint();
delta--;
}
}
} }
public void draw(Graphics g) { public void draw(Graphics g) {
@ -41,8 +129,9 @@ public class GamePanel extends JPanel implements Runnable {
ball.draw(g); ball.draw(g);
} }
public void move() { public void move() {
paddle_1.move(); paddle_1.move();
paddle_2.move(); paddle_2.move();
ball.move(); ball.move();
@ -59,7 +148,10 @@ public class GamePanel extends JPanel implements Runnable {
ball = new Ball((FRAME_WIDTH/2)-(BALL_DIAMETER/2), ((FRAME_HEIGHT/2)-(BALL_DIAMETER/2)), BALL_DIAMETER, BALL_DIAMETER); ball = new Ball((FRAME_WIDTH/2)-(BALL_DIAMETER/2), ((FRAME_HEIGHT/2)-(BALL_DIAMETER/2)), BALL_DIAMETER, BALL_DIAMETER);
} }
public void newPaddle() {
paddle_1 = new Paddle(0, (FRAME_HEIGHT/2)-(PADDLE_HEIGHT/2), PADDLE_WIDTH, PADDLE_HEIGHT, 1 );
paddle_2 = new Paddle(FRAME_WIDTH-PADDLE_WIDTH, (FRAME_HEIGHT/2)-(PADDLE_HEIGHT/2), PADDLE_WIDTH, PADDLE_HEIGHT, 2 );
}
public class AL extends KeyAdapter { public class AL extends KeyAdapter {
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {

5
src/main/java/PingPong/Score.java

@ -10,7 +10,10 @@ public class Score extends Rectangle {
int player_1; int player_1;
int player_2; int player_2;
Score(int FRAME_WIDTH, int FRAME_HEIGHT){
Score.FRAME_WIDTH = FRAME_WIDTH;
Score.FRAME_HEIGHT = FRAME_HEIGHT;
}
public void draw(Graphics g) { public void draw(Graphics g) {
g.setColor(Color.white); g.setColor(Color.white);

0
src/test/java/AIGridGUITest.java → src/test_/java/AIGridGUITest.java

0
src/test/java/SnakeTest.java → src/test_/java/SnakeTest.java

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

BIN
target/classes/PingPong/GamePanel.class

BIN
target/classes/PingPong/Score.class

BIN
target/hellsgamers-1.0-SNAPSHOT.jar

2
target/maven-archiver/pom.properties

@ -1,5 +1,5 @@
#Generated by Maven #Generated by Maven
#Tue Feb 07 11:52:01 CET 2023
#Wed Feb 08 20:10:52 CET 2023
groupId=Hellsgamers groupId=Hellsgamers
artifactId=hellsgamers artifactId=hellsgamers
version=1.0-SNAPSHOT version=1.0-SNAPSHOT

5
target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst

@ -2,10 +2,12 @@ MenuPanel.class
PingPong\Score.class PingPong\Score.class
BattleShip\BSButton.class BattleShip\BSButton.class
Snake\Window.class Snake\Window.class
PingPong\GamePanel$AL.class
Snake\Controller$1.class Snake\Controller$1.class
MenuPanel$GameFrame.class MenuPanel$GameFrame.class
BattleShip\Ship.class BattleShip\Ship.class
PingPong\Ball.class PingPong\Ball.class
BattleShip\BShip$NewGameListener.class
Snake\TextView$AnchorType.class Snake\TextView$AnchorType.class
BattleShip\AIGridGUI$SetShipsListener.class BattleShip\AIGridGUI$SetShipsListener.class
MenuPanel$AL.class MenuPanel$AL.class
@ -22,8 +24,10 @@ Snake\SnakeView.class
Snake\AppleView.class Snake\AppleView.class
Snake\Controller$3.class Snake\Controller$3.class
Snake\TextView.class Snake\TextView.class
BattleShip\GridGUI$MyCellListener.class
BattleShip\BShip.class BattleShip\BShip.class
PingPong\GamePanel.class PingPong\GamePanel.class
PingPong\CollisionChecker.class
Snake\Controller$MoveAction.class Snake\Controller$MoveAction.class
Snake\Snake$1.class Snake\Snake$1.class
Snake\Apple.class Snake\Apple.class
@ -33,3 +37,4 @@ Snake\Drawable.class
Snake\Controller$2.class Snake\Controller$2.class
MenuFrame.class MenuFrame.class
Snake\GameView.class Snake\GameView.class
BattleShip\GridGUI.class

20
target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst

@ -1,3 +1,12 @@
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\BattleShip\BShip.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\Main.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\BattleShip\BSButton.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\Snake\SnakeView.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\Snake\Apple.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\Snake\Game.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\BattleShip\Ship.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\PingPong\GameFrame.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\Snake\Window.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\MenuPanel.java C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\MenuPanel.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\BattleShip\AIGridGUI.java C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\BattleShip\AIGridGUI.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\Snake\AppleView.java C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\Snake\AppleView.java
@ -5,19 +14,12 @@ C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\PingPong\Paddle.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\MenuFrame.java C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\MenuFrame.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\BattleShip\Direction.java C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\BattleShip\Direction.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\Snake\Controller.java C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\Snake\Controller.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\BattleShip\BShip.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\PingPong\GamePanel.java C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\PingPong\GamePanel.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\Main.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\PingPong\Score.java C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\PingPong\Score.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\Snake\Snake.java C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\Snake\Snake.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\Snake\GameView.java C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\Snake\GameView.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\PingPong\CollisionChecker.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\Snake\Drawable.java C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\Snake\Drawable.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\BattleShip\BSButton.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\Snake\SnakeView.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\Snake\Apple.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\Snake\Game.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\BattleShip\GridGUI.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\Snake\TextView.java C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\Snake\TextView.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\BattleShip\Ship.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\PingPong\GameFrame.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\Snake\Window.java
C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\PingPong\Ball.java C:\Users\Laura\IdeaProjects\hellsgamers\src\main\java\PingPong\Ball.java
Loading…
Cancel
Save