2017-10-20 6 views
0

探索と狩りオプションで1ターンのターンカウンターが必要です。それを現在の時代に加えてください。どうやってやるの?私はPython 2.7を使用しています。初期turn=0は、あなたの探求/ハントケースでPython 2.7でカウントターンを行うには

from main import name 
import os 
import random 


kenyan_sand_boa = { 
    "snek": "kenyan sand boa", 
    "prey": "mice, " "birds, " "lizards", 
    "biome": "desert", 
    "predators": "desert monitor lizard", 
    "adult age": 156, 
    "baby size": 10, 
    "adult size": 20, 
    "current size": 10, 
    "current age": "0", 
    "name": name, 
} 


os.system('cls') 
def menu(): 
     os.system('cls') 
     print '''Now that you have chosen what snek to be, you have a couple 
options 
1. Read info about kenyan sand boas. 
2. Explore. 
3. Hunt. 
4. View inventory. 
5. Save. 
6. Exit. 
''' 

loop = 1 
choice = 0 
while loop == 1: 
    menu() 
    choice = int(raw_input()) 

    if choice == 1: 
     #information about kenyan sand boas 
    if choice == 2: 
     #exploring 
    if choice == 3: 
     #huntinng 
    if choice == 4: 
     #view inventory 
    else: 
     menu() 
+0

trun = 0; .....もしかして.... + + 1? –

+0

ありがとうございます。それは完全に機能します。 –

+0

上部に 'INFO = 1'、' EXPLORING = 2'、 'HUNTING = 3'、' INVENTORY = 4'があると便利かもしれません。これにより、 'if choice == INFO:'などを行うことができます。また、最初の 'elif'の後に' if'をすべて変更することができます。 – user2471379

答えて

1

、以下を追加します:ここでは、コードの重要な部分です

turn = turn+1 
kenyan_sand_boa["current age"] = kenyan_sand_boa["current age"]+1 

はintとして年齢を定義する必要があるかもしれません、など現在は文字列ですが、このコードを実行するとこのコードは完了します。あなたのwhileコードセットターン以内

1

あなたにも年齢をインクリメントしているので

while loop == 1: 
    turn = 0 
    menu() 
    # ... 

0に、"current age"0代わりの"0"に設定する方が良いだろう。 "current age"turnを1つ増やしてif句を探して調べます。 (代わりにelifを使用するためにはもっと無声になります)

elif choice == 2: 
    turn += 1 
    kenyan_sand_boa["current age"] += 1 
    # exploring 
elif choice == 3: 
    turn += 1 
    kenyan_sand_boa["current age"] += 1 
    # hunting 
関連する問題