Была неправильная структура файла, получался перекрестный импорт
Исправленный код:
game.py
from funcs import *
from classes import *
import sys
try:
curscreen=screen1
except:
pass
try:
while 1:
curscreen.show()
curscreen.execute()
if curscreen.newScreen!=None:
curscreen=curscreen.newScreen
except (NameError,AttributeError) as e:
print(e)
funcs.py
from classes import *
import sys
def StartGame():
return StartGameScreen
def Settings():
return SettingsScreen
def Quit():
sys.exit()
def NewGame():
pass
def LoadGame():
pass
def DeleteGame():
pass
NewGameButton=button('Новая игра',NewGame)
LoadGameButton=button('Загрузить',LoadGame)
DeleteGameButton=button('Удалить запись',DeleteGame)
StartGameScreen=screen({'1':NewGameButton,
'2':LoadGameButton,
'3':DeleteGameButton})
StartGameButton=button('Начать игру',StartGame)
SettingsButton=button('Настройки',Settings)
QuitButton=button('Выйти из игры',Quit)
screen1=screen({'1':StartGameButton,'2':SettingsButton,'3':QuitButton})
classes.py
class screen:
def __init__(self,elements):
self.elements=elements
def show(self):
for element in self.elements:
self.elements[element].show()
def execute(self):
for element in self.elements:
if self.elements[element].executable:
self.elements[element].execute()
command = input()
newScreen=self.elements[command].action()
if newScreen!=None:
self.newScreen=newScreen
class button:
def __init__(self,text,action):
self.executable=False
self.text=text
self.action=action
def show(self):
print(self.text)
class mission:
def __init__(self,structure,actions):
self.structure=structure
self.actions=actions