Browse Source
Merge remote-tracking branch 'origin/main'
Merge remote-tracking branch 'origin/main'
# Conflicts: # target/classes/BattleShip/AIGridGUI$SetShipsListener.class # target/classes/BattleShip/GridGUI.classmain
Thoumi Ngonga Brice
2 years ago
18 changed files with 298 additions and 29 deletions
-
1.idea/compiler.xml
-
2src/main/java/MenuPanel.java
-
52src/main/java/PingPong/Ball.java
-
20src/main/java/PingPong/CollisionChecker.java
-
60src/main/java/PingPong/GamePanel.java
-
100src/main/java/PingPong/Paddle.java
-
23src/main/java/PingPong/Score.java
-
BINtarget/classes/MenuPanel$AL.class
-
BINtarget/classes/MenuPanel$GameFrame.class
-
BINtarget/classes/MenuPanel.class
-
BINtarget/classes/PingPong/Ball.class
-
BINtarget/classes/PingPong/GamePanel.class
-
BINtarget/classes/PingPong/Paddle.class
-
BINtarget/classes/PingPong/Score.class
-
BINtarget/hellsgamers-1.0-SNAPSHOT.jar
-
2target/maven-archiver/pom.properties
-
27target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
-
40target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
@ -1,4 +1,54 @@ |
|||
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); |
|||
} |
|||
} |
@ -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; |
|||
} |
|||
|
|||
} |
@ -1,4 +1,102 @@ |
|||
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); |
|||
} |
|||
} |
@ -1,4 +1,25 @@ |
|||
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); |
|||
|
|||
} |
|||
} |
@ -1,5 +1,5 @@ |
|||
#Generated by Maven |
|||
#Mon Feb 06 20:43:15 CET 2023 |
|||
#Tue Feb 07 11:52:01 CET 2023 |
|||
groupId=Hellsgamers |
|||
artifactId=hellsgamers |
|||
version=1.0-SNAPSHOT |
@ -1,22 +1,35 @@ |
|||
Snake\TextView.class |
|||
MenuPanel.class |
|||
PingPong\Score.class |
|||
PingPong\GamePanel.class |
|||
BattleShip\BSButton.class |
|||
Snake\Window.class |
|||
Snake\Snake$1.class |
|||
Snake\Controller$1.class |
|||
MenuPanel$GameFrame.class |
|||
BattleShip\Ship.class |
|||
PingPong\Ball.class |
|||
Snake\TextView$AnchorType.class |
|||
BattleShip\AIGridGUI$SetShipsListener.class |
|||
MenuPanel$AL.class |
|||
Main.class |
|||
Snake\Controller$GameState.class |
|||
PingPong\Paddle.class |
|||
Snake\Apple.class |
|||
Snake\Snake.class |
|||
Snake\Game.class |
|||
PingPong\GameFrame.class |
|||
Snake\Controller.class |
|||
Snake\Drawable.class |
|||
MenuFrame.class |
|||
BattleShip\AIGridGUI$DirectionCompare.class |
|||
BattleShip\AIGridGUI.class |
|||
Snake\Snake$SnakeDirection.class |
|||
Snake\SnakeView.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 |
@ -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 |
Write
Preview
Loading…
Cancel
Save
Reference in new issue