Skip to content

Develop #1

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 17 commits into
base: main
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.metadata/
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cSpell.words": [
"Pacman",
"pdlo"
]
}
12 changes: 12 additions & 0 deletions Pacman/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions Pacman/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/
28 changes: 28 additions & 0 deletions Pacman/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Pacman</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1712395080124</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
2 changes: 2 additions & 0 deletions Pacman/.settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
14 changes: 14 additions & 0 deletions Pacman/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=11
27 changes: 27 additions & 0 deletions Pacman/src/fr/eseo/e3e/pdlo/entities/Bonus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package fr.eseo.e3e.pdlo.entities;

import fr.eseo.e3e.pdlo.utils.Direction;

public class Bonus extends Entity {

private boolean collected;
private int value;

public Bonus(int x, int y) {
super(x, y);
this.collected = false;
}

public void collect() {
this.collected = true;

}
public int getValue(){
return this.value;
}

@Override
public void move(Direction direction) {

}
}
36 changes: 36 additions & 0 deletions Pacman/src/fr/eseo/e3e/pdlo/entities/Entity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
*
*/
package fr.eseo.e3e.pdlo.entities;

import fr.eseo.e3e.pdlo.utils.Direction;

/**
*
*/
public abstract class Entity {
protected int x, y;

public Entity(int x, int y) {
this.x = x;
this.y = y;
}

public int getX() {
return x;
}

public void setX(int x) {
this.x = x;
}

public int getY() {
return y;
}

public void setY(int y) {
this.y = y;
}

public abstract void move(Direction direction);
}
30 changes: 30 additions & 0 deletions Pacman/src/fr/eseo/e3e/pdlo/entities/Ghost.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
*
*/
package fr.eseo.e3e.pdlo.entities;

import fr.eseo.e3e.pdlo.utils.Direction;

/**
*
*/
public class Ghost extends Entity {
private boolean isScared;

public Ghost(int x, int y) {
super(x, y);
}


public void moveRamdomly(Direction direction) {

}
public void chasePacman(){}


@Override
public void move(Direction direction) {
throw new UnsupportedOperationException("Unimplemented method 'move'");
}

}
38 changes: 38 additions & 0 deletions Pacman/src/fr/eseo/e3e/pdlo/entities/PacMan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
*
*/
package fr.eseo.e3e.pdlo.entities;

import fr.eseo.e3e.pdlo.utils.Coordonnees;
import fr.eseo.e3e.pdlo.utils.Direction;

/**
*
*/
public class PacMan extends Entity {
private int score;
private Coordonnees position;
private boolean dead = false;

public PacMan(int x, int y) {
super(x, y);
this.score = 0;
}

@Override
public void move(Direction direction) {

}

public void eatBonus(Bonus bonus) {
this.score+=bonus.getValue();

}
public void die() {
this.dead = true;
}

public boolean isDead() {
return dead;
}
}
86 changes: 86 additions & 0 deletions Pacman/src/fr/eseo/e3e/pdlo/gui/GamePanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package fr.eseo.e3e.pdlo.gui;

import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.BasicStroke;

import fr.eseo.e3e.pdlo.levels.Maze;

public class GamePanel extends JPanel {
private final Maze maze;


private final Color mazeColor = new Color(5, 100, 5);
private final Color dotColor = Color.YELLOW;

public GamePanel() {

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

};
maze = new Maze(levelData);
setPreferredSize(new Dimension(300, 300));
}

@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
drawMaze((Graphics2D) g);
}

private void drawMaze(Graphics2D g2d) {
short[] screenData = maze.getScreenData();
int blockSize = maze.getBlockSize();
int nBlocks = maze.getNBlocks();
int screenSize = nBlocks * blockSize;

int i = 0;
for (int y = 0; y < screenSize; y += blockSize) {
for (int x = 0; x < screenSize; x += blockSize) {
g2d.setColor(mazeColor);
g2d.setStroke(new BasicStroke(2));

if ((screenData[i] & 1) != 0) {
g2d.drawLine(x, y, x, y + blockSize - 1);
}

if ((screenData[i] & 2) != 0) {
g2d.drawLine(x, y, x + blockSize - 1, y);
}

if ((screenData[i] & 4) != 0) {
g2d.drawLine(x + blockSize - 1, y, x + blockSize - 1, y + blockSize - 1);
}

if ((screenData[i] & 8) != 0) {
g2d.drawLine(x, y + blockSize - 1, x + blockSize - 1, y + blockSize - 1);
}

if ((screenData[i] & 16) != 0) {
g2d.setColor(dotColor);
g2d.fillRect(x + 11, y + 11, 2, 2);
}

i++;
}
}
}
}
24 changes: 24 additions & 0 deletions Pacman/src/fr/eseo/e3e/pdlo/gui/GameWindow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fr.eseo.e3e.pdlo.gui;

import javax.swing.JFrame;
import javax.swing.WindowConstants;

public class GameWindow extends JFrame {
private GamePanel gamePanel;

public GameWindow() {
setTitle("PacMan Game");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setResizable(false);

gamePanel = new GamePanel();
add(gamePanel);
pack();
setLocationRelativeTo(null);
setVisible(true);
}

public static void main(String[] args) {
new GameWindow();
}
}
59 changes: 59 additions & 0 deletions Pacman/src/fr/eseo/e3e/pdlo/levels/Cell.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
*
*/
package fr.eseo.e3e.pdlo.levels;

import fr.eseo.e3e.pdlo.utils.CellType;

/**
*
*/
public class Cell {
private boolean isWall;
private boolean hasBonus;
private boolean hasGhost;
private CellType type;


public Cell(boolean isWall) {
this.isWall = isWall;
this.hasBonus = false;
this.hasGhost = false;
}
public boolean isWalkable() {
return this.type == CellType.PATH || this.type == CellType.BONUS || this.type == CellType.SUPER_BONUS;
}


public boolean isWall() {
return isWall;
}

public void setWall(boolean isWall) {
this.isWall = isWall;
}
public CellType getType() {
return type;
}

public void setType(CellType type) {
this.type = type;
}

public boolean hasBonus() {
return hasBonus;
}

public void setBonus(boolean hasBonus) {
this.hasBonus = hasBonus;
}

public boolean hasGhost() {
return hasGhost;
}

public void setGhost(boolean hasGhost) {
this.hasGhost = hasGhost;
}

}
Loading