Browse Source

Merge remote-tracking branch 'origin/main'

# Conflicts:
#	target/classes/BattleShip/AIGridGUI$SetShipsListener.class
#	target/classes/BattleShip/GridGUI.class
main
Thoumi Ngonga Brice 2 years ago
parent
commit
276b3cc67f
  1. 1
      .idea/compiler.xml
  2. 2
      src/main/java/MenuPanel.java
  3. 52
      src/main/java/PingPong/Ball.java
  4. 20
      src/main/java/PingPong/CollisionChecker.java
  5. 60
      src/main/java/PingPong/GamePanel.java
  6. 100
      src/main/java/PingPong/Paddle.java
  7. 23
      src/main/java/PingPong/Score.java
  8. BIN
      target/classes/MenuPanel$AL.class
  9. BIN
      target/classes/MenuPanel$GameFrame.class
  10. BIN
      target/classes/MenuPanel.class
  11. BIN
      target/classes/PingPong/Ball.class
  12. BIN
      target/classes/PingPong/GamePanel.class
  13. BIN
      target/classes/PingPong/Paddle.class
  14. BIN
      target/classes/PingPong/Score.class
  15. BIN
      target/hellsgamers-1.0-SNAPSHOT.jar
  16. 2
      target/maven-archiver/pom.properties
  17. 27
      target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
  18. 40
      target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst

1
.idea/compiler.xml

@ -6,7 +6,6 @@
<sourceOutputDir name="target/generated-sources/annotations" /> <sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" /> <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" /> <outputRelativeToContentRoot value="true" />
<module name="hellsgamers" />
</profile> </profile>
</annotationProcessing> </annotationProcessing>
<bytecodeTargetLevel> <bytecodeTargetLevel>

2
src/main/java/MenuPanel.java

@ -1,5 +1,6 @@
import PingPong.GamePanel; import PingPong.GamePanel;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.KeyAdapter; import java.awt.event.KeyAdapter;
@ -38,6 +39,7 @@ public class MenuPanel extends JPanel {
new GameFrame(); new GameFrame();
} }
} }
} }

52
src/main/java/PingPong/Ball.java

@ -1,4 +1,54 @@
package PingPong; package PingPong;
public class Ball {
import java.awt.*;
import java.util.Random;
public class Ball extends Rectangle {
int xVelocity;
int yVelocity;
int ballSpeed = 3;
Random random;
Ball(int x, int y , int width, int height){
super(x,y,width,height);
random =new Random();
int randomXDirection = random.nextInt(2);
if (randomXDirection == 0)
randomXDirection--;
xDirect(randomXDirection);
int randomYDirection = random.nextInt(2);
yDirect(randomYDirection);
}
private void yDirect(int randomYDirection) {
if (randomYDirection == 0)
randomYDirection--;
setYDirection(randomYDirection * ballSpeed);
}
private void xDirect(int randomXDirection) {
setXDirection(randomXDirection * ballSpeed);
}
public void setXDirection (int randomXDirection){
xVelocity = randomXDirection;
}
public void setYDirection (int randomYDirection){
yVelocity = randomYDirection;
}
public void move(){
x += xVelocity;
y += yVelocity;
}
public void draw(Graphics g){
Color(g);
g.fillOval(x, y, width, height);
}
private static void Color(Graphics g) {
g.setColor(Color.red);
}
} }

20
src/main/java/PingPong/CollisionChecker.java

@ -0,0 +1,20 @@
package PingPong;
import java.awt.*;
public class CollisionChecker {
public Boolean didTouchTopOrBottomEdge(Integer ballYCoordinate, Integer maxHeight) {
return ballYCoordinate <= 0 || ballYCoordinate >= maxHeight;
}
public Boolean didTouchPaddle(Rectangle ball, Rectangle paddle) {
return ball.intersects(paddle);
}
public Boolean didTouchLeftEdge(Integer ballXCoordinate) {
return ballXCoordinate <= 0;
}
public Boolean didTouchRightEdge(Integer ballXCoordinate, Integer maxWidth) {
return ballXCoordinate >= maxWidth;
}
}

60
src/main/java/PingPong/GamePanel.java

@ -2,6 +2,10 @@ package PingPong;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.Random;
public class GamePanel extends JPanel implements Runnable { public class GamePanel extends JPanel implements Runnable {
static final int FRAME_WIDTH = 1000; static final int FRAME_WIDTH = 1000;
@ -12,7 +16,63 @@ public class GamePanel extends JPanel implements Runnable {
public static final Dimension SCREEN = new Dimension(FRAME_WIDTH, FRAME_HEIGHT); public static final Dimension SCREEN = new Dimension(FRAME_WIDTH, FRAME_HEIGHT);
Ball ball;
Paddle paddle_1;
Paddle paddle_2;
Score score;
Image image;
Graphics graphics;
public void run() { public void run() {
}
public void draw(Graphics g) {
score.draw(g);
paddle_1.draw(g);
paddle_2.draw(g);
ball.draw(g);
}
public void move() {
paddle_1.move();
paddle_2.move();
ball.move();
}
public void paint(Graphics g) {
image = createImage(getWidth(), getHeight());
graphics = image.getGraphics();
draw(graphics);
g.drawImage(image, 0, 0, this);
} }
public void newBall() {
ball = new Ball((FRAME_WIDTH/2)-(BALL_DIAMETER/2), ((FRAME_HEIGHT/2)-(BALL_DIAMETER/2)), BALL_DIAMETER, BALL_DIAMETER);
}
public class AL extends KeyAdapter {
public void keyPressed(KeyEvent e) {
paddle_1.pressed(e);
paddle_2.pressed(e);
}
}
public void keyReleased(KeyEvent e) {
paddle_1.released(e);
paddle_2.released(e);
}
} }

100
src/main/java/PingPong/Paddle.java

@ -1,4 +1,102 @@
package PingPong; package PingPong;
public class Paddle {
import java.awt.*;
import java.awt.event.KeyEvent;
public class Paddle extends Rectangle {
int y1;
int y2;
int id;
int x;
int yVelocity1;
int yVelocity2;
int speed = 10;
int width;
int height;
Paddle(int x, int y, int width, int height, int id) {
//super(x, y, width, height);
this.x = x;
if (id == 1) {
y1 = y;
} else if (id == 2) {
y2 = y;
}
this.width = width;
this.height = height;
this.id = id;
}
public void released(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_W) {
setYDirection(0, 1);
} else if (e.getKeyCode() == KeyEvent.VK_S) {
setYDirection(0, 1);
}
if (e.getKeyCode() == KeyEvent.VK_UP) {
setYDirection(0, 2);
} else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
setYDirection(0, 2);
}
move();
}
public void pressed (KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_W) {
setYDirection(-speed, 1);
} else if (e.getKeyCode() == KeyEvent.VK_S) {
setYDirection(speed, 1);
}
if (e.getKeyCode() == KeyEvent.VK_UP) {
setYDirection(-speed, 2);
} else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
setYDirection(speed, 2);
}
move();
}
public void move() {
yVol1();
yVol2();
}
private void yVol2() {
y2 += yVelocity2;
}
private void yVol1() {
y1 += yVelocity1;
}
public void setYDirection(int yDirection, int paddleId) {
if (paddleId == 1) {
yVelocity1 = yDirection;
} else if (paddleId == 2) {
yVelocity2 = yDirection;
}
}
public void draw(Graphics g) {
if (id == 1) {
Paddle2(g);
g.fillRect(x, y1, width, height);
} else {
Paddle1(g);
g.fillRect(x, y2, width, height);
}
}
private static void Paddle2(Graphics g) {
g.setColor(Color.BLUE);
}
private static void Paddle1(Graphics g) {
g.setColor(Color.YELLOW);
}
} }

23
src/main/java/PingPong/Score.java

@ -1,4 +1,25 @@
package PingPong; package PingPong;
public class Score {
import java.awt.*;
public class Score extends Rectangle {
static int FRAME_WIDTH;
static int FRAME_HEIGHT;
public final int COURT_CIRCLE = 150;
public final int CENTER_DOT = 10;
int player_1;
int player_2;
public void draw(Graphics g) {
g.setColor(Color.white);
g.setFont(new Font("Consolas", Font.BOLD,50));
g.drawLine(FRAME_WIDTH/2, 0, FRAME_WIDTH/2, FRAME_HEIGHT);
g.drawOval((FRAME_WIDTH/2)-(COURT_CIRCLE/2), (FRAME_HEIGHT/2) - (COURT_CIRCLE/2), COURT_CIRCLE,COURT_CIRCLE);
g.fillOval((FRAME_WIDTH/2)-(CENTER_DOT/2), (FRAME_HEIGHT/2) - (CENTER_DOT/2), CENTER_DOT,CENTER_DOT);
g.drawString(String.valueOf(player_1/10) + String.valueOf(player_1%10), (FRAME_WIDTH/2)- 75, 50);
g.drawString(String.valueOf(player_2/10) + String.valueOf(player_2%10), (FRAME_WIDTH/2)+ 20, 50);
}
} }

BIN
target/classes/MenuPanel$AL.class

BIN
target/classes/MenuPanel$GameFrame.class

BIN
target/classes/MenuPanel.class

BIN
target/classes/PingPong/Ball.class

BIN
target/classes/PingPong/GamePanel.class

BIN
target/classes/PingPong/Paddle.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
#Mon Feb 06 20:43:15 CET 2023
#Tue Feb 07 11:52:01 CET 2023
groupId=Hellsgamers groupId=Hellsgamers
artifactId=hellsgamers artifactId=hellsgamers
version=1.0-SNAPSHOT version=1.0-SNAPSHOT

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

@ -1,22 +1,35 @@
Snake\TextView.class
MenuPanel.class MenuPanel.class
PingPong\Score.class PingPong\Score.class
PingPong\GamePanel.class
BattleShip\BSButton.class
Snake\Window.class Snake\Window.class
Snake\Snake$1.class
Snake\Controller$1.class
MenuPanel$GameFrame.class MenuPanel$GameFrame.class
BattleShip\Ship.class
PingPong\Ball.class PingPong\Ball.class
Snake\TextView$AnchorType.class Snake\TextView$AnchorType.class
BattleShip\AIGridGUI$SetShipsListener.class
MenuPanel$AL.class MenuPanel$AL.class
Main.class Main.class
Snake\Controller$GameState.class
PingPong\Paddle.class PingPong\Paddle.class
Snake\Apple.class
Snake\Snake.class
Snake\Game.class
PingPong\GameFrame.class PingPong\GameFrame.class
Snake\Controller.class Snake\Controller.class
Snake\Drawable.class
MenuFrame.class
BattleShip\AIGridGUI$DirectionCompare.class
BattleShip\AIGridGUI.class
Snake\Snake$SnakeDirection.class Snake\Snake$SnakeDirection.class
Snake\SnakeView.class Snake\SnakeView.class
Snake\AppleView.class Snake\AppleView.class
Snake\Controller$3.class
Snake\TextView.class
BattleShip\BShip.class
PingPong\GamePanel.class
Snake\Controller$MoveAction.class
Snake\Snake$1.class
Snake\Apple.class
Snake\Snake.class
BattleShip\Direction.class
Snake\Drawable.class
Snake\Controller$2.class
MenuFrame.class
Snake\GameView.class Snake\GameView.class

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

@ -1,17 +1,23 @@
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
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\Snake\AppleView.java
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\BattleShip\Direction.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\Main.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\GameView.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\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
Loading…
Cancel
Save