def prepare(self): self.map = m.Map(self.mode, self.level_info['map'], (0, self.args.size[1]), align=(0, 2)) self.players = [p.Player(self.level_info['player'], i) for i in range(self.mode['connect']['total'])] self.my_player = self.players[self.mode['connect']['id']] self.target_pan = self.get_target_pan() self.pan = self.target_pan self.alpha = 10 # thread self.thread_recv = Thread(target=self.receive, name=f'recv', daemon=True) self.thread_recv.start()
def __init__(self, args, mode, init_status=None): self.args = args self.date = datetime.utcnow().strftime('%Y-%m-%d_%H-%M-%S') self.name = self.date self.mode = mode # display player_colors = cl.get_player_colors()[:self.mode['num']] self.players = [{ 'land': 0, 'army': 0, 'color': player_colors[id] } for id in range(self.mode['num'])] self.scoreboard = sb.Scoreboard(self.args, (self.args.size[0] - 10, 10), self.players, align=(2, 0)) self.map = m.Map(self.args, self.args.get_pos(1, 1), self.players, self.mode['id'], map_status=init_status, align=(1, 1)) self.command = cm.Command(self.args, self.players, self.mode['id']) self.player = h.Human(self.args, self.map) self.turn_displayer = td.TurnDisplayer(self.args, (10, 10), self.map, align=(0, 0)) # record self.status_record = [self.map.get_status(('owner', 'num', 'terrain'))] # connect self.status = { 'connected': [False if id == 0 else True for id in range(self.mode['num'])], 'running': True, 'winner': None, } self.thread_recv = [] for id in range(1, self.mode['num']): new_thread = Thread(target=self.receive(id), name=f'recv-{id}', daemon=True) new_thread.start() self.thread_recv.append(new_thread) self.sends(json.dumps({'tag': 'init', 'status': self.map.init_status}))
def prepare(self): self.map = m.Map(self.mode, (self.args.size[0] // 2, self.args.size[1] // 2), align=(1, 1)) self.log = l.Log(self.mode, self.player_mode, self.threshold) self.ctrl = c.Controls(self.map) self.game_menu = gm.GameMenu(self.mode, (self.args.size[0] - 15, 15), align=(2, 0)) self.game_buttons = gb.GameButtons( (self.args.size[0] - 15, self.args.size[1] - 15), self.log, align=(2, 2)) self.score_board = sb.ScoreBoard(self.mode, self.map, self.threshold, (15, 15), align=(0, 0)) self.set_players()
def __init__(self, args, mode): self.args = args self.mode = mode # display player_colors = cl.get_player_colors()[:self.mode['num']] self.players = [{ 'land': 0, 'army': 0, 'color': player_colors[id] } for id in range(self.mode['num'])] self.scoreboard = sb.Scoreboard(self.args, (self.args.size[0] - 10, 10), self.players, align=(2, 0)) self.command = cm.Command(self.args, self.players, self.mode['id']) self.map_status = None # connect self.status = { 'connected': True, 'running': True, 'winner': None, 'paused': False } self.thread_recv = Thread(target=self.receive, name='recv', daemon=True) self.thread_recv.start() # map while self.map_status is None: time.sleep(0.01) self.map = m.Map(self.args, self.args.get_pos(1, 1), self.players, self.mode['id'], map_status=self.map_status, align=(1, 1)) self.player = h.Human(self.args, self.map) self.turn_displayer = td.TurnDisplayer(self.args, (10, 10), self.map, align=(0, 0))
def __init__(self, args, replay): self.args = args self.replay = replay self.name = '' # display player_colors = cl.get_player_colors()[:self.replay['num']] self.players = [{ 'land': 0, 'army': 0, 'color': player_colors[id] } for id in range(self.replay['num'])] self.scoreboard = sb.Scoreboard(self.args, (self.args.size[0] - 10, 10), self.players, align=(2, 0)) self.replay_menu = rm.ReplayMenu( (self.args.size[0] - 10, self.args.size[1] - 10), align=(2, 2)) self.map = m.Map(self.args, self.args.get_pos(1, 1), self.players, 0, map_status=self.replay['init-status'], align=(1, 1)) self.map.set_status( { 'visible': [True for _ in range(self.map.dim[0] * self.map.dim[1])] }, refresh=False) self.command = cm.Command(self.args, self.players, 0) self.player = rb.ReplayBot(self.args, self.map, self.replay['turn']) self.turn_displayer = td.TurnDisplayer(self.args, (10, 10), self.map, arrows=True, max_turn=self.replay['turn']) # status self.status = {'running': True} self.threshold = 0.5 self.execute(['pause'])
def prepare(self): self.map = m.Map(self.mode, self.level_info['map'], (0, self.args.size[1]), align=(0, 2)) if self.mode['mode'] == 'mult': self.players = [ p.Player(self.level_info['player'], i) for i in range(len(self.mode['connect']['clients']) + 1) ] elif self.mode['mode'] == 'sing': self.players = [p.Player(self.level_info['player'])] self.my_player = self.players[0] self.target_pan = self.get_target_pan() self.pan = self.target_pan self.alpha = 10 # thread if self.mode['mode'] == 'mult': for i in range(len(self.mode['connect']['clients'])): new_thread = Thread(target=self.receive(i), name=f'recv-{i}', daemon=True) self.thread_recv.append(new_thread) new_thread.start()
def __init__(self, args, mode, id, client): self.args = args self.mode = mode # {'num-players', 'size', 'threshold', 'max-apples'} self.id = id self.client = client # map and players self.map = m.Map(self.args, self.args.get_pos(1, 1), dim=self.mode['size'], max_apples=self.mode['max-apples'], align=(1, 1)) player_colors = cl.get_player_colors() init_grids = utils.get_init_grids(self.mode['size']) self.players = [ p.Player(self.args, i, player_colors[i], init_grids[self.id]) for i in range(self.mode['num-players']) ] self.map.focus_board(self.players[self.id].head()) # thread self.send(json.dumps({'tag': 'start-game'})) threading.Thread(target=self.receive, name='client-recv', daemon=True).start()