Skip to content

massive folder restructuring, and adding unit testing with junit5 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
}
23 changes: 23 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.zetcode</groupId>
<artifactId>pacman</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>pacman</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.2</version>
</dependency>
</dependencies>
</project>
116 changes: 82 additions & 34 deletions src/com/zetcode/Board.java → src/main/java/com/zetcode/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,21 @@ public class Board extends JPanel implements ActionListener {
private int req_dx, req_dy, view_dx, view_dy;

private final short levelData[] = {
19, 26, 26, 26, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 22,
21, 0, 0, 0, 17, 16, 16, 16, 16, 16, 16, 16, 16, 16, 20,
21, 0, 0, 0, 17, 16, 16, 16, 16, 16, 16, 16, 16, 16, 20,
21, 0, 0, 0, 17, 16, 16, 24, 16, 16, 16, 16, 16, 16, 20,
17, 18, 18, 18, 16, 16, 20, 0, 17, 16, 16, 16, 16, 16, 20,
17, 16, 16, 16, 16, 16, 20, 0, 17, 16, 16, 16, 16, 24, 20,
25, 16, 16, 16, 24, 24, 28, 0, 25, 24, 24, 16, 20, 0, 21,
1, 17, 16, 20, 0, 0, 0, 0, 0, 0, 0, 17, 20, 0, 21,
1, 17, 16, 16, 18, 18, 22, 0, 19, 18, 18, 16, 20, 0, 21,
1, 17, 16, 16, 16, 16, 20, 0, 17, 16, 16, 16, 20, 0, 21,
1, 17, 16, 16, 16, 16, 20, 0, 17, 16, 16, 16, 20, 0, 21,
1, 17, 16, 16, 16, 16, 16, 18, 16, 16, 16, 16, 20, 0, 21,
1, 17, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 20, 0, 21,
1, 25, 24, 24, 24, 24, 24, 24, 24, 24, 16, 16, 16, 18, 20,
9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 25, 24, 24, 24, 28
19, 26, 26, 26, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 22,
21, 0, 0, 0, 17, 16, 16, 16, 16, 16, 16, 16, 16, 16, 20,
21, 0, 0, 0, 17, 16, 16, 16, 16, 16, 16, 16, 16, 16, 20,
21, 0, 0, 0, 17, 16, 16, 24, 16, 16, 16, 16, 16, 16, 20,
17, 18, 18, 18, 16, 16, 20, 0, 17, 16, 16, 16, 16, 16, 20,
17, 16, 16, 16, 16, 16, 20, 0, 17, 16, 16, 16, 16, 24, 20,
25, 16, 16, 16, 24, 24, 28, 0, 25, 24, 24, 16, 20, 0, 21,
1, 17, 16, 20, 0, 0, 0, 0, 0, 0, 0, 17, 20, 0, 21,
1, 17, 16, 16, 18, 18, 22, 0, 19, 18, 18, 16, 20, 0, 21,
1, 17, 16, 16, 16, 16, 20, 0, 17, 16, 16, 16, 20, 0, 21,
1, 17, 16, 16, 16, 16, 20, 0, 17, 16, 16, 16, 20, 0, 21,
1, 17, 16, 16, 16, 16, 16, 18, 16, 16, 16, 16, 20, 0, 21,
1, 17, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 20, 0, 21,
1, 25, 24, 24, 24, 24, 24, 24, 24, 24, 16, 16, 16, 18, 20,
9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 25, 24, 24, 24, 28
};

private final int validSpeeds[] = {1, 2, 3, 4, 6, 8};
Expand All @@ -80,6 +80,54 @@ public class Board extends JPanel implements ActionListener {
private short[] screenData;
private Timer timer;

public short[] getScreenData() {
return screenData;
}

public Color getMazeColor() {
return mazeColor;
}

public Dimension getD() {
return d;
}

public int getPacman_x() {
return pacman_x;
}

public int getPacman_y() {
return pacman_y;
}

public int getPacsLeft() {
return pacsLeft;
}

public int getScore() {
return score;
}

public int getN_GHOSTS() {
return N_GHOSTS;
}

public boolean isInGame() {
return inGame;
}

public void setReq_dx(int req_dx) {
this.req_dx = req_dx;
}

public void setReq_dy(int req_dy) {
this.req_dy = req_dy;
}

public void setPacsLeft(int pacsLeft) {
this.pacsLeft = pacsLeft;
}

public Board() {

loadImages();
Expand All @@ -96,7 +144,7 @@ private void initBoard() {
setBackground(Color.black);
}

private void initVariables() {
protected void initVariables() {

screenData = new short[N_BLOCKS * N_BLOCKS];
mazeColor = new Color(5, 100, 5);
Expand Down Expand Up @@ -180,7 +228,7 @@ private void drawScore(Graphics2D g) {
}
}

private void checkMaze() {
protected void checkMaze() {

short i = 0;
boolean finished = true;
Expand Down Expand Up @@ -210,7 +258,7 @@ private void checkMaze() {
}
}

private void death() {
protected void death() {

pacsLeft--;

Expand Down Expand Up @@ -299,7 +347,7 @@ private void drawGhost(Graphics2D g2d, int x, int y) {
g2d.drawImage(ghost, x, y, this);
}

private void movePacman() {
protected void movePacman() {

int pos;
short ch;
Expand Down Expand Up @@ -478,7 +526,7 @@ private void initGame() {
currentSpeed = 3;
}

private void initLevel() {
protected void initLevel() {

int i;
for (i = 0; i < N_BLOCKS * N_BLOCKS; i++) {
Expand Down Expand Up @@ -523,20 +571,20 @@ private void continueLevel() {

private void loadImages() {

ghost = new ImageIcon("src/resources/images/ghost.png").getImage();
pacman1 = new ImageIcon("src/resources/images/pacman.png").getImage();
pacman2up = new ImageIcon("src/resources/images/up1.png").getImage();
pacman3up = new ImageIcon("src/resources/images/up2.png").getImage();
pacman4up = new ImageIcon("src/resources/images/up3.png").getImage();
pacman2down = new ImageIcon("src/resources/images/down1.png").getImage();
pacman3down = new ImageIcon("src/resources/images/down2.png").getImage();
pacman4down = new ImageIcon("src/resources/images/down3.png").getImage();
pacman2left = new ImageIcon("src/resources/images/left1.png").getImage();
pacman3left = new ImageIcon("src/resources/images/left2.png").getImage();
pacman4left = new ImageIcon("src/resources/images/left3.png").getImage();
pacman2right = new ImageIcon("src/resources/images/right1.png").getImage();
pacman3right = new ImageIcon("src/resources/images/right2.png").getImage();
pacman4right = new ImageIcon("src/resources/images/right3.png").getImage();
ghost = new ImageIcon(getClass().getClassLoader().getResource("images/ghost.png")).getImage();
pacman1 = new ImageIcon(getClass().getClassLoader().getResource("images/pacman.png")).getImage();
pacman2up = new ImageIcon(getClass().getClassLoader().getResource("images/up1.png")).getImage();
pacman3up = new ImageIcon(getClass().getClassLoader().getResource("images/up2.png")).getImage();
pacman4up = new ImageIcon(getClass().getClassLoader().getResource("images/up3.png")).getImage();
pacman2down = new ImageIcon(getClass().getClassLoader().getResource("images/down1.png")).getImage();
pacman3down = new ImageIcon(getClass().getClassLoader().getResource("images/down2.png")).getImage();
pacman4down = new ImageIcon(getClass().getClassLoader().getResource("images/down3.png")).getImage();
pacman2left = new ImageIcon(getClass().getClassLoader().getResource("images/left1.png")).getImage();
pacman3left = new ImageIcon(getClass().getClassLoader().getResource("images/left2.png")).getImage();
pacman4left = new ImageIcon(getClass().getClassLoader().getResource("images/left3.png")).getImage();
pacman2right = new ImageIcon(getClass().getClassLoader().getResource("images/right1.png")).getImage();
pacman3right = new ImageIcon(getClass().getClassLoader().getResource("images/right2.png")).getImage();
pacman4right = new ImageIcon(getClass().getClassLoader().getResource("images/right3.png")).getImage();

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.zetcode;

import java.awt.EventQueue;

import javax.swing.JFrame;

public class Pacman extends JFrame {
Expand All @@ -16,15 +17,15 @@ private void initUI() {

setTitle("Pacman");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(380, 420);
setSize(380, 430);
setLocationRelativeTo(null);
}

public static void main(String[] args) {

EventQueue.invokeLater(() -> {

var ex = new Pacman();
Pacman ex = new Pacman();
ex.setVisible(true);
});
}
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Loading