Assignment doc:
Code:
Task
In this practicum, you'll have to program a game, using a simple graphicacl library.
The Game
The game situates in a 2-dimensional world, represented by a board, which is divided in
an amount of cells. A cell can be empty or contain a box. Dozo is the actor in this game.
He is controled by the player by using the cursors and can navigate through this 2D world
this way. The goal of the game is to get as many boxes to disappear. Boxes disappear when
they are grouped per 3 or per 4 (depending on the type of box).
The game stops if all boxes are disappeared.
Boxes
Boxes can be moved by Dozo when he pushes them. Dozo can move 1 or more boxes at once in one
direction this way, on condition that all boxes are of the same type and not placed against
a wall. Dozo can, in other words, not move both a red and a blue box at once. When he does
try this, he's meant to remain standing on the spot.
Two boxes are connected if and only if they have one side in common. Two boxes x and y belong
to the same group if x and y are connected or if a box z exists in such a way that x and z
are connected and z and y belong to the same group.
Red boxes have as characteristic that they disappear as soon as at least 3 such boxes are
grouped. Blue boxes disappear as soon as they're grouped with at least 4.
Walls
A wall (black square on the figure) is immovable. You can assume in this practicum that Dozo's
world is closed by walls.
The boxes below are grouped correctly and will thus have to disappear
* *<figure 2>
Figure 3 shows configurations of boxes that aren't complete and thus don't disappear.
* *<figure 3>
Concrete
A description of the world is saved in a file with extension .txt. The file exists out of a
few rows that represent the world. The example below makes this clear.
Dim 12 5 *The first rule defines a board of 12 cells wide and 5 cells high.
..########..
..#.B.#R..#. . Empty cell
..#BB.B.R.@# # wall (immovable)
..#....R..#. B a blue box
...#######.. R a red box
*@ Dozo
You can assume that:
* There's only one Dozo defined.
* The board is closed. Dozo can't walk reach a cell that's at the edge of the board in any
way.
* Except for the first row, all rows in the file are equally long.
To load a world from a file, you may use the class FileInput which you used in the previous
practicum.
Tips
Although the previous is strictly seen enough to get you to work, we're giving some classes
which can appear in your design. A possible implementation could use the following classes.
Note, you're not obliged to follow these directions.
Keep in mind that with the quoting, a fancy graphical userinterface won't be taken into
concideration, but the quality of your design and implementation of it will.
On Toledo, you'll find under "assignments", aside of a digital version of the task of this
practicum, a library with which you can draw graphical components on the screen. This way,
you can, for example, draw Dozo's world with the aid of the classe Bord. A couple of examples
make the use of these classes clear.
DozoWorld
This class enables you to make and control an object which keeps a model of the 2D world in
which Dozo navigates.
Define a constructor that creates and initiates a DozoWorld using the rows that can be read
from the file and give as paramenter the Board on which the world will be drawn.
* public DozoWorld(String[] rows, Board bord)
Next you can offer the next methods (this list isn't complete)
* public Item getCel (int x, int y)
Gives the item that is on that position (x,y). If there's no item on that position,
you can, for example, have the method return the value null.
* public void placeCel (int x, int y, Item item)
Places the item on that position (x,y).
* public void drawWorld()
Draws the complete world, including Dozo, on the board.
Item
An object of the class Item can be attached to each cell. An item can, for example, be a box
or a wall.
Examples of interesting methods here are:
* public boolean moveItem(int direction)
This method tries to move the item in the given direction and returns whether or not
this operation has succeeded.
* public Item give Item(int direction)
Gives the item that borders to the item on which the method has ran.
* public int getX()
Gives the x-coordinate back of the cell on which the item is.
Wall
You can define a Wall as subclass of Item. The method moveItem can be given a new implementation
here.
Dozo
Dozo too can be defined as subclass of Item.
Practical details
Design your solution on an objectorientated manner. Keep in mind as well that your code has
to be read and understood by other people:
* Choose clear variable- and methodnames and keep yourself to the conventions concearning
namegiving: names of variables and methods start with small letters, names of constants are
fully in capitals, ...
* Put structure in your code (indenting of blocks, ...) and add comments where needed.
* Complicated methods can be best tested by using it in a different main of a different class
and see if it has the right result.
Input:
The world to be loaded and cursors, to move Dozo
Processes:
- Loading a world
- Moving Dozo
- Pushing boxes -> Checking if a box is moved against a wall
- Checking for how many boxes to be pushed
- Checking for amount of grouped boxes to make them disappear
Output:
Object properties change and objects on screen change accordingly
Functions:
See Processes