2017-02-25 8 views
-1

私はPythonには新しく、古典的なテキストの冒険をしようとしています。現在、私の基本的なゲームはコマンドプロンプトで再生されます。PythonでテキストアドベンチャーのUIを作成する最善の方法

  1. が をに解釈される入力を集める下部の入力ボックスを持って
  2. 白地に大きな黒いフォントでゲームのテキストを印刷します: は、どのように私はシンプルなUIを作るに行きますか。 (コマンドプロンプトと同様)

本質的にZorkに似たUIです。 私はtkinterを使ってみましたが、混乱し、非常に効率が悪くなりました。また、あなたが疑問に思っているのであれば、テキストが非常に小さく、読みにくいので、コマンドプロンプトを使用したくないと思っています。

from player import Player 

#intro screen 
def intro(): 
    print('Incarnation') 
    print(''' 
    Welcome to Incarnation, please type an option: 
    - Play 
    - Load 
    - Instructions 
    - Credits 
    - Quit 
    ''') 
    option = input('>').lower() 
    if option == 'play': 
     play() 
    elif option == 'instructions': 

     print(""" 
     Objective: The objective of the game is to complete the narrative by exploring 
     the world, collecting items, defeating enemies and solving puzzles. 
     You control your character by typing commands. 
     Here are some essential commands, make sure to experiment! They are not case sensitive. 
     N, S, E, W: Move your character in the cardinal directions 
     I: Open your inventory 
     H: Heal with an item in your inventory 
     A *item*: Attack with an item. Replace *item* with the name of the item. 
     T *NPC*: Talk to a present NPC. Repalce *NPC* with the name of the person. 
     """) 
    elif option == 'credits': 
     print('made by Lilian Wang') 
    elif option == 'load': 
     pass 
    elif option == 'quit': 
     quit() 
    else: 
     print("That's not an option.") 

player = Player() 

# Possible player actions 
def actions(action): 
    if action == 'n': 
     player.move_north() 
    elif action == 's': 
     player.move_south() 
    elif action == 'e': 
     player.move_east() 
    elif action == 'w': 
     player.move_west() 
    elif 'heal' in str(action): 
     player.heal(action) 
    else: 
     print("You can't do that.") 
     player.previousLocation = player.location 


# Main game function 
def play(): 
    print(player.location.name) 
    while player.gameover == False: 
     if player.previousLocation != player.location: 
      print(player.location.name) 
     action = input(">") 
     actions(action) 

intro() 

答えて

0

は簡単PyQt5にかけてすることができますポートGUIから始まるために良い、PyQt4を使用してみてください:それは場合に役立ちます。ここ

は、メインゲームコードです。 simpeのHello Worldプログラムの アン例: 輸入SYS PyQt4インポートQtGuiから

def window(): 
    app = QtGui.QApplication(sys.argv) 
    w = QtGui.QWidget() 
    b = QtGui.QLabel(w) 
    b.setText("Hello World!") 
    w.setGeometry(100,100,200,50) 
    b.move(50,20) 
    w.setWindowTitle("PyQt") 
    w.show() 
    sys.exit(app.exec_()) 

if __name__ == '__main__': 
    window() 

出力:

enter image description here

PyQt4は、GUIのデザインと学ぶことは非常に簡単のための最高のモジュールです。私は最近、PyQt4で今作っています何のスニークピーク:

enter image description here

あなたが

それが役に立てば幸いPyQt4 hereを学習を開始することができます。

+0

面白そうに見えますが、一度チェックしてください!コマンドを入力するたびに、新しいテキストを画面に印刷するにはどうすればいいですか? –

+0

私はあなたに今説明することはできません。オプションを入力する代わりにクリックするだけで、ボタンを作成することができます。まず、PyQt4の基本を学ばなければならないし、基本的なことについてはGoogleから助けを得ることができます。 :) ご希望の場合は、正しい答えをマークしてください。 –

関連する問題