コード例 #1
0
ファイル: main.py プロジェクト: jjjesus/ArithmeBricks
class ArithmeBricksApp(App):

    def build(self):
        self.icon = 'icon.png'
        self.load_sounds()
        game = ArithmeBricksGame()
        Clock.schedule_once(lambda dt: game.show_title(), 1)
        return game

    def load_sounds(self):
        self.symbol_to_sound = QueryDict()
        sound_ids = list('0123456789') + list(SOUND_ID_TO_SYMBOL)
        for sound_id in sound_ids:
            filename = SOUND_FILENAME_PATTERN.format(sound_id)
            symbol = SOUND_ID_TO_SYMBOL.get(sound_id, sound_id)
            self.symbol_to_sound[symbol] = SoundLoader.load(filename)

    def play_sound(self, symbol, delay=None, volume=0.15):
        sound = self.symbol_to_sound.get(symbol)
        if sound is not None:
            def callback(dt):
                sound.volume = volume
                sound.play()
            if delay is None:
                delay = random.randint(0, 20) / 50
            Clock.schedule_once(callback, delay)
コード例 #2
0
class ArithmeBricksApp(App):
    def build(self):
        self.icon = 'icon.png'
        self.load_sounds()
        game = ArithmeBricksGame()
        Clock.schedule_once(lambda dt: game.show_title(), 1)
        return game

    def load_sounds(self):
        self.symbol_to_sound = QueryDict()
        sound_ids = list('0123456789') + list(SOUND_ID_TO_SYMBOL)
        for sound_id in sound_ids:
            filename = SOUND_FILENAME_PATTERN.format(sound_id)
            symbol = SOUND_ID_TO_SYMBOL.get(sound_id, sound_id)
            self.symbol_to_sound[symbol] = SoundLoader.load(filename)

    def play_sound(self, symbol, delay=None, volume=0.15):
        sound = self.symbol_to_sound.get(symbol)
        if sound is not None:

            def callback(dt):
                sound.volume = volume
                sound.play()

            if delay is None:
                delay = random.randint(0, 20) / 50
            Clock.schedule_once(callback, delay)
コード例 #3
0
ファイル: test_utils.py プロジェクト: robertour/kivy
 def test_QueryDict(self):
     qd = QueryDict()
     self.assertTrue(isinstance(qd, dict))
     # __setattr__
     qd.toto = 1
     self.assertEqual(qd.get('toto'), 1)
     # __getattr__
     toto = qd.toto 
     self.assertEqual(toto, 1)
コード例 #4
0
ファイル: test_utils.py プロジェクト: robertour/kivy
 def test_QueryDict(self):
     qd = QueryDict()
     self.assertTrue(isinstance(qd, dict))
     # __setattr__
     qd.toto = 1
     self.assertEqual(qd.get('toto'), 1)
     # __getattr__
     toto = qd.toto
     self.assertEqual(toto, 1)
コード例 #5
0
ファイル: test_utils.py プロジェクト: 13768324554/kivy
 def test_QueryDict(self):
     qd = QueryDict()
     self.assertTrue(isinstance(qd, dict))
     # __setattr__
     qd.toto = 1
     self.assertEqual(qd.get('toto'), 1)
     # __getattr__
     toto = qd.toto
     self.assertEqual(toto, 1)
     with self.assertRaises(AttributeError):
         foo = qd.not_an_attribute
コード例 #6
0
 def test_QueryDict(self):
     qd = QueryDict()
     self.assertTrue(isinstance(qd, dict))
     # __setattr__
     qd.toto = 1
     self.assertEqual(qd.get('toto'), 1)
     # __getattr__
     toto = qd.toto
     self.assertEqual(toto, 1)
     with self.assertRaises(AttributeError):
         foo = qd.not_an_attribute