Pac-Man
|
The code, readme and all project files are accesible at project repository.
Implement the classic Pacman game against the computer (you can implement other variants as well).
The game must have the following features:
Where can I use polymorphism? (recommended)
Distribution of players: player, spirit (different types of artificial intelligence) Game mode: classic (ghosts walk according to their strategies), furious (ghosts chase players), invulnerable (ghosts are slower, they can be killed) Game field: ground, wall, point, bonus (change mode), cherry (more points), teleport User interface: console, ncurses, SDL, OpenGL (various variants), ...
More information
https://cs.wikipedia.org/wiki/Pac-Man http://programujte.com/clanek/2011010500-chovani-duchu-ve-hre-pac-man-cast-1/ http://programujte.com/clanek/2011010900-chovani-duchu-ve-hre-pac-man-cast-2/
(designation [1] - [4] refers to individual mandatory points from the assignment)
The behavior of the game and its appearance will be similar to the classic game Pac-Man (as a reference to the game Pac-Man is taken a description of the rules of the game available through the links in the school assignment) [1]. The game will allow at least two game modes. However, the non-basic mode may differ in form from the classic game. The game will be implemented using a graphical interface.
The game will take place on a predetermined map on which the game objects will be located. The map will load from file [2]. It will also be possible to set other properties using a configuration file (it will be possible to modify all parameters from the school assignment) [3]. It will also be possible to set the game mode using this configuration file. The mode of play will determine the behavior of ghosts and thus their difficulty [4]. Both files will have a predefined valid format.
Player (Pac-Man, player-controlled movement) Four different ghosts (behaving according to classic rules, moving) Moving bonus (if the player picks it up, the player scores a score, in the classic game cherry moves)
Small bonus (if the player takes it, adds a score to the player, does not move) Bigger bonus (if the player takes it, allows the player to capture ghosts for a certain time, does not move) Moving bonus ...
Wall (object that cannot be passed through) Gateway (object through which only ghosts can pass) Empty box (normal object free to move moving objects)
Teleporting to the other side of the map will also be possible [1] (in cases where the classic rules of the game allow it).
During the implementation of the game, the main goal is to implement the necessary basic skeleton of the game. Later, other functionalities will be extended to the specified range. For example, some elements may be missing (for example, it could be an extra class for special ghost behavior outside the basic ghosts of Pac-man). Since the game is far from complete, the existing implementation, if any, is in the prototype state. Some parts of the implementation are purely to allow compilation of the completed part of the prototype. Additionally, methods that are in the header files are marked with a TEST comment.
Polymorphism will be used in different ghost behavior. This refers to the class CGhost and its other descendants (CRedGhost, CTurqoiseGhost, CSienaGhost, CPurpleGhost). A simple design of classes using polymorphism was included as an illustration.
Design method declaration: \ virtual SCoordinates move (const CMap & amp; map , const SCoordinates & playerCoords, const CGameInfo & gameInfo) = 0;
The method starts moving the ghost on the map and returns the new position of the ghost after the move. This will allow each ghost to behave exactly according to its characteristics. It's so easy to implement different types of ghosts.
Design method declaration: \ virtual SGameObjectInfo getObjectInfo () const = 0;
The method returns basic game information about the game object (in this case, the ghost). SGameObjectInfo is a structure through which data is passed in the application. For example, such a structure is passed to the CView , which takes care of the GUI.
The main purpose of multiple game modes is to allow for a greater variety of behaviors or ghost types. The polymorphism will be used for ghosts. \ The moving bonus (CMovingBonus) and player (CPlayer) are not included in this polymorphism, despite their similarity, because their methods with the same functionality require fewer arguments. In addition, there is always a maximum of one.
Pacman (player) moves with the arrow keys. When choosing a new direction, this direction is memorized and used as a new direction of movement as soon as possible, so you can schedule a turn forward.
When losing, press enter to start a new game.
How to call the game: \ [program name] [path to configuration file] [path to map file] The folder from which the game is started must contain a valid directory of textured images, otherwise the game will not start.
You always need to load the map from a text file.
Sample map:
-------
| ##. ## |
| # ... # |
| #. # G # |
| # P # X # |
| #. # G # |
| # ... # |
| #### |
-------
Each map must be enclosed in characters (- and |) as shown in the example. The inner field of this "pen" must be filled with characters from the following set of characters:
'' for an empty field (0 to more)
'#' for wall (0 to more)
'X' for a gate through which only ghosts pass (0 to more)
'P' for players (just 1)
'G' for ghost (at least 1!)
'.' for a basic bonus (at least 1!)
'@' for a bonus allowing players to kill ghosts (0 to more)
The minimum map size is 3x3.
If you follow the rules above, there is no problem loading the game. However, loading maps is tolerant and it is possible to create, for example, a file where the maps are counted one after the other and only the first one is used. It is important to have the elements behind you and not to use the enclosure characters outside of the enclosure.
------- Any ascii characters
can be outside the fence
| ##. ## |
| # ... # |
| #. # G # |
| # P # X # | also here
| #. # G # |
even here there may be characters, this is not a map interruption
| # ... # |
| #### |
-------
------- | ##. ## || # ... # || #. # G # | this is how you can create a map
| # P # X # || #. # G # |
| # ... # || #### | -------
The configuration file always needs to be loaded from a text file.
Configuration file format (example)
0 // game mode 0 for normal, 1 for hard, 2 for random 50 // ghost speed percentage, possible values = 50 - 200 15 // default neutral time length, possible values = 1 - 60 15 // default hunt on ghosts time length, possible values = 1 - 60 15 // default hunt on player time length, possible values = 1 - 60 60 // probability of moving bonus spawn, possible values = 0 - 100 (0 makes bigger probability then 100 )
The file can contain any ascii characters, except that the individual parameters must appear at the beginning of the lines, as shown in the example (the parameter lines must follow each other and start at the first line)