Utils Package#
Submodules#
Generate Game Class#
- game.utils.generate_game.generate(seed: int = 153616004)[source]#
This method is what generates the game_map. This method is slow, so be mindful when using it. A seed can be set as the parameter; otherwise, a random one will be generated. Then, the method checks to make sure the location for storing logs exists. Lastly, the game map is written to the game file. :param seed: :return: None
Helpers Class#
Thread Class#
- class game.utils.thread.CommunicationThread(func, args=None, variable_type=None)[source]#
Bases:
ThreadCommunication Thread Class Notes:
Communication Threads are bulkier than normal Threads. It also has error catching functionality, but tends to be used for single-use, single-variable communication.
For example, if a client tries to use malicious code in any methods, a Communication Thread is used to check any given parameters and throw an error if the type needed does not match what is given.
Communication Threads use a nested class to make the return value of the Communication Thread private. It helps to keep things secure. This is now achieved through getter and setter decorators. Since the code here was written long ago, the structure is different. For future note, use getter and setter decorators as needed.
- run()[source]#
Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
- class game.utils.thread.Thread(func, args)[source]#
Bases:
Thread- Thread Class Notes:
Threads are how the engine communicates with user clients. These Threads are built to catch errors. If an error is caught, it will be logged, but the program will continue to run.
If multithreading is needed for whatever reason, this class would be used for that.
- run()[source]#
Method representing the thread’s activity.
You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.
Validation Class#
Vector Class#
- class game.utils.vector.Vector(x: int = 0, y: int = 0)[source]#
Bases:
GameObjectVector Class Notes:
This class is used universally in the project to handle anything related to coordinates. There are a few useful methods here to help in a few situations.
- Add Vectors Method:
This method will take two Vector objects, combine their (x, y) coordinates, and return a new Vector object.
- Example:
vector_1: (1, 1) vector_2: (1, 1)
Result: vector_result: (2, 2)
- Add to Vector method:
This method will take a different Vector object and add it to the current Self reference; that is, this method belongs to a Vector object and is not static.
- Example:
self_vector: (0, 0) vector_1: (1, 3)
Result: self_vector: (1, 3)
- Add X and Add Y methods:
These methods act similarly to the
add_vector()method, but instead of changing both the x and y, these methods change their respective variables.- Add X Example:
self_vector: (0, 0) vector_1: (1, 3)
Result: self_vector: (1, 0)
- Add Y Example:
self_vector: (0, 0) vector_1: (1, 3)
Result: self_vector: (0, 3)
- As Tuple Method:
This method returns a tuple of the Vector object in the form of (x, y). This is to help with storing it easily or accessing it in an immutable structure.
- property x: int#
- property y: int#