API merge final
This commit is contained in:
@@ -1,14 +1,42 @@
|
||||
# Game imports
|
||||
from serializable import Serializable
|
||||
from entities.entity import Entity
|
||||
from turn import Turn, TurnAction
|
||||
|
||||
# Native imports
|
||||
import json
|
||||
import uuid
|
||||
|
||||
class Event(Serializable):
|
||||
def __init__(self, location:str):
|
||||
def __init__(self, location:str, initial_description:str, entities:list[str]):
|
||||
super().__init__()
|
||||
self.id = str(uuid.uuid4())
|
||||
self.location = location
|
||||
self.description = ""
|
||||
self.id:str = str(uuid.uuid4())
|
||||
self.location:str = location
|
||||
self.initial_description:str = initial_description
|
||||
|
||||
self.entities:list[str] = entities
|
||||
self.turns:list[Turn] = []
|
||||
self.add_turn()
|
||||
|
||||
def remove_entity(self, entity_id:str):
|
||||
if entity_id in self.entities:
|
||||
self.entities.remove(entity_id)
|
||||
|
||||
def get_current_turn(self):
|
||||
idx = len(self.turns) - 1
|
||||
if idx < 0:
|
||||
raise IndexError("There is no turns yet, you should create one!")
|
||||
return self.turns[idx]
|
||||
|
||||
def add_turn(self):
|
||||
self.turns.append(Turn())
|
||||
|
||||
def perform_action(self, action:TurnAction, entity_id:str, description:str):
|
||||
current_turn = self.get_current_turn()
|
||||
current_turn.add_action(action_type=action, entity_id=entity_id, description=description)
|
||||
|
||||
if current_turn.is_finished():
|
||||
self.add_turn()
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user