How Do You Change This Code to Python?!?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ajs31000
    New Member
    • May 2010
    • 4

    How Do You Change This Code to Python?!?

    Hey i have this java code for a text based videogame (its like Zork if you know what that is), but im having problems putting it into python. I've changed the parts I know and it starts to run, but then it comes up with random errors like that the Game instance doesn't have a currentRoom attribute. Please tell me if you have any ideas how to put the java code into python, how to make the python code run, or how to put new code from python into the java code? Thank you!!! :D
    Attached Files
  • Glenton
    Recognized Expert Contributor
    • Nov 2008
    • 391

    #2
    Hi

    I think you're going to have to give us more clues than that!

    But a cursory look through suggests that the following might be things to look at/try:
    1. At the end you run the program as follows:
    Code:
    newGame = Game()
    
    currentRoom = Room()
    
    newGame.play()
    This makes no sense to me. the currentRoom variable is clearly not used here.

    2. In the Game class, many class variables are set, but as far as I can see these are never used.

    3. In the __init__ method of the Game class the first three lines are
    Code:
    self.io = Console()
    
    currentRoom = self.bedroom
    
    self.bedroom = Room("your familiar bedroom")
    The currentRoom variable is therefore only defined for the duration of the running of __init__. Intuitively I would guess that what is meant is:
    Code:
    self.io = Console()
    self.bedroom = Room("your familiar bedroom")
    self.currentRoom = self.bedroom
    Unfortunately I don't have visual installed at the moment, but this change might make the difference. Or it might not... You'll have to let us know.

    Comment

    • ajs31000
      New Member
      • May 2010
      • 4

      #3
      Thank you!!! actually im pretty sure that will work... i just started adding in currentRoom variables in an effort to get it to work so all take out that last one too!!!

      Comment

      • Glenton
        Recognized Expert Contributor
        • Nov 2008
        • 391

        #4
        Glad to be of help. Let us know how it goes.

        Comment

        Working...