コード例 #1
0
class Test(object):
    def run(self):
        moves   = 'd'*2 + 'r'*18 + 'u'*11 + 'l'*17
        moves   = 'r'*9 + 'l'*8
        moves   = 'r'*30 + 'l'*30

        for move in moves:
            board.draw()
            player.move(move, wrap)

        return

        ####
        self.textinput = TextInput(("%hd %hd %s", randcmd))

        while True:
            words.display()
            cmd = self.textinput.getinput()

            if first(cmd) == randcmd : words.randreveal()
            else                     : self.reveal_letter( *cmd )
            words.check_end()

    def reveal_letter(self, *cmd):
        try               : words.guess(*cmd)
        except IndexError : print(self.textinput.invalid_move)
コード例 #2
0
ファイル: robots.py プロジェクト: ntcvantud/simple-games
class BasicInterface(object):
    def run(self):
        cmdpat = "%d?"
        cmdpat = cmdpat + " (%s)" % sjoin(commands.keys(), '|')
        pattern = cmdpat + (" %s?" % cmdpat) * (max_cmds - 1)

        self.textinput = TextInput(pattern,
                                   board,
                                   accept_blank=True,
                                   singlechar_cmds=True)

        while True:
            board.draw()
            print(", ".join("%s: %s" % (k, v) for k, v in commands.items()))
            for unit in players + robots:
                if unit.player:
                    cprog = self.create_program
                else:
                    cprog = unit.create_program
                unit.program = unit.program or cprog()
                unit.go()

    def create_program(self):
        while True:
            try:
                program = self.textinput.getinput() or ['r']
                return rgame.expand_program(program)
            except (KeyError, IndexError):
                print(self.textinput.invalid_inp)
コード例 #3
0
class BasicInterface(object):
    def run(self):
        self.textinput = TextInput("loc %d", board)

        while True:
            board.draw()
            loc, val   = self.get_move()
            board[loc] = Number(val)
            sudoku.check_end()

    def get_move(self):
        while True:
            cmd = self.textinput.getinput()
            if sudoku.valid_move(*cmd) : return cmd
            else                       : print(self.textinput.invalid_move)
コード例 #4
0
ファイル: words.py プロジェクト: Voder/PBE
class BasicInterface(object):
    def run(self):
        self.textinput = TextInput(("%hd %hd %s", randcmd))

        while True:
            words.display()
            cmd = self.textinput.getinput()

            if first(cmd) == randcmd : words.randreveal()
            else                     : self.reveal_letter(*cmd)
            words.check_end()

    def reveal_letter(self, *cmd):
        try               : words.guess(*cmd)
        except IndexError : print(self.textinput.invalid_inp)
コード例 #5
0
class BasicInterface(object):
    def run(self):
        # allow entering of multiple (up to 10) locations
        pattern        = "%s? loc%s" % (mark_key, " loc?"*9)
        self.textinput = TextInput(pattern, board, singlechar_cmds=True)
        while True:
            board.draw()
            self.make_move()

    def make_move(self):
        cmd  = self.textinput.getinput()
        mark = bool(first(cmd) == mark_key)
        if mark: cmd.pop(0)

        for loc in cmd:
            tile = board[loc]
            tile.toggle_mark() if mark else board.reveal(tile)
            mines.check_end(tile)
コード例 #6
0
ファイル: robots.py プロジェクト: lpezzullo/PBE
class BasicInterface(object):
    def run(self):
        cmdpat = "%d?"
        cmdpat = cmdpat + " (%s)" % sjoin(commands.keys(), "|")
        pattern = cmdpat + (" %s?" % cmdpat) * (max_cmds - 1)

        self.textinput = TextInput(pattern, board, accept_blank=True, singlechar_cmds=True)

        while True:
            board.draw()
            for unit in players + robots:
                cprog = self.create_program if unit.player else unit.create_program
                unit.program = unit.program or cprog()
                unit.go()

    def create_program(self):
        while True:
            try:
                program = self.textinput.getinput() or ["r"]
                return rgame.expand_program(program)
            except (KeyError, IndexError):
                print(self.textinput.invalid_inp)
コード例 #7
0
ファイル: betelgeuse.py プロジェクト: Voder/PBE
class BasicInterface(object):
    def run(self):
        self.textinput = TextInput("%hd %hd %d", board, accept_blank=True)

        while True:
            for player in players:
                betelgeuse.show_ships_player = None if player.ai else player
                board.draw()
                player.make_random_moves() if player.ai else self.make_moves(player)
                betelgeuse.check_end()

            for sf in stars + fleets: sf.go()
            betelgeuse.turn += 1

    def make_moves(self, player):
        while True:
            cmd = self.get_move(player)
            if not cmd: break
            player.send(*cmd)
            board.draw()

    def get_move(self, player):
        while True:
            try:
                return self._get_move(player)
            except (IndexError, AssertionError):
                print(self.textinput.invalid_move)

    def _get_move(self, player):
        cmd = self.textinput.getinput()
        if not cmd: return

        src, goal, ships = cmd
        src, goal = stars[src], stars[goal]
        assert src == player and src.ships >= ships
        return src, goal, ships