Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python &引用;类型错误:';int';对象不可调用";文本冒险游戏_Python_Typeerror - Fatal编程技术网

Python &引用;类型错误:';int';对象不可调用";文本冒险游戏

Python &引用;类型错误:';int';对象不可调用";文本冒险游戏,python,typeerror,Python,Typeerror,我正在为我的历史课写一个文本冒险游戏。我对Python还是相当陌生的,所以请容忍我 # 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

我正在为我的历史课写一个文本冒险游戏。我对Python还是相当陌生的,所以请容忍我

# 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()
#马萨诸塞州文本冒险
#
#作者:尼克·德克
#
#在Python 3.6.2中
导入时间
从随机导入*
startgame=False
食物=100
饮料=100
士气=80
人=64
健康=80
周=1
开始=5
def week():
全球周
全球粮食
全球饮料
全球士气
全球人民
全球卫生
全球启动
打印(“\n”*100)
打印(“周数”,周)
打印(“食物剩余:”,食物)
打印(“饮料剩余:”,饮料)
打印(“士气:”,士气)
打印(“活着的人:”,人)
ftp=输入(“您将为您的员工提供多少食物?请在0-10之间选择一个数字。”)
如果ftp==0:
打印(“您没有喂养您的员工。”)
健康=健康-5
士气=士气-10

elif ftp在程序开始时,您将变量week指定为int:week=1。这与函数:week()相混淆。重命名整数或函数以更正问题。

在程序开始时,变量week被指定为int:week=1。这与函数:week()相混淆。重命名整数或函数以更正问题。

您有一个全局
week
变量和一个函数。将其中一个更改为其他。您好,欢迎使用堆栈溢出!在发布代码时,尽量将代码减少到一个最小值;也就是说,尝试用最少的代码重新创建您的问题。因为我们没有编写您的代码,所以我们不知道每一行的所有细微差别或意图,所以我们不知道什么重要,什么不重要,但您知道。简化您发布的代码将帮助我们更容易地定位代码错误。在这种情况下,
week
变量的问题就在顶部附近,而且很快就能找到,但在将来,错误可能不会这么简单,因此尝试养成这样的习惯:您既有一个全局
week
变量,又有一个函数。将其中一个更改为其他。您好,欢迎使用堆栈溢出!在发布代码时,尽量将代码减少到一个最小值;也就是说,尝试用最少的代码重新创建您的问题。因为我们没有编写您的代码,所以我们不知道每一行的所有细微差别或意图,所以我们不知道什么重要,什么不重要,但您知道。简化您发布的代码将帮助我们更容易地定位代码错误。在这种情况下,
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