windows 10 Pro version : Python 3.8 (docker)
Don't skip the story of skipping the separation of state management files.
game.py
from status import Status
class Game():
def __init__():
self.status = Status.NOTHING
status.py
from enum import Enum, auto
class Status(Enum):
NOTHING = auto()
WAITING = auto()
PLAYING = auto()
class GameStatus():
def start():
if self.game.status == Status.NOTHING:
...
if self.game.status == Status.WAITING:
...
if self.game.status == Status.PLAYING:
...
It feels like changing the process depending on the status.
It feels like creating a Status as an enumeration and changing the States to WAITING or PLAYING according to the flow of the game in the initial state Status.NOTHING.
The Game class of game.py imports Status, but status.py does not import it because it has Status in the same file.
There is a discrepancy in the object IDs here, and only the Status.NOTHING
assigned by the init function has a different object ID, and equality comparison is not established.
It seems that the enum equivalent comparison refers to the object ID instead of the value.
Without skipping
gamestatus.py
from status import Status
class GameStatus():
def start():
if self.game.status == Status.NOTHING:
...
if self.game.status == Status.WAITING:
...
if self.game.status == Status.PLAYING:
...
status.py
from enum import Enum, auto
class Status(Enum):
NOTHING = auto()
WAITING = auto()
PLAYING = auto()
By dividing the file like that and following the procedure of importing when using all files, the difference in object ID depending on the presence or absence of import is not created.
Let's divide the file properly without skipping. .. .. ..
Recommended Posts