2014-06-22 107 views
0

我正在嘗試創建一個地下城開發程序,並且我使用了許多模塊。我有一個主模塊,一個地板模塊,一個房間模塊和一個瓷磚模塊。地板是瓷磚網格的房間。在我的地板組件,我導入室,這樣我可以儲藏室的二維列表,但我不斷收到錯誤:在Python中導入模塊時遇到問題

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 

我的代碼如下。

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 

我不知道是什麼問題,可能是在所有。在此先感謝

+1

總體過度使用類 – EL3PHANTEN

+0

請不要嘗試在Python中編寫Java。 –

+0

Python是什麼意思? – Rishabh2

回答

1

Floor.pyimport Roomclass屬性,所以,你必須使用類對象來訪問它。嘗試使用....

import Room 

class Floor(object): 

    def __init__(self): 
     # other code goes here .... 
+1

非常感謝!我對python仍然很陌生 – Rishabh2