高分 [英] Highscore

查看:64
本文介绍了高分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!我想为我正在制作的游戏制作一个高分。我怎么可能这样做?


谢谢

Hi! I want to make a highscore for a game i am making. How might i do that?

Thanks

推荐答案


嗨!我想为我正在制作的游戏制作一个高分。我该怎么做?


谢谢
Hi! I want to make a highscore for a game i am making. How might i do that?

Thanks



你可能会做很多事。告诉我们更多关于获得高分的信息。意味着(你的意思是想办法记住前5个高分吗?)。

You might do that many ways. Tell us more about what "make a high score" means (do you mean make a way to remember the top 5 high scores over time?).


是....我的意思是....我想让我的程序保存以某种方式排名前十的得分和名字....
Yes.... I mean.... i want to make my program save the top 10 scores and names in some way....



是的......我的意思是......我想做我的程序以某种方式保存前10个分数和名称....
Yes.... I mean.... i want to make my program save the top 10 scores and names in some way....



这里,我使用元组列表。此列表可以按分数排序,然后进行pickle以将其保存到磁盘。 Pickle文档在python 2.4 docs的3.14.3节中。


>>> hiscores = [(300," John")]

>>>得分= 200

>>> player =" Jane"

>>> hiscores.append((得分,玩家))

>>>打印hiscores

[(300,''John''),(200,''Jane'')]

>>> hiscores.sort()

>>>打印hiscores

[(200,''Jane''),(300,''John'')]



>> ;>进口泡菜


>>>得分=开放(得分,w)

>>> pickle.dump(hiscores [-10:],分数)

>>> scores.close()


>>>得分=开放(得分,r)

>>> oldscores = pickle.load(scores)

>>> scores.close()

>>>打印oldscores

[(200,''Jane''),(300,''John'')]

>>>

Here, I use a list of tuples. This list can be sorted by score, then pickled to save it to disk. Pickle documentation is in section 3.14.3 of python 2.4 docs.

>>> hiscores = [(300, "John")]
>>> score = 200
>>> player = "Jane"
>>> hiscores.append((score, player))
>>> print hiscores
[(300, ''John''), (200, ''Jane'')]
>>> hiscores.sort()
>>> print hiscores
[(200, ''Jane''), (300, ''John'')]


>>> import pickle

>>> scores = open("scores", "w")
>>> pickle.dump(hiscores[-10:], scores)
>>> scores.close()

>>> scores = open("scores", "r")
>>> oldscores = pickle.load(scores)
>>> scores.close()
>>> print oldscores
[(200, ''Jane''), (300, ''John'')]
>>>


这篇关于高分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆