Exemplo n.º 1
0
class FrutrisGame:

    def __init__(self):
        config.FRAME = Rect(250, 10, 640, 512)
        self.game = Game()
        self.level_counter = LEVEL_COUNTER_INIT
        play_effect('frutris')
        self.frutris_box = FrutrisBox(self.game, LEVEL)
        # frame = Frame(self.screen, Rect(660, 220, 200, 200))
        self.data = {
            'score': 0,
            'level': 1,
        }
        self.status_box = self.create_status_box()

        # Music
        self.music_counter = 50  # periodically check for expiring track
        self.current_music = ('a', 1)
        self.music = MusicPlayer()
        self.music.play_music('/home/krother/projects/frutris/frutris/music/a1.ogg')


    def choose_next_music(self):
        MUSIC = '/home/krother/projects/frutris/frutris/music/{}{}.ogg'
        LETTERS = 'aaaabbbbcccccccc'
        letter, number = self.current_music
        number = 3 - number
        stack_size = self.frutris_box.level.get_stack_size()
        letter = LETTERS[stack_size]
        #if len(self.players) >= 1:
        #    stack_size = self.players[0].get_stack_size()
        self.current_music = (letter, number)
        next_track = MUSIC.format(letter, number)
        print('NEXT TRACK: ', next_track)
        return next_track

    def update_music(self):
        self.music_counter -= 1
        if self.music_counter == 0:
            self.music_counter = 50
            if self.music.check_music_status() == CLOSE_TO_END:
                next_track = self.choose_next_music()
                self.music.next_music(next_track)

    def update_level(self):
        self.level_counter -= 1
        if self.level_counter == 0:
            self.data['level'] += 1
            self.level_counter = LEVEL_COUNTER_INIT
            self.frutris_box.make_blocks_drop_faster()

    @property
    def score(self):
        return self.data['score']

    def create_status_box(self):
        frame = Frame(self.game.screen, Rect(660, 20, 200, 200))
        return DictBox(frame, self.data)

    def draw(self):
        self.data['score'] += self.frutris_box.counter.pull_score()
        self.frutris_box.draw()
        self.status_box.draw()
        if self.frutris_box.game_over:
            self.game.exit()
        self.update_level()
        self.update_music()

    def run(self):
        self.game.event_loop(figure_moves=self.frutris_box.store_command, draw_func=self.draw)
Exemplo n.º 2
0
class FrutrisGame:

    def __init__(self, screen):
        self.level_counter = 1
        play_effect('frutris')
        self.screen = screen
        screen.clear()
        self.frame = Frame(self.screen, Rect(10, 10, 640, 512))
        self.tile_factory = TileFactory('data/tiles.conf')
        self.events = None
        self.frutris_box = FrutrisBox(self.frame, self.tile_factory, LEVEL)
        # frame = Frame(self.screen, Rect(660, 220, 200, 200))
        self.data = {
            'score': 0,
            'level': 1,
        }
        self.status_box = self.create_status_box()

        # Music
        self.music_counter = 50 # periodically check for expiring track
        self.current_music = ('a', 1)
        self.music = MusicPlayer()
        self.music.play_music('/home/krother/projects/frutris/frutris/music/a1.ogg')


    def choose_next_music(self):
        MUSIC = '/home/krother/projects/frutris/frutris/music/{}{}.ogg'
        LETTERS = 'aaaabbbbcccccccc'
        letter, number = self.current_music
        number = 3 - number
        stack_size = self.frutris_box.level.get_stack_size()
        letter = LETTERS[stack_size]
        #if len(self.players) >= 1:
        #    stack_size = self.players[0].get_stack_size()
        self.current_music = (letter, number)
        next_track = MUSIC.format(letter, number)
        print('NEXT TRACK: ', next_track)
        return next_track

    def update_music(self):
        self.music_counter -= 1
        if self.music_counter == 0:
            self.music_counter = 50
            if self.music.check_music_status() == CLOSE_TO_END:
                next_track = self.choose_next_music()
                self.music.next_music(next_track)

    @property
    def score(self):
        return self.data['score']

    def create_status_box(self):
        frame = Frame(self.screen, Rect(660, 20, 200, 200))
        return DictBox(frame, self.data)

    def draw(self):
        self.data['score'] += self.frutris_box.counter.pull_score()
        self.frutris_box.draw()
        self.status_box.draw()
        if self.frutris_box.game_over:
            self.events.exit_signalled()
        self.update_music()

    def run(self):
        self.events = EventGenerator()
        self.events.add_listener(FigureMoveListener(self.frutris_box.store_command))
        self.events.add_listener(ExitListener(self.events.exit_signalled))
        with draw_timer(self, self.events):
            self.events.event_loop()