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)
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)
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)
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 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 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")
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)
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)
def draw(self): print(nl*5 + sjoin(track)) sleep(pause_time)
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)
def writeln(*args): out.write(sjoin(args) + nl)
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)
def ljoin(L): return sjoin(L, space, tiletpl)
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 )
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)