Esempio n. 1
0
File: tmovies.py Progetto: Voder/PBE
    def run(self):
        inp     = TextInput()
        mfiles  = [fn for fn in os.listdir(tut_dir) if not fn.startswith('.')]
        choices = [ (first(f.split('.')), f) for f in mfiles ]

        while True:
            Tutorial(inp.menu(choices)).play()
Esempio n. 2
0
def getScreen(stdscr):
    return Screen(stdscr, 8, 4, [Text(1, 2, 'Register')],
                  [[TextInput(2, 2, "Name")], [TextInput(3, 2, "ShortDsc")],
                   [TextInput(4, 2, "Desc")], [TextInput(5, 2, "Value")],
                   [TextInput(6, 2, "Category")],
                   [AddButton(7, 1, "Add"),
                    BackButton(7, 3, "Back")]])
Esempio n. 3
0
    def run(self):
        inp = TextInput()
        mfiles = [fn for fn in os.listdir(tut_dir) if not fn.startswith('.')]
        choices = [(first(f.split('.')), f) for f in mfiles]

        while True:
            Tutorial(inp.menu(choices)).play()
Esempio n. 4
0
 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()
Esempio n. 5
0
def getScreen(stdscr):
    return Screen(
        stdscr, 8, 4, [Text(1, 2, 'Register')],
        [[TextInput(2, 2, "Username")], [TextInput(3, 2, "Password")],
         [TextInput(4, 2, "First")], [TextInput(5, 2, "Last")],
         [TextInput(6, 2, "Role")],
         [RegisterButton(7, 1, "Register"),
          BackButton(7, 3, "Back")]])
Esempio n. 6
0
    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()
Esempio n. 7
0
    def run(self):
        self.textinput = TextInput(board=board)

        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)
            bblocks.check_end(p)
Esempio n. 8
0
    def run(self):
        # board is only used to check if location is within range (using board.valid())
        self.textinput = TextInput(board=first(players).board)

        for player in cycle(players):
            bship.draw()
            tile = self.ai_move(player) if player.ai else self.get_move(player)
            tile.hit()
            bship.check_end(player.enemy())
Esempio n. 9
0
    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()
Esempio n. 10
0
    def run(self):
        moves          = board.get_valid_moves
        player         = rndchoice(players)
        player         = first(players)
        self.textinput = TextInput(board=board)

        while True:
            board.draw()
            move = player.get_random_move() if player.ai else self.get_move(player)
            player.make_move(move)

            # give next turn to enemy OR end game if no turns left, FALLTHRU: current player keeps the turn
            if moves(player.enemy()) : player = player.enemy()
            elif not moves(player)   : versi.game_end()
Esempio n. 11
0
    def run(self):
        self.textinput = TextInput("(r|p|s)")
        scores = [0, 0]

        while True:
            choice1, choice2 = (self.get_move(p) for p in players)

            if choice1 != choice2:
                winplayer = 1 if (choice1 + choice2 in wins) else 0
                scores[winplayer] += 1

            print(status % (players[0], scores[0], players[1], scores[1],
                            choice1, choice2))
            sleep(pause_time)
Esempio n. 12
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)
Esempio n. 13
0
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)
Esempio n. 14
0
class BasicInterface(object):
    def run(self):
        """ Run main game loop.

            If more than one valid move is available to the human player, let him make the choice
            with `get_move()`.
        """
        def offer_choice(): return bool(not player.ai and len(valid_moves) > 1)

        self.textinput = TextInput('%hd')
        pchar          = first(p for p in player_chars if p not in ai_players)
        if pchar: print("You are playing:", pchar)

        for player in cycle(players):
            race.draw()
            movedist    = dice.rollsum()
            valid_moves = race.valid_moves(player, movedist)
            getmove     = self.get_move if offer_choice() else rndchoice

            race.move(*getmove(valid_moves))
            player.check_end()

    def get_move(self, valid_moves):
        """Get player's choice of move."""
        moves = [space] * (length + 6)
        for n, (loc, _) in enumerate1(valid_moves):
            moves[loc] = n
        print(sjoin(moves))

        while True:
            try:
                return valid_moves[ self.textinput.getval() ]
            except IndexError:
                print(self.textinput.invalid_move)
Esempio n. 15
0
File: bblocks.py Progetto: Voder/PBE
    def run(self):
        self.textinput = TextInput(board=board)

        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)
            bblocks.check_end(p)
Esempio n. 16
0
    def run(self):
        """ Run main game loop.

            If more than one valid move is available to the human player, let him make the choice
            with `get_move()`.
        """
        def offer_choice(): return bool(not player.ai and len(valid_moves) > 1)

        self.textinput = TextInput('%hd')
        pchar          = first(p for p in player_chars if p not in ai_players)
        if pchar: print("You are playing:", pchar)

        for player in cycle(players):
            race.draw()
            movedist    = dice.rollsum()
            valid_moves = race.valid_moves(player, movedist)
            getmove     = self.get_move if offer_choice() else rndchoice

            race.move(*getmove(valid_moves))
            player.check_end()
Esempio n. 17
0
    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()
Esempio n. 18
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)
Esempio n. 19
0
class Test(object):
    def run(self):
        self.textinput = TextInput(board=board)

        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)
            bblocks.check_end(p)

    def get_move(self, player):
        while True:
            loc = self.textinput.getloc()
            if board.valid_move(player, board[loc]): return board[loc]
            else: print(self.textinput.invalid_move)
Esempio n. 20
0
class BasicInterface(object):
    def run(self):
        # board is only used to check if location is within range (using board.valid())
        self.textinput = TextInput(board=first(players).board)

        for player in cycle(players):
            bship.draw()
            tile = self.ai_move(player) if player.ai else self.get_move(player)
            tile.hit()
            bship.check_end(player.enemy())

    def get_move(self, player):
        """Get user command and return the tile to attack."""
        return player.enemy().board[self.textinput.getloc()]

    def ai_move(self, player):
        """Very primitive 'AI', always hits a random location."""
        return player.enemy().board.random_unhit()
Esempio n. 21
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)
Esempio n. 22
0
class RockPaperScissors(object):
    def run(self):
        self.textinput = TextInput("(r|p|s)")
        scores = [0, 0]

        while True:
            choice1, choice2 = (self.get_move(p) for p in players)

            if choice1 != choice2:
                winplayer = 1 if (choice1 + choice2 in wins) else 0
                scores[winplayer] += 1

            print(status % (players[0], scores[0], players[1], scores[1],
                            choice1, choice2))
            sleep(pause_time)

    def get_move(self, player):
        if player in ai_players: return randchoice(moves)
        else: return self.textinput.getval()
Esempio n. 23
0
class BasicInterface(object):
    def run(self):
        moves          = board.get_valid_moves
        player         = rndchoice(players)
        player         = first(players)
        self.textinput = TextInput(board=board)

        while True:
            board.draw()
            move = player.get_random_move() if player.ai else self.get_move(player)
            player.make_move(move)

            # give next turn to enemy OR end game if no turns left, FALLTHRU: current player keeps the turn
            if moves(player.enemy()) : player = player.enemy()
            elif not moves(player)   : versi.game_end()

    def get_move(self, player):
        while True:
            loc = self.textinput.getloc()
            if board.valid_move(player, loc) : return loc
            else                             : print(self.textinput.invalid_move)
Esempio n. 24
0
    def run(self):
        player.look()

        while True:
            cmd = TextInput("(a|s|w|d|p|i|m|l)").getval()
            getattr(player, commands[cmd])()
Esempio n. 25
0
from os.path import exists
from textwrap import wrap
from time import sleep
from copy import copy

from utils import TextInput, Container, shuffled, getitem, nl, space

width = 78
screensep = 30
border = Container(tl='╭', tr='╮', bl='╰', br='╯', horiz='─', vertical='│')
cards_fn = "cards.txt"
question = " Did you get it right (Y/n)? "
status = "\n %d right out of %d (%d%%)\n"
sep = "--"

textinput = Container(question=TextInput(accept_blank=True, prompt=question),
                      pause=TextInput(accept_blank=True))


class Card(object):
    def __init__(self, card):
        front, back = card.split(sep, 1)
        self.front = front.strip()
        self.back = back.strip()

    def draw(self, status_msg):
        print(nl * screensep)
        self.box(self.front)
        print(status_msg)
        textinput.pause.getinput()
Esempio n. 26
0
def getScreen(stdscr):
    return Screen(
        stdscr, 5, 4, [Text(1, 2, 'Search')],
        [[TextInput(2, 2, "Category")], [TextInput(3, 2, "Name")],
         [SearchResultsButton(4, 1, "Search"),
          BackButton(4, 3, "Back")]])
Esempio n. 27
0
def getScreen(stdscr):
    return Screen(
        stdscr, 5, 4, [Text(1, 2, 'Login')],
        [[TextInput(2, 2, "Username")], [TextInput(3, 2, "Password")],
         [LoginButton(4, 1, "Login"),
          BackButton(4, 3, "Back")]])