0

I am trying to create a dungeon developing program, and I have a number of modules I am using. I have a main module, a floor module, a room module, and a tile module. Floors are girds of rooms which are grids of tiles. In my floor module, I import Room so that I can store a two dimensional list of Rooms, but I keep getting the error:

Traceback (most recent call last):
 File "C:\Users\Rishabh\workspace\Bonding\Bonding\src\MainWork.py", line 15, in <module>
  floor = Floor.Floor()
 File "C:\Users\Rishabh\workspace\Bonding\Bonding\src\Floor.py", line 6, in __init__
  rooms = [[Room.RoomClass(i, j) for i in range(7)] for j in range(7)]
 File "C:\Users\Rishabh\workspace\Bonding\Bonding\src\Floor.py", line 6, in <listcomp>
  rooms = [[Room.RoomClass(i, j) for i in range(7)] for j in range(7)]
 File "C:\Users\Rishabh\workspace\Bonding\Bonding\src\Floor.py", line 6, in <listcomp>
  rooms = [[Room.RoomClass(i, j) for i in range(7)] for j in range(7)]
NameError: global name 'Room' is not defined

My code is as follows.

Mainwork.py

import Enemy
import Player
import Ribbon
import random
import Floor
import Room
import pygame as pyg
pyg.init()

screenWidth = 1280
screenHeight = 720
Player.health = 100
FPS = 60

floor = Floor.Floor()
floor.printgrid()

def mainLoop():
    pass

Floor.py

class Floor(object):

    import Room

    def __init__(self):
        rooms = [[Room.Room(i, j) for i in range(7)] for j in range(7)]
        current = [0, 0]
        roomStack = []
        totalRooms = 49
        visitedRooms = 1

Room.py

class Room(object):

    import Tile

    def __init__(self, floorx, floory, layout=[[0 for i in range(13)] for j in range(7)]):
        self.floorx = floorx
        self.floory = floory
        self.doors = [False, False, False, False]  # N,S,E,W
        for i in layout:
            for j in i:
                self.layout[i][j] = Tile.Tile(layout[i][j])

Tile.py

class Tile(object):

    def __init__(self, state):
        self.state = state

I have no idea what the problem could be at all. Thanks in advance

3
  • 1
    total overuse of classes Commented Jun 22, 2014 at 17:53
  • Please do not try to write Java in Python. Commented Jun 22, 2014 at 18:15
  • What do you mean Java in Python? Commented Jun 22, 2014 at 18:17

1 Answer 1

1

In Floor.py the import Room is a class attribute so, you have to use class object to access it. Try using....

import Room

class Floor(object):

    def __init__(self):
        # other code goes here ....
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot! I'm still pretty new to python

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.