Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(778)

Side by Side Diff: samples/pop_pop_win/lib/src/audio.dart

Issue 242443008: samples/pop_pop_win: now based on StageXL (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: tiny nit Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « samples/pop_pop_win/lib/pop_pop_win.dart ('k') | samples/pop_pop_win/lib/src/canvas.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 library pop_pop_win.audio;
2
3 import 'dart:math';
4
5 import 'package:stagexl/stagexl.dart';
6
7 class GameAudio {
8 static final Random _rnd = new Random();
9
10 static ResourceManager _resourceManager;
11
12 static const String _WIN = 'win',
13 _CLICK = 'click',
14 _POP = 'Pop',
15 _FLAG = 'flag',
16 _UNFLAG = 'unflag',
17 _BOMB = 'Bomb',
18 _THROW_DART = 'throw';
19
20 static void initialize(ResourceManager resourceManager) {
21 if (_resourceManager != null) throw new StateError('already initialized');
22 _resourceManager = resourceManager;
23 }
24
25 static void win() => _playAudio(_WIN);
26
27 static void click() => _playAudio(_CLICK);
28
29 static void pop() => _playAudio(_POP);
30
31 static void flag() => _playAudio(_FLAG);
32
33 static void unflag() => _playAudio(_UNFLAG);
34
35 static void bomb() => _playAudio(_BOMB);
36
37 static void throwDart() => _playAudio(_THROW_DART);
38
39 static void _playAudio(String name) {
40 if (_resourceManager == null) throw new StateError('Not initialized');
41 switch (name) {
42 case GameAudio._POP:
43 var i = _rnd.nextInt(8);
44 name = '${GameAudio._POP}$i';
45 break;
46 case GameAudio._BOMB:
47 var i = _rnd.nextInt(4);
48 name = '${GameAudio._BOMB}$i';
49 break;
50 }
51 _resourceManager.getSoundSprite('audio').play(name);
52 }
53 }
OLDNEW
« no previous file with comments | « samples/pop_pop_win/lib/pop_pop_win.dart ('k') | samples/pop_pop_win/lib/src/canvas.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698