def load(self, player, status, objs, linked_event=None): if objs is None: log.e("No object for event {}".format(self)) self.player = player self.objs = objs self.linked_event = linked_event
def load(self, game, player, status, objs, zone_name): if objs is None: log.e("No object for event {}".format(self)) if zone_name is None: log.e("No zone for event {}".format(self)) self.objs = objs self.zone_name = zone_name self.zones = []
def __init__(self, name): if name is None: log.e("Invalid name for Zone") self.id = uuid.uuid4() self.name = name self.objects = [] self.staged = []
def __init__(self, num_players): if num_players < 2: log.e("Invalid number of players") self.id = uuid.uuid4() self.state = GameState.RUNNING self.objects = [] # TODO: Load rules self.rules = [RulePriorityPass(), RuleAdvanceTurn()] # TODO: Allow different types of players self.players = collections.deque() for i in range(num_players): self.players.append(ConsolePlayer(self)) self.active_player = None self.event_queue = EventQueue(self) self.event_history = [] self.turn = Turn(self) self.manapool = {"black": 0, "blue": 0, "gree": 0, "red": 0, "white": 0, "colorless": 0} self.zones = { "battlefield": Zone("battlefield"), "stack": Zone("stack"), "exile": Zone("exile"), "ante": Zone("ante"), "command": Zone("command"), } for player in self.players: library = Zone("library") library.exhausted = False self.zones["library", player.id] = library self.zones["hand", player.id] = Zone("hand") self.zones["graveyard", player.id] = Zone("graveyard") # TODO: handle deck loading player.load_deck() for card in player.deck.main: card.load(library, player) library.add_object(card) self.objects.append(card)
def __init__(self, filename=None): self.id = uuid.uuid4() self.filename = filename self.main = [] self.side = [] if filename is None: return with open(filename) as f: data = f.read() in_sideboard = False for line in data.split('\n'): if not line.strip(): in_sideboard = True continue exp = re.search("([0-9]+) (.+)", line.strip()) amount = int(exp.group(1)) cardname = exp.group(2) filename = Deck.get_file_name(cardname) classname = Deck.get_class_name(cardname) try: card_module = importlib.import_module("cards.{}".format(filename)) card_class = getattr(card_module, classname) except: log.e("Card not found: {}".format(cardname)) log.d("Card Loaded: {}".format(card_class)) for i in range(amount): if not in_sideboard: self.main.append(card_class()) else: self.side.append(card)
def wait_on(self, event, priority=False): if event is None: log.e("Cannot wait on NULL event") if event == self: log.e("An event cannot wait on itself") if self.status is EventStatus.ABORTED: log.e("Cannot wait od aborted event") self.wait_list.append(event) self.game.event_queue.queue(event, priority) self.status = EventStatus.WAITING
def __init__(self, game): if game is None: log.e("NULL game provided to GameLoop") self.game = game
def remove_object(self, card): if card is None: log.e("Null card removed to zone {}".format(zone.name)) self.objects.remove(card)
def add_object(self, card): if card is None: log.e("Null card added to zone {}".format(zone.name)) self.objects.append(card)