如何才能建立账户? Python
我想用 python 制作一个简单的游戏,全基于文本。有点像带有谜题等的互动故事,但可能很长。我希望人们能够“保存进步”。也许给他们自己指定一个名字等等?我是 Python 新手,想知道是否可以建立一个包含游戏详细信息的银行,可以通过输入用户名来访问该银行,因此将加载代码的正确区域以允许玩家从离开的地方继续的。
假设他们在……发现谋杀案线索后决定退出游戏。计算机会存储他们所在的代码行并让他们输入自己的名字。下次他们可以从启动菜单中选择“加载”,然后输入他们的名字。然后计算机会搜索他们的名字并提取他们所在的代码段并从那里继续正常进行。
我对此很陌生,所以请尝试简单地解释一下。我可以制作菜单等。如果条件等没有问题,并使故事成为自己的。这只是我想添加的负载。
我希望这不会太复杂!?请帮我!
I want to make a simple game on python, all text based. Sort of an interactive story with puzzles etc. but it is likely to be long. I want to be able to it possible for poeple to sort of, 'Save Progress'. Perhaps assign them selves a name etc? I am new to Python and am wondering if it is possible to set up a bank containing details of game play that can be accessed by entering a username and so will load the correct area of the code to allow the player to pick up where they left of.
Say they decided to quit the game just after... say, finding a clue to a murder. The computer would store the line of code they were on and get them to enter their name. Next time they could select 'Load' from the start up menu and then enter their name. The computer would then search for their name and pull up the peice of code they were at and continue as normal from there.
I am new at this so please try and explain simply. I can make a menu etc. no problems with the if's etc and make the story it's self. It is just the loading I want to add.
I hope this isn't tooooo complicated!? Please help me!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该检查 pickle 模块。它允许您存储/检索任何 python 对象。实现此目的的一种方法是让您的游戏在一个类中进行,其中所有状态/等都是该类(或派生类)的成员。当他们想救你的时候,就会破坏你的班级!
您对 python 还很陌生,我建议您阅读此处提供的文档: http://docs.python.org/教程/。
Python 力求既易于学习又全面。大多数问题都会自己回答!
You should check out the pickle module. It allows you to store/retrieve any python object. One way to do this would be to have your game take place in a class, where all of the states/etc were members of that class (or derived classes). When they wanted to save you would just pickle your class!
You are pretty new to python, I would recommend reading the documentation provided here: http://docs.python.org/tutorial/ .
Python tries to be both easy to learn and comprehensive. Most questions answer themselves!
取决于您如何创建游戏...
您是否遵循用户在游戏中做出的决策树?如果是这样,您将决策保存在文件中,保存到某个位置(例如“saves/{username}/{name_of_save}.sav”或“saves/{username.sav}”,如果每个用户名只应保存一次,但这只是一个例子,一切都取决于你)。然后,您可以允许他们选择保存文件,然后模拟文件中的操作,直到到达最后做出决定的位置。
如果您想轻松地将数据保存到文件中,您还可以使用 JSON 等格式, python 内置支持 - 阅读更多信息 http://docs.python.org/library /json.html 。这将使您能够轻松创建要从文件中保存/读取并用于处理的对象。
希望有帮助...
只是一个想法,我实际上还没有尝试过这样的事情
Depends on how you create your game...
Do you follow the tree of decisions that the user took in the game? If so you save the decisions in a file, that you save to a location (for example "saves/{username}/{name_of_save}.sav or just "saves/{username.sav} if every username should have only one save, but this is just a example it all depends on you). You could then allow them to select their save file and then simulate the actions from the file till you reach the point where the last decision took place.
If you would like to easily save the data to the file(s) you could also use a format like JSON, which python has built-in support for - read more at http://docs.python.org/library/json.html . This will allow you to easily create objects that you want to save/read from the file and use for processing.
Hope that helps...
Just a Idea, I have not actually tried anything like this
看一下 http://www.sqlite.org/ 或使用纯文本文件作为开始:)您可以使用用户名:位字段来编码您的进度。或者使用 Python 的 ConfigParser 模块并为每个用户创建一个部分:) 祝学习愉快:)
Take a look at http://www.sqlite.org/ or use plain text files for the beginning:) you could use the username:bitfield to encode you progress. Or use the ConfigParser module for Python and create a scetion for each user:) have fun learning:)