class Reel(object): def __init__(self, rotations, max_cycle): self.reel = Loop(symbols.keys(), name="symbol") self.rotations = rotations self.max_cycle = max_cycle def symbol(self, cycle=0): if cycle and cycle <= self.max_cycle: self.rotate() return self.reel.symbol def rotate(self): self.reel.next(self.rotations)
class BlockyBlocks(object): winmsg = "player %s wins!" counter = Loop(range(check_moves)) def __init__(self): self.term = Term() def check_end(self, player): """Check if game is finished.""" return all(tile.player==player for tile in board) def end(self, player): board.draw() print(nl, self.winmsg % player) sleep(2) sys.exit() def run(self): for p in cycle(players.keys()): board.draw() tile = board.ai_move(p) if p in ai_players else self.get_move(p) tile.increment(p) if self.check_end(p): self.end(p) def get_move(self, player): commands.player = player while True: cmd = self.term.getch() try: val = commands[cmd]() if val: return val except KeyError: print("unknown command:", cmd)
def __init__(self, *args, **kwargs): super(BlocksBoard, self).__init__(*args, **kwargs) neighbours = self.neighbour_cross_locs for tile in self: tile.maxnum = len( [self.valid(nbloc) for nbloc in neighbours(tile)] ) tile.num = Loop(range1(tile.maxnum))
class BlockyBlocks(object): winmsg = "player %s wins!" counter = Loop(range(check_moves)) def check_end(self, player): """Check if game is finished.""" if all(tile.player == player for tile in board): board.draw() print(nl, self.winmsg % player) sys.exit()
def __init__(self, *args, **kwargs): super(BlocksBoard, self).__init__(*args, **kwargs) self.current = Loc(0,0) self.hl_visible = False neighbours = self.neighbour_cross_locs for tile in self: tile.maxnum = len( [self.valid(nbloc) for nbloc in neighbours(tile)] ) tile.num = Loop(range1(tile.maxnum)) if randomize_option: for _ in range(randrange(0, tile.maxnum)): tile.num.next()
def viswrap_draw(self): print(nl*5) # print("self.vtopleft.y", self.vtopleft.y) rows = Loop(self.board, "row", index=self.vtopleft.y) for _ in range(self.vheight): cols = Loop(rows.row, index=self.vtopleft.x) print(space, ujoin( topitems(cols.n_items(self.vwidth)) )) rows.next() sleep(pause_time)
def center_on(self, item_loc): loc = self.ploc(item_loc) halfwidth = iround(self.vwidth / 2) halfheight = iround(self.vheight / 2) if self.viswrap: x = Loop(range(self.width), index=loc.x) y = Loop(range(self.height), index=loc.y) x = x.prev(halfwidth) y = y.prev(halfheight) else: x, y = loc.x - self.halfwidth, loc.y - self.halfheight x, y = max(0, x), max(0, y) writeln(self.vtopleft, loc) self.vtopleft = Loc(x, y) writeln(self.vtopleft); writeln()
def __init__(self, loc=None, direction=None): super(Mobile, self).__init__(loc) self.direction = direction or Loop(board.dirlist2, name="dir") self.program = []
def __init__(self, rotations, max_cycle): self.reel = Loop(symbols.keys(), name="symbol") self.rotations = rotations self.max_cycle = max_cycle