def strength_training(player): '''Training: improves strength''' remove_menu() print(set_title('Strength training')) if not is_undead(player): if can_do_action(player): if is_trainable(player, 'strength'): inkey = _Getch() d = select_difficulty(inkey, [(1, 'Easy'), (2, 'Hard')]) pattern = 'a' * (d + 1) + 'l' * (d + 1) print() print('Repeat the pattern', BOLD + YELLOW + pattern.upper() + ENDC, 'as fast as you can for 5 seconds') input('When you\'re ready, press ENTER ') print('GO!') try: train = input_with_timeout(5, inkey, False) except ValueError: pass train = train.lower().strip() n = len(findall(pattern, train)) improve = n * 2**(d + 1) / 7 * d print('\n| {3} |\nPattern executed {1}{0}{2} times.'.format( n, YELLOW, ENDC, train.upper())) update_stats(player, 'strength', improve) player['stats']['stamina'] -= 1 else: print('As {}undead{} you can\'t strength training!\n'.format( RED, ENDC))
def move(self, GameMap): # 移动函数 getch = _Getch() move_success = False while not move_success: print "位置:%s" % self.char_position print "移动 >", direction = getch() position = self.char_position[:] if direction == 'w': position[1] += 1 elif direction == 'a': position[0] -= 1 elif direction == 's': position[1] -= 1 elif direction == 'd': position[0] += 1 else: prints("按w/a/s/d移动") continue if not self.check_boundary(position, GameMap): # 人物抵达地图边界 print "你向前走去,触摸到了冰冷的墙壁" else: move_success = True self.char_position[:] = position # print GameMap.map_exit if self.char_position == GameMap.map_exit: prints("你发现了地牢的出口, 成功逃出地牢! 大吉大利, 今晚吃鸡!") exit(0)
def choose_magic(self, opponent): if not self.magic_list: print "没有可用的魔法" self.action(opponent) else: print "剩余MP:%d" % self.mp print "可用的魔法列表:" for i in range(len(self.magic_list)): print( "%d. %s(%dmp)" % (i + 1, self.magic_list[i].name, self.magic_list[i].cost)) print "使用魔法 > ", getch = _Getch() magic_option = getch() print magic_option for j in range(len(self.magic_list)): if magic_option == str(j + 1): # 判断是否存在输入的魔法 if self.magic_list[j].cost > self.mp: print "魔法值不足!" self.choose_magic(opponent) else: self.cast_magic(opponent, self.magic_list[j]) break else: print "你的记忆中没有这个魔法\n" self.action(opponent)
def user_pong_w_processing(args): # variables fig = plt.figure() getcharobj = _Getch() reward, done, info = None, False, None # initialize environment env = EnvWrapperPong() state = env.reset() while not done: display_vec = (np.squeeze(env.diff_state) + 1)/2.0 plt.imshow(display_vec, cmap='gray') plt.savefig("./save_graph/vpg_pong_tf_gameplay.png") x = getcharobj() reward, done, info = env.step(x)
def action(self, opponent): # 行动函数 if not self.alive: # 判断自身是否具有行动能力 prints("你挂了!") prints("胜败乃兵家常事,大侠请重新来过") exit(0) getch = _Getch() prints("你想要做什么?\nA: 攻击; B: 魔法; C: 逃跑") action_option = getch() self.escaped = False if action_option == 'A' or action_option == 'a': self.fight(opponent) elif action_option == 'B' or action_option == 'b': self.choose_magic(opponent) elif action_option == 'C' or action_option == 'c': self.escape(opponent) else: print "不存在的操作!" self.action(opponent)
def focus_training(player): '''Training: improves focus''' remove_menu() print(set_title('Focus training')) if is_undead(player) or can_do_action(player): if is_trainable(player, 'focus'): seconds = 3 if is_undead(player): seconds += 2 inkey = _Getch() d = select_difficulty(inkey, [(1, 'Easy'), (2, 'Hard'), (3, 'Insane')]) times = 4 + ((d - 1) * 2) pattern = ''.join( [chr(choice(range(97, 123))) for _ in range(times)]) print('\n> 3', end='\r') sleep(1) print('> 2', end='\r') sleep(1) print('> 1', end='\r') sleep(1) print('> GO!\n') print('Insert the pattern {2}{3}{0}{4} in the next {1} seconds!'. format(pattern.upper(), seconds, YELLOW, BOLD, ENDC)) try: train = input_with_timeout(seconds, inkey, False) except ValueError: pass train = train.strip() print('\n| {} |'.format(train.upper())) if pattern.lower() == train.lower(): improve = 2**d / 10 + 0.1 update_stats(player, 'focus', improve) else: print( 'The patterns don\'t match, {}no improvements{} this time.\n' .format(RED, ENDC)) if not is_undead(player): player['stats']['stamina'] -= 1
def user_pong(args): # variables getcharobj = _Getch() reward, done, info = None, False, None # initialize environment env = gym.make('Pong-v0') state = env.reset() print(env.unwrapped.get_action_meanings()) while not done: env.render() x = getcharobj() if x.lower() == 'u': action = 2 elif x.lower() == 'd': action = 3 else: action = 1 state, reward, done, info = env.step(action)
def rest(player): '''Resting: TODO''' remove_menu() print(set_title('Resting')) if not is_undead(player): if player['stats']['stamina'] < player['max_stats']['stamina']: print( 'Guide your soul to the {}mortal path{}, if you want to live again.' .format(YELLOW, ENDC)) sleep(1) hp_max, restoring = player['hp'], 0 step = hp_max / 10 inkey = _Getch() while abs(restoring) < hp_max: print(hp_bar(hp_max, restoring, reverse=True)) m_path = chr(choice(range(97, 123))) u_path = chr(choice(range(97, 123))) while u_path == m_path: u_path = chr(choice(range(97, 123))) print('Mortal path > {1}{0}{2}'.format(m_path.upper(), GREEN, ENDC)) try: c = input_with_timeout(3, inkey) except ValueError: try: print(ERASE, end='\r') print('Undead path > {1}{0}{2}'.format( u_path.upper(), RED, ENDC)) c = input_with_timeout(1, inkey) except ValueError: c = '-' finally: if c == m_path: restoring += step elif c == u_path: restoring -= step print(ERASE * 2, end='\r') if restoring < 0: print(ERASE, end='\r') player['name'] += ' The UNDEAD' undead_times = len(findall(' The UNDEAD', player['name'])) undead_times_card = ord_to_card(undead_times) if undead_times < 2: print('You follow the {}UNDEAD{} path..'.format(RED, ENDC)) sleep(1) else: print('You follow the {}UNDEAD{} path.. for the {} time!'. format(RED, ENDC, undead_times_card)) sleep(1) if undead_times > 3: increase_strength = 0.5 decrease_focus = 0.2 else: increase_strength = 3 - undead_times + 0.5 decrease_focus = 2**(4 - undead_times) / 10 print('HP: {0} -> {2}{1}{3}'.format(player['hp_left'], 1, RED, ENDC)) print('Strength: {0:.2f} -> {2}{1:.2f}{3}'.format( player['stats']['strength'], player['max_stats']['strength'] * increase_strength, GREEN, ENDC)) print('Focus: {0:.2f} -> {2}{1:.2f}{3}'.format( player['stats']['focus'], player['stats']['focus'] * decrease_focus, RED, ENDC)) print('Stamina: {0} -> {2}{1}{3}'.format( player['stats']['stamina'], -666, PURPLE, ENDC)) player['hp_left'] = 1 player['stats']['stamina'] = -666 if undead_times < 2: player['saved_undead'] = player['stats']['strength'] player['stats']['strength'] = player['max_stats'][ 'strength'] * increase_strength player['stats']['focus'] *= decrease_focus print('Rest {}complete{}!\n'.format(YELLOW, ENDC)) else: print(ERASE, end='\r') print('HP: {0} -> {2}{1}{3}'.format(player['hp_left'], player['hp'], GREEN, ENDC)) player['hp_left'] = player['hp'] player['stats']['stamina'] = player['max_stats']['stamina'] if player['saved_undead'] == 0: print('Strength: {0:.2f} -> {2}{1:.2f}{3}'.format( player['stats']['strength'], player['stats']['strength'] * 0.90, RED, ENDC)) player['stats']['strength'] *= 0.90 else: player['name'] = sub(' The UNDEAD', '', player['name']) print('Strength: {0:.2f} -> {2}{1:.2f}{3}'.format( player['stats']['strength'], player['saved_undead'], RED, ENDC)) player['stats']['strength'] = player['saved_undead'] player['saved_undead'] = 0 print('Focus: {0:.2f} -> {2}{1:.2f}{3}'.format( player['stats']['focus'], player['stats']['focus'] * 0.95, RED, ENDC)) print('Stamina: {0} -> {2}{1}{3}'.format( player['stats']['stamina'], player['max_stats']['stamina'], GREEN, ENDC)) player['stats']['focus'] *= 0.95 print('Rest {}complete{}!\n'.format(YELLOW, ENDC)) else: print( 'You\'re are {}full{} of stamina, you can\'t rest right now!\n' .format(YELLOW, ENDC)) else: print('As {}undead{} you can\'t rest!\n'.format(RED, ENDC))
def battle(player, enemy, fighters_moveset): '''Battle: enemy''' remove_menu() print(set_title('Boss battle')) sleep(1) if is_undead(player) or can_do_action(player): if enough_fast(player, enemy[4]): inkey = _Getch() print('A new Boss appeared..') sleep(2) print(BOLD + RED + enemy[0].upper() + ENDC) enemy_hp_left = enemy[2] enemy_velocity = int( floor(player['stats']['focus']) - enemy[4] + 1) print('{0:<15}{6}{3}{7}\n{1:<15}{6}{4}{7}\n{2:<15}{6}{5}s{7}\n'. format('HP', 'Damage', 'Response time', enemy[1], enemy[3], enemy_velocity, YELLOW, ENDC)) r = input('Do you want to fight? ') while not possible_choice(r[0], ['y', 'n'], str): print(ERASE, end='\r') r = input('Do you want to fight? [y/n] ') if r[0] == 'n': print('You {}run away{} faster than light!\n'.format( YELLOW, ENDC)) return 0 else: print() while enemy_hp_left > 0 and player['hp_left'] > 0: print(versus_step(player, enemy, enemy_hp_left)) bm = rand_move(enemy[5]) try: sleep(random()) print('Enemy does', get_name(fighters_moveset, bm, 1), end='\n') pm = input_with_timeout(enemy_velocity, inkey, moveset=get_shortcut( fighters_moveset[0])) if possible_move(fighters_moveset[0], pm): dmg = damage_vs(fighters_moveset, pm, bm) else: dmg = damage_vs(fighters_moveset, 'n', bm) except ValueError: dmg = damage_vs(fighters_moveset, 'n', bm) finally: space_cancel = ' ' * 30 critic = 1.5 if random() < 0.15 else 1 if dmg > 0: print('Boss takes {0}DAMAGE{1} {2} {3}'.format( GREEN, ENDC, 'with ' + PURPLE + 'CRITIC' + ENDC if critic > 1 else '', space_cancel)) enemy_hp_left -= player['stats'][ 'strength'] * dmg * critic if dmg < 0: print('Player takes {0}DAMAGE{1} {2} {3}'.format( RED, ENDC, 'with ' + PURPLE + 'CRITIC' + ENDC if critic > 1 else '', space_cancel)) player['hp_left'] -= enemy[3] * dmg * critic if dmg == 0: print('Nothing happens..' + space_cancel) sleep(1) print(ERASE + ERASE + ERASE + ERASE, end='') print(versus_step(player, enemy, enemy_hp_left), end='\n\n') if player['hp_left'] <= 0: print('Player dies...\n') player['hp_left'] = 0 player['stats']['stamina'] = 0 return 0 else: player['level'] += 1 player['stats']['stamina'] = 0 print(enemy[0], GREEN + 'DEFEATED' + ENDC + '!!!') sleep(1) print('You reach level ' + YELLOW + str(player['level'] + 1) + ENDC + '!') sleep(1) print(new_moves(player['level']), end='\n') return 1 else: print('You\'ll die instantly, be careful!') print( 'You don\'t have enough focus to counter this Boss\' velocity [{2}{0}{3}] [{1}train focus{3}]\n' .format(enemy[4], YELLOW, BLUE, ENDC)) return 0 else: return 0
ans=1 return ans def txtpause(): ans=raw_input("press 'Enter' to continue:") # while True: # if sys.stdin.read(1)!=" ": # continue return if __name__=="__main__": "test code for text to list application" import sys import getchar inchar=getchar._Getch() if len(sys.argv)>1: ffile=sys.argv[-1] else: ffile=True and raw_input("convert what file to a word list?: ") or "./networktext.txt" wordlst=txw.main(ffile) #raw_input("convert what file to a word list?: ")) for word in wordlst: showWord(word) # Check for key command: # *** options appear to be limited to 'Tkinter' and 'mscrt' functions # key=inchar() # if key=='p': # raw_input("PAUSE") # key='' print("\n\nFini!")