2017-09-27 11 views
0

私は自分のヒストリークラスのテキストアドベンチャーゲームを書いています。私はまだPythonの新機能ですので、私にご負担ください。"TypeError:テキストアドベンチャーゲームで 'int'オブジェクトが呼び出せません。

# Massachusetts Text Adventure 
# 
#  Written by Nick Decker 
# 
#   In Python 3.6.2 

import time 
from random import * 

startgame = False 
food=100 
drink=100 
morale=80 
people=64 
health=80 
week=1 
start=5 

def week(): 
    global week 
    global food 
    global drink 
    global morale 
    global people 
    global health 
    global start 
    print ("\n" * 100) 
    print("Week number",week) 
    print("Food left: ",food) 
    print("Drink left: ",drink) 
    print("Morale: ",morale) 
    print("People alive: ",people) 
    ftp = input("How much food will you feed your people? Choose a number between 0-10.") 
    if ftp==0: 
     print("You did not feed your people.") 
     health = health - 5 
     morale = morale - 10 
    elif ftp <= 5 and ftp != 0: 
     print("You gave your people some food.") 
     health = health - 2 
     food = food - ftp 
     morale = morale - 2 
    elif ftp <= 10 and ftp > 5: 
     print("You gave your people a lot of food.") 
     health = health + 2 
     food = food - ftp 
     morale = morale + 2 
    dtp = input("How much water will you give your people? Choose a number between 0-10.") 
    if dtp==0: 
     print("You did not give your people any water") 
     health = health - 10 
     morale = morale - 10 
    elif dtp <=5 and dtp != 0: 
     print ("You gave your people some water.") 
     health = health + 1 
     morale = morale + 5 
     drink = drink - dtp 
    elif dtp > 5 and dtp <= 10: 
     print("You gave your people a lot of water") 
     health = health + 5 
     morale = morale + 5 
     drink = drink - dtp 

    if health <= 70: 
     dead = randint(1,7) 
     people = people - dead 

    if morale <= 65: 
     com = randint(1,100) 
     if com <= 50: 
      morale = morale 
     elif com > 50 and com <= 100: 
      mutiny() 
    week = week + 1 
    whattodo() 

def whattodo(): 
    if week > 8: 
     print("You've made it to the New World!") 
     win = input("To play again, type RESTART. To quit, type QUIT.") 
     if win==RESTART: 
      story() 
     elif win==QUIT: 
      quit() 
    else: 
     week() 

def background(): 
    global start 
    print ("\n" * 100) 
    print("Congratulations! You have been appointed by the King himself to lead a journey to Massachusetts!") 
    time.sleep(2.0) 
    print("You are leading a fleet of 11 ships, though in this game, you will be in charge of only one. This ship's name is the Arbella.") 
    time.sleep(2.0) 
    print("The voyage will take months, and you have to keep the people alive and happy.") 
    time.sleep(2.0) 
    print("By controlling food and drink you can keep your people alive.") 
    time.sleep(2.0) 
    print("Good luck!") 
    time.sleep(5.0) 
    start=0 
    week() 

def story(): 
    global startgame 
    global food 
    global drink 
    global morale 
    global health 
    global people 
    global week 
    global start 

    startgame = True 
    food=100 
    drink=100 
    morale=80 
    people=64 
    health=80 
    week=1 

    print ("\n" * 100) 
    print('Welcome to the Massachusetts Text Adventure!') 
    time.sleep(2.0) 
    print('In this game you are on your way to the New World as John Winthrop.') 
    time.sleep(2.0) 
    print('Along the way, you will face many dangers.') 
    time.sleep(2.0) 
    print('You will make friends...') 
    time.sleep(2.0) 
    print('... and enemies.') 
    time.sleep(5.0) 
    background() 

def mutiny(): 
    print ("\n" * 100) 
    global morale 
    print("The people on your ship are unhappy! They are planning a mutiny!") 
    time.sleep(2.0) 
    print("The mutiny has a 50/50 chance of being succesfull.") 
    ms = randint(1,100) 
    if ms <= 50: 
     print("The mutiny failed, and the crew's morale has been boosted by 15!") 
     morale = morale + 15 
     whattodo() 
    elif ms > 50 and ms <= 100: 
     fail = input("You've failed! Type RESTART to restart. Type QUIT to quit.") 
     if fail==RESTART: 
      story() 
     elif fail==QUIT: 
      quit() 

while startgame==False: 
    story() 

プログラムを実行すると、background()でweek()を呼び出すまで続きます。その後、私にこれらのエラーを与える:

Traceback (most recent call last): 
    File "E:\MassTA.py", line 154, in <module> 
    story() 
    File "E:\MassTA.py", line 133, in story 
    background() 
    File "E:\MassTA.py", line 102, in background 
    week() 
TypeError: 'int' object is not callable 

は繰り返しますが、私はまだかなり新しいですので、それは混乱だ場合、私はごめんなさい。 誰かが私にこれらのエラーを修正する方法を教えてもらえますか? ありがとう!

+2

グローバルな「週」変数と関数の両方を持っています。それらのうちの1つを別のものに変更します。 – kichik

+1

こんにちは、ようこそ、スタックオーバーフロー!コードを投稿するときは、コードを[MCVE]に減らしてみてください。つまり、最小限のコードで問題を再作成してください。私たちはあなたのコードを書いていないので、各行のニュアンスや意図をすべて知っているわけではないので、重要なこととそうでないことは分かりません。投稿したコードを単純化することで、コードのエラーを簡単に特定できるようになります。この場合、 'week'変数の問題はすぐ上にあり、すぐに見つけることができましたが、将来はエラーがそれほど単純ではないかもしれないので、[MCVE]の習慣を試してみてください –

答えて

2

あなたのプログラムの冒頭では、変数weekはint:week = 1として割り当てられています。これはあなたの関数:week()と混同されています。問題を解決するために整数または関数の名前を変更してください。

関連する問題