2016-09-03 15 views
0

私はpyInstallerを使用してスタンドアロンの.exeに変換した小さなPythonアーケードゲームを持っています。それはpygameとうまく動作しますが、問題はpicksを使って最高値を保存することです。私はもともとcmdを使用していたので、cmdでは "あなたの名前を入力してください"と言っていました。あなたが入力したものは、pickleを使って別のファイルに保存されます。 2つの問題:スタンドアロンの.exeでcmdを使用することはできません(とにかく醜いと思われます)、それを別のファイルにpickleで保存すると、スタンドアロンに含まれているとは思われません。コードがユーザー入力セクションを過ぎてしまうことはないので、私は "考える"と言います。pygameの画面上でのユーザー入力の取得方法と保存方法

cmdではなく、自分のフォントと場所でユーザー入力を画面に表示させるにはどうすればよいですか?

は、どのように私は.exeファイルに含まれる(ピクルスで保存されている)ユーザーの入力ファイルを含めることができますか?

これは私が(メインループ内のすべての)現在持っているものです。

if lives == 0: 
    username = input("Please type your name: ") 
    highscore = {username: points} 
    try: 
     with open("C:/Python35/highscore.txt", "rb") as highscoreBest: 
      highscoreBest = pickle.load(highscoreBest) 

    except EOFError: 
     with open("C:/Python35/highscore.txt", "wb") as highscoreBest: 
      pickle.dump(highscore, highscoreBest) 

    for (k, v), (k2, v2) in zip(highscore.items(), highscoreBest.items()): 
     if v >= v2: 
      with open("C:/Python35/highscore.txt", "wb") as highscoreBest: 
       pickle.dump(highscore, highscoreBest) 

    with open("C:/Python35/highscore.txt", "rb") as highscoreBest: 
     highscoreBest = pickle.load(highscoreBest) 

    for key, value in highscoreBest.items(): 
     print("%s has the highscore of %s!" % (key, value)) 
     highscoreText = highscorefont.render("Highscore %s" % (value), 1, textcolor) 

    gameOverText = font.render("GAME OVER", 1, textcolor) 
    scoreText = font.render("Score %s" % (points), 1, textcolor) 

    while 1: 
     screen.blit(gameOverText, (200, 400)) 
     screen.blit(scoreText, (225, 450)) 
     screen.blit(highscoreText, (235,500)) 
     for event in pygame.event.get(): 
      if event.type == pygame.QUIT: sys.exit() 
     pygame.display.flip() 
     time.sleep(1) 

は返信すべての人に感謝します。

答えて

0

あなたのゲームにはGUIがあるように見えます。このhttp://www.pygame.org/wiki/guiをお読みください。例えば

、実行可能ファイルと一緒にバンドルに含めることができますハイスコアのためのテキストファイルについて

OcempGUI 

Links 

Home Page: http://ocemp.sourceforge.net/gui.html 
Source:  http://sourceforge.net/project/showfiles.php?group_id=100329&package_id=149654 
Installation http://ocemp.sourceforge.net/manual/installation.html 

、私はexeファイルとの同梱することができます知っているhttps://pythonhosted.org/PyInstaller/spec-files.html#adding-files-to-the-bundle

Adding Data Files 
To have data files included in the bundle, provide a list that describes the files as the value of the datas= argument to Analysis. The list of data files is a list of tuples. Each tuple has two values, both of which must be strings: 

The first string specifies the file or files as they are in this system now. 
The second specifies the name of the folder to contain the files at run-time. 
For example, to add a single README file to the top level of a one-folder app, you could modify the spec file as follows: 

a = Analysis(... 
    datas=[ ('src/README.txt', '.') ], 
    ... 
    ) 
You have made the datas= argument a one-item list. The item is a tuple in which the first string says the existing file is src/README.txt. That file will be looked up (relative to the location of the spec file) and copied into the top level of the bundled app. 
+0

を参照してください、しかし、私はpyInstallerで必要なファイルを自動的にバンドルする方法を知らないので、手動で追加する方法はわかりません。また、これらの「GUIライブラリ」のインストール方法もわかりません。より具体的になりますか? –

+0

ちょうど私の提案を更新しました – sr3z

+0

ありがとう、これは非常に役に立ちましたが、OcempGUI用にダウンロードした '.gz'ファイルはどうしたらいいですか?すべての「抽出」オプションはグレー表示されています。 –

関連する問題