马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
花了好久时间找倒计时的方法,到最后都没找到,后面想到另外一种方法~ 萌新作品大佬们见笑了 import random
import time
def typing_game():
while True:
print('------------------------------------------------------------------------')
print(' ❤欢迎游玩打字游戏❤\n')
print('|-- 1.开始游戏 --|')
print('|-- 2.查看规则 --|')
print('|-- 3.自定难度 --|')
print('|-- 4.退出游戏 --|')
choice = int(input('|-- 输入以上数字选择:'))
if choice == 2:
print("""\n|-- 游戏规则:系统会给你一串英文字符,你需要在规定时间内记住并打出字符 --|
|-- 当你成功打完并正确后,难度会慢慢升级,你可以坚持多久呢? --|
|-- 如果你觉得开始难度太低,你可以选择自定义难度,那就会从你选的难度开始 --|
|-- 是时候展示真正的手速和眼力了!加油 ! --|""")
if choice == 4:
print('\n客官慢走~下次再来玩哟~ ')
break
if choice == 1 or choice == 3:
if choice == 1:
game_time = 16
answer = ''
number = 30
else:
game_time = int(input('请输入规定时间(不得超过60秒):'))
if game_time > 60:
while game_time > 60:
game_time = int(input('请重新输入规定时间(不得超过60秒):'))
answer = ''
number = int(input('请输入字符数量(最大48):'))
first = 0
count_down = ''
while True:
try:
a = list(random.sample('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',number))
except ValueError:
print('你输入的字符数量超出最大数值!为你返回主界面')
reTurn = 1
break
answer = ''.join(a)
if first == 1:
count_down = input('你需要倒计时吗(输入1为需要,输入其他内容则为不需要):')
print('\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
print('目前难度:时间【%d】秒,字符数量(默认30)【%d】个' % (game_time,number))
time.sleep(1)
if count_down == '1' or first == 0:
print('|--倒计时--|')
time.sleep(1)
print('|-- 3 --|')
time.sleep(1)
print('|-- 2 --|')
time.sleep(1)
print('|-- 1 --|')
time.sleep(1)
print("""|-- 开始 --|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~""")
time.sleep(0.5)
time_list1 = list(time.gmtime())
player_typing = input(answer + ':')
time_list2 = list(time.gmtime())
start_second = time_list1[5]
start_min = time_list1[4]
over_second = time_list2[5]
over_min = time_list2[4]
if over_min == start_min:
use_time = over_second - start_second
if over_min > start_min:
if over_min - start_min == 1:
use_time = over_second + (60 - start_second)
else:
use_time = over_second + (60 - start_second) + (60 * (over_min - start_min - 1))
if answer == player_typing and use_time <= game_time:
print('厉害了!离规定时间还有【%d】秒完成,继续加油!' % (game_time - use_time))
first += 1
time.sleep(1)
game_time -= 1
continue
elif answer != player_typing and use_time <= game_time:
print('你没有完全输入正确,下次加油!')
break
elif use_time > game_time and answer == player_typing:
print('超时【%d秒】,太可惜了' % (use_time - game_time))
break
else:
print('你没有完全输入正确,并且超时【%d秒】,蔡!' % (use_time - game_time))
break
try:
reTurn
except UnboundLocalError:
pass
else:
if reTurn == 1:
reTurn = 0
continue
game_over = input('\n请问你还要继续玩吗【输入1继续,输入其它内容离开】:')
if game_over == '1':
continue
else:
print('\n客官慢走~下次再来玩哟~ ')
break
typing_game()
|