when i run my program i want it to run start_game(self)
. For that, the constructor has to be run. Without that, the objects don't exist and therefore their methods can't be run. So far, so clear. Basically, i struggle to correctly "start" that process.
from Surface import Surface
from Pellet import Pellet
from Pacman import Pacman
from Ghost import Ghost
from Timer import Timer
class Controls:
def __init__(self):
global the_surface
the_surface = Surface(self)
the_pellets = []
for y in range(0, 8):
for x in range(0, 14):
pellet = Pellet(x, y)
the_pellets.append(pellet)
global the_pacman
the_pacman = Pacman(the_pellets)
the_ghosts = []
for ghost in range(0, 3):
the_ghosts.append(Ghost())
global the_timer
the_timer = Timer(self, 200)
# [...]
def start_game(self):
self.__init_game_objects()
Timer.start(the_timer)
return
def tick_timer(self):
Pacman.move(the_pacman)
return
# http://stackoverflow.com/a/419185
if __name__ == '__main__':
# need to run start_game()
What I've tried (all of the following is after the if __name__ [...]
line, every bullet point represents one trial.)
first attempt:
the_controls = Controls()
the_controls.start_game(the_controls)
Traceback (most recent call last):
File "Controls.py", line 8, in <module>
class Controls:
File "Controls.py", line 53, in Controls
the_controls = Controls()
NameError: name 'Controls' is not defined
second attempt:
__init__('Controls')
self.start_game(self)
Traceback (most recent call last):
File "Controls.py", line 8, in <module>
class Controls:
File "Controls.py", line 54, in Controls
self.start_game(self)
NameError: name 'self' is not defined
third attempt(as suggested by @TigerhawkT3)
the_controls = Controls()
the_controls.start_game()
Traceback (most recent call last):
File "Controls.py", line 8, in <module>
class Controls:
File "Controls.py", line 53, in Controls
the_controls = Controls()
NameError: name 'Controls' is not defined