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

Side by Side Diff: samples/pop_pop_win/lib/src/html/game_view.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.html;
2
3 class GameView extends GameManager {
4 static const String _xKey = 'x';
5 static const String _yKey = 'y';
6
7 final TableElement _table;
8 final Element _leftCountDiv;
9 final Element _gameStateDiv;
10 final Element _clockDiv;
11
12 GameView(int width, int height, int bombCount,
13 this._table, this._leftCountDiv, this._gameStateDiv,
14 this._clockDiv) : super(width, height, bombCount);
15
16 void updateElement() {
17 updateClock();
18 _gameStateDiv.innerHtml = game.state.name;
19 _leftCountDiv.innerHtml = game.bombsLeft.toString();
20
21 if(_table.children.length == 0) {
22
23 for(int r = 0; r < game.field.height; r++) {
24 TableRowElement row = _table.insertRow(-1);
25
26 for(int c = 0; c < game.field.width; c++) {
27 TableCellElement cell = row.insertCell(-1);
28 cell.onMouseDown.listen(_cellClick);
29 cell.dataset[_xKey] = c.toString();
30 cell.dataset[_yKey] = r.toString();
31 }
32 }
33 }
34
35 for(int r = 0; r < game.field.height; r++) {
36 for(int c = 0; c < game.field.width; c++) {
37 TableRowElement row = _table.rows[r];
38 TableCellElement cell = row.cells[c];
39
40 cell.classes.clear();
41 cell.classes.add('game-square');
42 final ss = game.getSquareState(c, r);
43 cell.classes.add(ss.name);
44 if(ss == SquareState.revealed) {
45 final adj = game.field.getAdjacentCount(c, r);
46 assert(adj != null);
47 if(adj > 0) {
48 cell.innerHtml = adj.toString();
49 }
50 }
51 }
52 }
53
54 }
55
56 void newGame() {
57 super.newGame();
58 _table.children.clear();
59 updateElement();
60 }
61
62 void updateClock() {
63 if(game.duration == null) {
64 _clockDiv.innerHtml = '';
65 } else {
66 _clockDiv.innerHtml = game.duration.inSeconds.toString();
67 }
68
69 super.updateClock();
70 }
71
72 void _cellClick(MouseEvent args) {
73 if(args.button == 0 && _canClick) {
74 final TableCellElement cell = args.currentTarget;
75 final xStr = cell.dataset[_xKey];
76 final yStr = cell.dataset[_yKey];
77
78 final x = int.parse(xStr);
79 final y = int.parse(yStr);
80 _click(x, y, args.shiftKey);
81 }
82 }
83
84 void gameUpdated(args) {
85 updateElement();
86 }
87 }
OLDNEW
« no previous file with comments | « samples/pop_pop_win/lib/src/html/game_storage.dart ('k') | samples/pop_pop_win/lib/src/html/high_score_view.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698