Skip to content

Commit

Permalink
modifications to allow more games
Browse files Browse the repository at this point in the history
  • Loading branch information
marianoguerra committed Jun 1, 2010
1 parent 434288d commit 1930397
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions mof.py
Expand Up @@ -23,6 +23,11 @@ def load_image(name, base='imgs'):
return image, image.get_rect()


def random_note():
'''generate a random note'''
return Note(random.randint(8, 20), random.randint(0, 3))


class Note(object):
'''representation of a note'''

Expand All @@ -42,11 +47,6 @@ def __init__(self, note, shape, accidental=None):
else:
self.accidental = accidental

@classmethod
def random(cls):
'''generate a random note'''
return Note(random.randint(8, 20), random.randint(0, 3))

class Staff(object):
'''a surface that holds notes'''

Expand Down Expand Up @@ -126,6 +126,21 @@ def __init__(self):
self.background = pygame.Surface(self.screen.get_size())
self.background = self.background.convert()

def run(self, GameClass):
'''loop until we have to quit on user action'''
game = GameClass(self.screen, self.background)

do_quit = False

while not do_quit:
do_quit = game.step()


class HitTheKeyGame(object):

def __init__(self, screen, background):
self.screen = screen
self.background = background
self.gstaff = Staff(y=80)
self.fstaff = Staff(y=300, clef='f')
self.new_note()
Expand All @@ -147,7 +162,7 @@ def new_note(self):
staffs'''

self.staff = random.choice(['f', 'g'])
self.last_note = Note.random()
self.last_note = random_note()
self.last_pos = random.randint(0, 6)

def step(self):
Expand Down Expand Up @@ -184,13 +199,6 @@ def step(self):

return False

def run(self):
'''loop until we have to quit on user action'''
do_quit = False

while not do_quit:
do_quit = self.step()

def draw_note(self):
'''draw a random note on one of the staffs'''

Expand All @@ -216,4 +224,4 @@ def show_count(self):
self.background.blit(text, textpos)

if __name__ == '__main__':
Game().run()
Game().run(HitTheKeyGame)

0 comments on commit 1930397

Please sign in to comment.