예제 #1
0
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)
예제 #2
0
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)
예제 #3
0
    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))
예제 #4
0
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()
예제 #5
0
    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()
예제 #6
0
    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)
예제 #7
0
    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()
예제 #8
0
 def __init__(self, loc=None, direction=None):
     super(Mobile, self).__init__(loc)
     self.direction = direction or Loop(board.dirlist2, name="dir")
     self.program = []
예제 #9
0
 def __init__(self, rotations, max_cycle):
     self.reel      = Loop(symbols.keys(), name="symbol")
     self.rotations = rotations
     self.max_cycle = max_cycle