Python游戏高分

时间:2014-06-30 08:23:53

标签: python

嗨我已经在python中制作了一个游戏,你需要在时间用完之前输入指定的数字。我希望能够保存前5名的高分并在最后显示它们。我已经浏览网页寻找解决方案,但在python中成为业余爱好者,我只是无法根据我的编码量身定制它们。我想将名称和分数保存在一行中,最好使用\ t来分隔它们。

任何答案都会非常感激。

游戏:

# number press game
import time
import random


print "Welcome to my Number Press Game"
print "the computer will display a number"
print "you will have to enter the number before the time runs out"
name = raw_input ("please enter your name: "+"\n")

print "\n"+"welcome to the game "+name

print "ready"
time.sleep (1)
print "steady"  
time.sleep (1)
print "GO!"

#game 
loop = -1
t = 3
while True:
    loop = loop+1 
    x = random.randint(1,3)
    print x
    start = time.time()
    num = input("the number is: ")
    end = time.time()
    elapsed = end - start
    if elapsed > t and num == x:
        print "CORRECT, but too slow"
        break

    elif num != x and elapsed < t:
        print "\n"+"WRONG, but in time"
        break
    elif num != x and elapsed > t:
        print "WRONG and too slow"
        break
    if num == x and elapsed< t:
       print "CORRECT and in time"
       if t>0.7:
           t =t*0.9


print "you loose"
print name+" scored: "+str(loop)

1 个答案:

答案 0 :(得分:0)

运行它,看看它是否给出了你的想法:这运行模拟游戏n次。然后打印出最高分数作为所有分数的列表。就在这里我使用了y = 5,如果你需要5个最高分,我认为你需要玩游戏至少5次然后比较得分和最高值打印为你的最高分:在{{1} }。然后对highest_scores进行排序,以挑选出您需要的n个最高分数。也就是说,你应该检查你的逻辑似乎是有问题的。如果有帮助就投票给答案。干杯

for loop
相关问题