示例#1
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")]])
示例#2
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")]])
示例#3
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()
示例#4
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()
示例#5
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)
示例#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()
示例#7
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())
示例#8
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()
示例#9
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()
示例#10
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)
示例#11
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()
示例#12
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()
示例#13
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")]])
示例#14
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")]])
示例#15
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()
示例#16
0
    def run(self):
        player.look()

        while True:
            cmd = TextInput("(a|s|w|d|p|i|m|l)").getval()
            getattr(player, commands[cmd])()