Map Package#
Submodules#
GameBoard Class#
- class game.common.map.game_board.GameBoard(seed: int | None = None, map_size: ~game.utils.vector.Vector = <game.utils.vector.Vector object>, locations: dict[slice(tuple[game.utils.vector.Vector], list[game.common.game_object.GameObject], None)] | None = None, walled: bool = False)[source]#
Bases:
GameObjectGameBoard Class Notes:
Map Size:#
map_size is a Vector object, allowing you to specify the size of the (x, y) plane of the game board. For example, a Vector object with an ‘x’ of 5 and a ‘y’ of 7 will create a board 5 tiles wide and 7 tiles long.
Example:
_ _ _ _ _ y = 0 | | | | | | | | | | | | _ _ _ _ _ y = 6
Locations:#
This is the bulkiest part of the generation.
The locations field is a dictionary with a key of a tuple of Vectors, and the value being a list of GameObjects (the key must be a tuple instead of a list because Python requires dictionary keys to be immutable).
This is used to assign the given GameObjects the given coordinates via the Vectors. This is done in two ways:
- Statically:
If you want a GameObject to be at a specific coordinate, ensure that the key-value pair is ONE Vector and ONE GameObject. An example of this would be the following:
locations = { (vector_2_4) : [station_0] }
In this example, vector_2_4 contains the coordinates (2, 4). (Note that this naming convention isn’t necessary, but was used to help with the concept). Furthermore, station_0 is the GameObject that will be at coordinates (2, 4).
- Dynamically:
If you want to assign multiple GameObjects to different coordinates, use a key-value pair of any length.
NOTE: The length of the tuple and list MUST be equal, otherwise it will not work. In this case, the assignments will be random. An example of this would be the following:
locations = { (vector_0_0, vector_1_1, vector_2_2) : [station_0, station_1, station_2] }
(Note that the tuple and list both have a length of 3).
When this is passed in, the three different vectors containing coordinates (0, 0), (1, 1), or (2, 2) will be randomly assigned station_0, station_1, or station_2.
If station_0 is randomly assigned at (1, 1), station_1 could be at (2, 2), then station_2 will be at (0, 0). This is just one case of what could happen.
Lastly, another example will be shown to explain that you can combine both static and dynamic assignments in the same dictionary:
locations = { (vector_0_0) : [station_0], (vector_0_1) : [station_1], (vector_1_1, vector_1_2, vector_1_3) : [station_2, station_3, station_4] }
In this example, station_0 will be at vector_0_0 without interference. The same applies to station_1 and vector_0_1. However, for vector_1_1, vector_1_2, and vector_1_3, they will randomly be assigned station_2, station_3, and station_4.
Walled:#
This is simply a bool value that will create a wall barrier on the boundary of the game_board. If walled is True, the wall will be created for you.
For example, let the dimensions of the map be (5, 7). There will be wall Objects horizontally across x = 0 and x = 4. There will also be wall Objects vertically at y = 0 and y = 6
Below is a visual example of this, with ‘x’ being where the wall Objects are.
Example:
x x x x x y = 0 x x x x x x x x x x x x x x x y = 6
- property game_map: list[list[game.common.map.tile.Tile]] | None#
- get_objects(look_for: ObjectType) list[tuple[game.utils.vector.Vector, list[game.common.game_object.GameObject]]][source]#
- property locations: dict#
- property seed: int#
- property walled: bool#
Occupiable Class#
- class game.common.map.occupiable.Occupiable(occupied_by: GameObject = None, **kwargs)[source]#
Bases:
GameObjectOccupiable Class Notes:
Occupiable objects exist to encapsulate all objects that could be placed on the gameboard.
These objects can only be occupied by GameObjects, so inheritance is important. The
Nonevalue is acceptable for this too, showing that nothing is occupying the object.Note: The class Item inherits from GameObject, but it is not allowed to be on an Occupiable object.
- get_occupied_by(target: ObjectType | GameObject) GameObject | None[source]#
Get the object in the occupied_by stack given either the ObjectType or GameObject. Returns the GameObject in the stack, but None if it isn’t there. This does NOT remove the GameObject.
- get_top_of_stack() GameObject | None[source]#
Method to get the top object of a stack
- is_occupied_by_game_object(game_object_type: Type) bool[source]#
This method searches for the given GameObject in the stack of occupied_by. If found, returns true.
- is_occupied_by_object_type(object_type: ObjectType) bool[source]#
This method searches for the given ObjectType in the stack of occupied_by. If found, returns true.
- property occupied_by: GameObject | None#
- place_on_top_of_stack(game_object: GameObject) bool[source]#
This method will take in a GameObject and place it on top of the occupied_by stack of the Occupiable object. The placed object will then also be underneath the Avatar object.
- Example before placing: Tile -> Avatar
After placing: Tile -> NewObject -> Avatar
- remove_game_object_from_occupied_by(game_object: GameObject | None = None) GameObject | None[source]#
This method will remove the first instance of the given ObjectType found in the occupied by stack.
- remove_object_type_from_occupied_by(object_type: ObjectType | None = None) GameObject | None[source]#
This method will remove the first instance of the given ObjectType found in the occupied by stack.
Tile Class#
- class game.common.map.tile.Tile(occupied_by: GameObject = None)[source]#
Bases:
OccupiableTile Class Notes:
The Tile class exists to encapsulate all objects that could be placed on the gameboard.
Tiles will represent things like the floor in the game. They inherit from Occupiable, which allows for tiles to have certain GameObjects and the avatar on it.
If the game being developed requires different tiles with special properties, future classes may be added and inherit from this class.
Wall Class#
- class game.common.map.wall.Wall[source]#
Bases:
GameObjectWall Class Note:
The Wall class is used for creating objects that border the map. These are impassable.