Reputation: 3
I am writing a text adventure game for my History class. I'm still pretty new to Python, so please bear with me.
# 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()
When I run the program, it continues until calling upon week() in background(). It then gives me these errors:
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
Again, I'm still pretty new, so I'm sorry if it's a mess. Could someone please tell me how to fix these errors? Thanks!
Upvotes: 0
Views: 513
Reputation: 427
At the beginning of your program you have variable week assigned as an int: week = 1. That is being confused with your function: week(). rename the integer or the functions to correct your issue.
Upvotes: 2