This is a pacman game project written in JavaFX for G52SWM CW2, using some design patterns like MVC, Singleton and Factory, etc.
- Screenshots
- Prerequisite
- Compiling & Running
- Source File Structure
- Creating New Levels
- File Storage
- Design Parterns
- About G52SWM CW2
- Credits
- Java 10
Compatible with:
- Java 11
- Maven
(Since JavaFX 11 is dropped from Java 11, you would need Maven installed to get the required sources if you use Java 11.)
You can launch the app either by running that pacman.Main.main()
method inside your IDE, or type mvn clean compile package exec:java
on the command line if you have maven installed.
For example, in IntelliJ, Click Run -> Run 'Main()'.
src
└── main
├── java
| └── pacman
| ├── constant
| ├── controller
| ├── model
| ├── util
| └── Main.java
└── resources
└── pacman
├── css
├── image
├── map
├── music
└── view
A new level can be easily added by creating a new ASCII .txt
file under /src/main/resources/pacman/map
.
Here is an example file example.txt
defining the initial state of a level:
/* This is a comment line. */
@PACMAN_PADDING_RATE 0.1
@PACMAN_STEP_RATE 0.15
@GHOST_PADDING_RATE 0.15
@GHOST_STEP_RATE 0.18
@COOKIE_PADDING_RATE 0.5
#########################
#@....#...........#....o#
#.###.#.#########.#.###.#
#.#O.................O#.#
#.#.###.### ###.###.#.#
#.#.....# X #.....#.#
<...###.# #.###...>
#.#.....# X X X #.....#.#
#.#.###.#########.###.#.#
#.#O.................O#.#
#.###.#.#########.#.###.#
#o....#...........#....o#
#########################
Symbol | Model |
---|---|
# |
An obstacle. |
@ |
The pacman. |
. |
A small cookie for 1 score. |
o |
A medium cookie for 5 score. |
O |
A big cookie for 10 score. |
X |
A ghost. |
< & > |
The portals. |
|
An open space. |
Note that neither of portals should be missing when the other twin is defined.
Key | Value |
---|---|
@PACMAN_PADDING_RATE |
The rate of pacman's padding. Default: 0.1 |
@PACMAN_STEP_RATE |
The rate of pacman's step. Default: 0.1 |
@GHOST_PADDING_RATE |
The rate of ghosts' padding. Default: 0.2 |
@GHOST_STEP_RATE |
The rate of ghosts' step. Default: 0.1 |
@COOKIE_PADDING_RATE |
The rate of cookies' padding. Default: 0.3 |
A padding defines the acceptable area of overlapping when two models touch.
A step defines how fast a movable model can move.
In src/main/java/pacman/constant/FileName.java
, add the filename of the map we created in step 1 to MAPS
:
public static final Set<String> MAPS =
new TreeSet<>(
Arrays.asList(
"pacman/map/#001 So Easy.txt",
"pacman/map/#002 Easy Again?.txt",
"pacman/map/#003 A Traitor.txt",
"pacman/map/#004 Freedom.txt",
"pacman/map/#005 Less is More.txt",
"pacman/map/#006 Up and Down.txt",
"pacman/map/#007 One Way.txt",
"pacman/map/#008 The Maze.txt",
"pacman/map/#009 Accel World.txt",
"pacman/map/#010 Spires.txt",
"pacman/map/example.txt"));
Done! A new level is created.
This project stores scoreboards in user's home directory: ~/.pacman
.
Feel free to delete it when you don't need mess up with this game any more.
- MVC
- Singleton
- Factory
- Builder
Click here to know more about its requirements.
My final submission for the coursework is tagged as 1.0
.
This project is modified from a basic one.
All media assets (images & music) are derived from the internet, and are ensured to be free to use for non-commercial use.
This project adopts MIT license.