This module implement a class (Board.Board) for Bomberman board, which is basically a matrix of states, represented with the class Board.State.
- empty – an empty spot, with NOTHING on it.
- dmur – a destructible wall, with JUST the wall on it.
- umur – an undestructible wall, with JUST the wall on it.
- expl – an empty spot, with JUST an explosion tag on it.
Warning
- Use those constants state only with copy.copy(..).
- overwise it will work with references over those constants.
>>> for i, j, spot in board: >>> spot=Board.emptyAll spots of [board] are now the same, so all modification like
>>> board[i,j].explosion=True
- will be done on ALL spot of [board].
- And that’s not what we want to.
Try to know if the encoding is UTF-8 supported.
A Class for the element of the board.
This class can be used both by the client and the server. But, for the server each players in the attribute players are instances of Player.PlayerServer; and for the client, the client’s player is a Player.Player instance, and all other players are Player.Player.
Simple constructor of state, assigned with default value (an undestructible piece of wall). Each parameters can be directly assigned.
For example, myState=State(wall=False, players=[myself]) return a State initializing as containing the player [myself].
True if the case is a wall, false if it is empty (ie : can be occupyed by a player, or/and a bomb, or/and a bonus).
True or False, if the case can be destroy (CONVENTION: a piece of wall is destroid in one explosion).
A Bomb.Bomb instance (no need for more than 1).
List of Player.noPlayer if there is a player, a Player.Player instance if there is one.
A boolean for a visual effect of an explosion !
None if there is no bonus, or a Bonus.Bonus instance if there is one (only one bonus in a state).
Simple transformation of a state to a universal (no UTF, only ASCII) string of 3 caraters.
Simple transformation of a state to a non ASCII (i.e. with UTF caracters) string of 3 caraters. For a wall, 3 grey blocks if it can be brocken, or 3 black blocks. For an explosion, a little sun is used.
If those caracters do not seems pretty, try to change the encoding used here to UTF-8.
Generic conversion to a string, choose an UTF8 representation if it is available.
Destroy the element in case [self] with [ingury] damages.
If it’s a destructible wall, break it, return SIGNAL_WALL_BREAKE=2.
If it’s a undestructible wall, break it, return SIGNAL_WALL_NOT_BREAKE=4.
If it’s a bomb, destroy it, return SIGNAL_BOMB_HURT.
The player in this case can die, raising Player.PlayerDeath.
An empty spot, with NOTHING on it.
A destructible wall, with JUST the wall on it.
An undestructible wall, with JUST the wall on it.
An empty spot, with JUST an explosion tag on it.
A Class to define a Bomberman board.
For call convention, take a look at [Matrix] module. [mat.box] will be used for printing, so it can be modified by other stuff.
This class can be used both by the client and the server.
Simple constructor of an empty board. Contains a [map] attribute initialized with all elements equal to a copy of [state]. The board is a rectangle, of length [lx] over [ly]. [maxStr] is passed throw the underlying matrix, and will be used for printing (see Matrix.tostr). [utf] is true to use non ASCII caracters for printing the matrix, false otherwise.
his dimension over horizontal axe x.
his dimension over vertical axe y.
max number of player, (for usual boards, it’s 4).
the map of State instances, coding as a matrix (ie. Matrix.Matrix instance).
Simply return a list of Bomb.Bomb associated with their position. Example : [(0,1,<bomb>), (1,3,<bomb>)]
FIXME: it shall be useless now.
Just decrease the timer of the bomb in the board[i,j], [toc] is the time spent during ticking.
FIXME: make sure it spreads from the spot, in the right direction. Seems ok.
FORCE is here to allow the destruction of a bomb even if its timer is not ok...
Warning
This function is quite long, make sure it works correctly !
Just decrease the timer of all bombs in the board, [toc] is the time spent during ticking. MAKE_DESTROY is here to allow ticking the board without triggering any explosion.
Because for the client, timers are just for priting.
Call destroy_bomb whenever it is needed (i.e. when a timer is going non positive (<= 0).)
Special method to allow an iteration with a board.
Warning
This seems to be wrong, use board[i,j] and not spot, if you want to modify board[i,j].
>>> for i,j,spot in board:
>>> spot.destr=False; spot.wall=False; spot.explosion=True
>>> print "Spot at place (%i, %i)" % (i,j)
A class for build an iterator for Board.
It’s mainly done here to learn about iterator. This workaround allow the following shortcut :
>>> for i,j,spot in board:
>>> spot.destr=False; spot.wall=False; spot.explosion=True
>>> print "Spot at place (%i, %i)" % (i,j)
the board used for iteration
current value of i (over axis x)
current value of j (over axis y)