| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 library pop_pop_win.audio; | |
| 5 | |
| 6 import 'dart:math'; | |
| 7 | |
| 8 import 'package:stagexl/stagexl.dart'; | |
| 9 | |
| 10 class GameAudio { | |
| 11 static final Random _rnd = new Random(); | |
| 12 | |
| 13 static ResourceManager _resourceManager; | |
| 14 | |
| 15 static const String _WIN = 'win', | |
| 16 _CLICK = 'click', | |
| 17 _POP = 'Pop', | |
| 18 _FLAG = 'flag', | |
| 19 _UNFLAG = 'unflag', | |
| 20 _BOMB = 'Bomb', | |
| 21 _THROW_DART = 'throw'; | |
| 22 | |
| 23 static void initialize(ResourceManager resourceManager) { | |
| 24 if (_resourceManager != null) throw new StateError('already initialized'); | |
| 25 _resourceManager = resourceManager; | |
| 26 } | |
| 27 | |
| 28 static void win() => _playAudio(_WIN); | |
| 29 | |
| 30 static void click() => _playAudio(_CLICK); | |
| 31 | |
| 32 static void pop() => _playAudio(_POP); | |
| 33 | |
| 34 static void flag() => _playAudio(_FLAG); | |
| 35 | |
| 36 static void unflag() => _playAudio(_UNFLAG); | |
| 37 | |
| 38 static void bomb() => _playAudio(_BOMB); | |
| 39 | |
| 40 static void throwDart() => _playAudio(_THROW_DART); | |
| 41 | |
| 42 static void _playAudio(String name) { | |
| 43 if (_resourceManager == null) throw new StateError('Not initialized'); | |
| 44 switch (name) { | |
| 45 case GameAudio._POP: | |
| 46 var i = _rnd.nextInt(8); | |
| 47 name = '${GameAudio._POP}$i'; | |
| 48 break; | |
| 49 case GameAudio._BOMB: | |
| 50 var i = _rnd.nextInt(4); | |
| 51 name = '${GameAudio._BOMB}$i'; | |
| 52 break; | |
| 53 } | |
| 54 _resourceManager.getSoundSprite('audio').play(name); | |
| 55 } | |
| 56 } | |
| OLD | NEW |