Skip to content

Simple statefulness #6

@aaronschif

Description

@aaronschif

First way

class Game(object):
  def __init__(self):
    "setup"

  def is_done(self):
    pass

  def tick(self, dt):
    pass

while True:
  game = Game()
  while not game.is_done():
    game.tick()
    sleep(1)

More complex, more flexible way.

def game():
  not_done = True
  "setup"
  while not_done:
    "do some stuff"
    yield

while True:
  for _ in game:
    sleep(1)

The second one can be nested, like you can have states in states (easier in python 3).

I would suggest the first way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions