Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Amber Diehl
15,402 Points__init__ does not appear to be running
I just started to modify bits of the script provided by Kenneth. I like calling things early and frequently to double check progress and ensure changes work.
When I call the basic scripts provided I am not prompted to enter player name. When I run the Character() class manually, looks good.
I copied the Py files to PyCharm and get the same result -- script runs and ends without error and without prompting me for my name. When I run the script in PyCharm with debug on, it's not entering the init. I haven't changed the code provided so why is this not working?
Amber Diehl
15,402 PointsHere's the code of game.py: ... from character import Character from monster import Dragon from monster import Goblin from monster import Troll
class Game: def setup(self): self.player = Character() self.monsters = [ Goblin(), Troll(), Dragon() ] self.monster = self.get_next_monster()
def get_next_monster(self):
try:
return self.monsters.pop(0)
except IndexError:
return None
def monster_turn(self):
# check to see if the monster attacks
if self.monster.attack:
# if so, tell the player
print("{}, a monster has attacked you!".format(self.player.name))
# check if the player wants to dodge
# if so, see if the dodge is successful
# if it is, move on
# if it's not, remove one player hit point
# if the monster isn't attacking, tell that too
def player_turn(self):
# let the player attack, rest, or quit
next_move = input("Do you want to (A)ttack, (R)est, or (Q)uit?").lower()
# if they attack:
# see if the attack is successful
# if so, see if the monster dodges
# if dodged, print that
# if not dodged, subtract the right num hit points from the monster
# if not a good attack, tell the player
# if they rest:
# call the player.rest() method
# if they quit, exit the game
# if they pick anything else, re-run this method
def cleanup(self):
# if the monster has no more hit points:
if self.monster.hit_points == 0:
# add to up the player's experience
self.player.experience += 1
# print a message
# get a new monster
def __init__(self):
self.setup()
while self.player.hit_points and (self.monster or self.monsters):
print(self.player)
self.monster_turn()
self.player_turn()
self.cleanup()
if self.player.hit_points:
print("You win!")
elif self.monsters or self.monster:
print("You lose!")
...
Amber Diehl
15,402 PointsDoh! The class Game is being defined there. I needed to add:
this_game = Game()
and off we went!
Definitely a doh! moment.
Sean Hayes
Courses Plus Student 8,106 PointsSean Hayes
Courses Plus Student 8,106 PointsCan you upload your code so we can take a look at it?