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

Side by Side Diff: samples/pop_pop_win/lib/src/canvas/square_element.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
OLDNEW
(Empty)
1 part of pop_pop_win.canvas;
2
3 class SquareElement extends Thing {
4 static const int _size = 80;
5
6 static const List<String> _balloonBits = const['balloon_pieces_a.png',
7 'balloon_pieces_b.png',
8 'balloon_pieces_c.png',
9 'balloon_pieces_d.png'];
10
11 static const List<String> _numberMap = const["game_board_center",
12 "number_one", "number_two",
13 "number_three", "number_four",
14 "number_five", "number_six",
15 "number_seven", "number_eight"];
16
17 final int x, y;
18
19 SquareState _lastDrawingState;
20
21 SquareElement(this.x, this.y): super(_size, _size) {
22 MouseManager.setClickable(this, true);
23 }
24
25 void update() {
26 if (_lastDrawingState != _squareState) {
27 _lastDrawingState = _squareState;
28 invalidateDraw();
29 }
30 }
31
32 void drawOverride(CanvasRenderingContext2D ctx) {
33 var textureName;
34 switch (_lastDrawingState) {
35 case SquareState.hidden:
36 textureName = _getHiddenTexture();
37 break;
38 case SquareState.flagged:
39 textureName = 'balloon_tagged_frozen.png';
40 break;
41 case SquareState.revealed:
42 final prefix = _numberMap[_adjacentCount];
43 textureName = '$prefix.png';
44 break;
45 case SquareState.bomb:
46 textureName = 'crater_b.png';
47 break;
48 case SquareState.safe:
49 textureName = 'balloon_tagged_bomb.png';
50 break;
51 }
52
53 _textureData.drawTextureKeyAt(ctx, textureName);
54 }
55
56 String toString() => 'Square at [$x, $y]';
57
58 String _getHiddenTexture() {
59 assert(_lastDrawingState == SquareState.hidden);
60 if (_game.state == GameState.lost) {
61 final index = (x + y) % _balloonBits.length;
62 return _balloonBits[index];
63 } else {
64 return 'balloon.png';
65 }
66 }
67
68 SquareState get _squareState => _game.getSquareState(x, y);
69
70 int get _adjacentCount => _game.field.getAdjacentCount(x, y);
71
72 BoardElement get _board {
73 final BoardElement p = this.parent;
74 return p;
75 }
76
77 TextureData get _textureData => _board._textureData;
78
79 Game get _game => _board._game;
80 }
OLDNEW
« no previous file with comments | « samples/pop_pop_win/lib/src/canvas/score_element.dart ('k') | samples/pop_pop_win/lib/src/canvas/title_element.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698