示例#1
0
    def doormsg(self, messages):
        descdoors = copy(self.dir.descdoors)

        if descdoors:
            msg = "You see a door "
            end = " of you."
            _and = " and "

            if len(descdoors) == 1:
                msg += first(descdoors) + end
            elif len(descdoors) == 2:
                msg += sjoin(descdoors, _and) + end
            else:
                last = descdoors.pop()
                msg += sjoin(descdoors, ", ") + _and + last + end

            messages.append(msg)
示例#2
0
文件: adv.py 项目: Voder/PBE
    def doormsg(self, messages):
        descdoors = copy(self.dir.descdoors)

        if descdoors:
            msg  = "You see a door "
            end  = " of you."
            _and = " and "

            if len(descdoors) == 1:
                msg += first(descdoors) + end
            elif len(descdoors) == 2:
                msg += sjoin(descdoors, _and) + end
            else:
                last = descdoors.pop()
                msg += sjoin(descdoors, ", ") + _and + last + end

            messages.append(msg)
示例#3
0
文件: words.py 项目: Voder/PBE
    def display(self):
        print(nl*5)

        for n, word in enumerate1(self.words):
            print(lettertpl % n, space, word, nl)
            lnumbers = sjoin(range1(len(word)), space * word.spacing(), lettertpl)
            print(space*4, lnumbers, nl*2)

        print(self.stattpl % (self.random_reveals, self.guesses), nl)
示例#4
0
    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)
示例#5
0
文件: robots.py 项目: lpezzullo/PBE
    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()
示例#6
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()
示例#7
0
    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:
            val = self.term.getch()
            if val=='q':
                sys.exit()
            try:
                return valid_moves[int(val)-1]
            except (ValueError, IndexError):
                print("Invalid move")
示例#8
0
    def run(self, pause_time, display=True):
        """Run the machine, return tuple of (symbol line, win_amount)."""

        rotations    = [randint(1,4) for _ in range(num_reels)]    # reel rotations per cycle
        rd           = reel_delay
        total_cycles = [randint(x, x+rd) for x in range(first_stop, first_stop + rd*num_reels, rd)]

        reels        = [Reel(rotations, max_cycle) for rotations, max_cycle in zip(rotations, total_cycles)]

        for cycle in range1(max(total_cycles)):
            line = sjoin( [reel.symbol(cycle) for reel in reels] )
            if display: print(nl*5, line)
            sleep(pause_time)

        return self.done(reels, display, line)
示例#9
0
文件: betelgeuse.py 项目: Voder/PBE
 def __repr__(self):
     data = [self.char, self.num]
     if show_ships or self == betelgeuse.show_ships_player:
         data.append("%s:%s" % (self.production, self.ships))
     return sjoin(data, space)
示例#10
0
 def draw(self):
     print(nl*5 + sjoin(track))
     sleep(pause_time)
示例#11
0
 def display(self, cursor=False, i=0):
     word = list( (hidden_char if n in self.hidden else l) for n, l in enumerate(self.word) )
     if cursor and words.hl_visible:
         word[i] = '*'
     return sjoin(word, space * self.spacing(), lettertpl)
示例#12
0
def writeln(*args):
    out.write(sjoin(args) + nl)
示例#13
0
 def display(self, cursor=False, i=0):
     word = list((hidden_char if n in self.hidden else l)
                 for n, l in enumerate(self.word))
     if cursor and words.hl_visible:
         word[i] = '*'
     return sjoin(word, space * self.spacing(), lettertpl)
示例#14
0
 def ljoin(L):
     return sjoin(L, space, tiletpl)
示例#15
0
        def ljoin(L): return sjoin(L, space, tiletpl)

        print( space*4, ljoin((1,2,3)), space, ljoin((4,5,6)), space, ljoin((7,8,9)), nl )
示例#16
0
文件: words.py 项目: Voder/PBE
 def __str__(self):
     word = ( (hidden_char if n in self.hidden else l) for n, l in enumerate(self.word) )
     return sjoin(word, space * self.spacing(), lettertpl)