def __init__(self, args): # arguments self.args = args # regex self.regex = r'(([1-9]?[0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5]))' self.regex_one = r'^' + self.regex + r'\.?$' self.regex_two = r'^' + self.regex + r'\.' + self.regex + r'\.?$' self.regex_three = r'^(' + self.regex + r'\.){2}' + self.regex + r'\.?$' self.regex_full = r'^(' + self.regex + r'\.){3}' + self.regex + r'$' # socket self.server_ip = '' self.client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.client.settimeout(1.0) # gui self.background = c.Component(lambda ui: ui.show_div((0, 0), self.args.size, color=(60, 179, 113))) self.error_msg = None self.error_msg_clock = sw.Stopwatch() self.buttons = { 'connect': c.Button( (self.args.size[0] // 2, 540), (400, 60), 'connect', font=f.tnr(22), align=(1, 1), background=(210, 210, 210) ), 'back': c.Button( (self.args.size[0] // 2, 640), (400, 60), 'back', font=f.tnr(22), align=(1, 1), background=(210, 210, 210) ), }
def __init__(self, pos): self.pos = pos # (120, 90) self.stopwatch = sw.Stopwatch() self.text_img = None self.text_width = 0 self.small_text_img = None self.small_text_width = 0
def __init__(self, args, pos, players, id, dim=(29, 24), *, map_status=None, align=(0, 0)): self.args = args self.id = id self.dim = dim self.prd = tuple(product(range(self.dim[0]), range(self.dim[1]))) self.eprd = tuple(enumerate(self.prd)) # display self.grid_size = 40 self.total_size = self.dim[0] * self.grid_size, self.dim[ 1] * self.grid_size self.pos = utils.top_left(pos, self.total_size, align=align) self.pan = (0, 0) # cursor and blocks self.cursor = None self.blocks = None self.cities = None self.players = players self.init_status = None MapLoader.init_blocks(self, map_status=map_status) # update self.turn = 0 self.update_interval = 0.5 self.city_gen = 2 self.blank_gen = 50 self.clock = sw.Stopwatch() self.clock.start() # record self.record = [[None for _ in self.players]] # refresh self.refresh()
def __init__(self, args): self.args = args self.background = c.Component(lambda ui: ui.show_div((0, 0), self.args.size, color=(60, 179, 113))) self.btn_slots = [ (self.args.size[0] // 2, 150), (self.args.size[0] // 2, 270), (self.args.size[0] // 2, 390), (self.args.size[0] // 2, 510) ] self.beacon = DiscoveryBeacon('224.0.3.101', list(range(5000, 5100)), b'battleofsnakes') self.beacon.start() self.rooms = [] self.buttons = { 'back': c.Button( (self.args.size[0] // 2, 650), (400, 60), 'Back', font=f.tnr(25), save='tnr-25', align=(1, 1), background=(210, 210, 210)), } self.refresh() self.timer = sw.Stopwatch() self.timer.start()
def __init__(self, mode, map, log, side): self.mode = mode self.map = map self.log = log self.side = side self.friendly = [] if self.mode == '2': self.friendly = { 'red': ['green'], 'yellow': ['blue'], 'blue': ['yellow'], 'green': ['red'] }[self.side] self.steps = 0 # ai self.opening = o.Opening(self.mode, self.side) self.ai_bot = ai.Minimax(self.mode, self.map, self.side, self.friendly) self.stopwatch = sw.Stopwatch() self.speed = 1 self.decision = None
def __init__(self, mode, clients): self.mode = mode # {'version', 'num-players', 'size', 'threshold', 'max-apples'} self.clients = clients self.map = m.Map(dim=self.mode['size'], max_apples=self.mode['max-apples']) init_grids = utils.get_init_grids(self.mode['size']) self.players = [ p.Player(i, grids=init_grids[i]) for i in range(self.mode['num-players']) ] self.map.generate_apples(self.players) self.status = {'running': True, 'connect': {i: True for i in range(self.mode['num-players'])}} # receive for id in range(self.mode['num-players']): threading.Thread(target=self.receive, args=(id,), name=f'server-recv{id}', daemon=True).start() # timer self.timer = sw.Stopwatch() self.timer.start() self.send_all(json.dumps({'tag': 'status', 'status': self.get_status()}, separators=(',', ':')))
def __init__(self, args): self.args = args self.background = c.Component(lambda ui: ui.show_div((0, 0), self.args.size, color=(60, 179, 113))) self.buttons = { 'new': c.Button( (self.args.size[0] // 2, 360), (600, 80), 'New Game', font=f.tnr(25), align=(1, 1), background=(210, 210, 210) ), 'join': c.Button( (self.args.size[0] // 2, 460), (600, 80), 'Join Game', font=f.tnr(25), align=(1, 1), background=(210, 210, 210) ), 'quit': c.Button( (self.args.size[0] // 2, 560), (600, 80), 'Exit', font=f.tnr(25), align=(1, 1), background=(210, 210, 210) ), 'reload_settings': c.Button( (self.args.size[0] - 140, self.args.size[1] - 3), (280, 30), '>> Reload settings <<', font=f.get_font('courier-prime', 20), align=(1, 2), color=(None, (255, 255, 255)), background=None, border=1 ) } self.settings_reloaded = False self.timer = sw.Stopwatch()
def __init__(self, map, log): self.map = map self.log = log self.gen = self.log.read() self.stopwatch = sw.Stopwatch() self.speed = 1