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

Side by Side Diff: sky/sdk/example/mine_digger/lib/main.dart

Issue 1217093005: Refactor stateful parts of Component into StatefulComponent (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: rebase Created 5 years, 5 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
« no previous file with comments | « no previous file | sky/sdk/example/stocks/lib/stock_home.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 import 'dart:sky' as sky; 5 import 'dart:sky' as sky;
6 import 'dart:math'; 6 import 'dart:math';
7 7
8 import 'package:sky/rendering/flex.dart'; 8 import 'package:sky/rendering/flex.dart';
9 import 'package:sky/widgets/basic.dart'; 9 import 'package:sky/widgets/basic.dart';
10 import 'package:sky/widgets/scaffold.dart'; 10 import 'package:sky/widgets/scaffold.dart';
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 toolbar: buildToolBar(), 178 toolbar: buildToolBar(),
179 body: new Container( 179 body: new Container(
180 child: new Center(child: board), 180 child: new Center(child: board),
181 decoration: new BoxDecoration(backgroundColor: colors.Grey[50]) 181 decoration: new BoxDecoration(backgroundColor: colors.Grey[50])
182 ) 182 )
183 ); 183 );
184 } 184 }
185 185
186 void handleBannerPointerDown(sky.PointerEvent event) { 186 void handleBannerPointerDown(sky.PointerEvent event) {
187 initialize(); 187 initialize();
188 app.setState((){}); 188 app.scheduleBuild();
189 } 189 }
190 190
191 // User action. The user uncovers the cell which can cause losing the game. 191 // User action. The user uncovers the cell which can cause losing the game.
192 void probe(int x, int y) { 192 void probe(int x, int y) {
193 if (!alive) 193 if (!alive)
194 return; 194 return;
195 if (uiState[y][x] == flaggedCell) 195 if (uiState[y][x] == flaggedCell)
196 return; 196 return;
197 // Allowed to probe. 197 // Allowed to probe.
198 if (cells[y][x]) { 198 if (cells[y][x]) {
199 // Probed on a mine --> dead!! 199 // Probed on a mine --> dead!!
200 uiState[y][x] = explodedCell; 200 uiState[y][x] = explodedCell;
201 alive = false; 201 alive = false;
202 } else { 202 } else {
203 // No mine, uncover nearby if possible. 203 // No mine, uncover nearby if possible.
204 cull(x, y); 204 cull(x, y);
205 } 205 }
206 app.setState((){}); 206 app.scheduleBuild();
207 } 207 }
208 208
209 // User action. The user is sure a mine is at this location. 209 // User action. The user is sure a mine is at this location.
210 void flag(int x, int y) { 210 void flag(int x, int y) {
211 if (uiState[y][x] == flaggedCell) { 211 if (uiState[y][x] == flaggedCell) {
212 uiState[y][x] = coveredCell; 212 uiState[y][x] = coveredCell;
213 --detectedCount; 213 --detectedCount;
214 } else { 214 } else {
215 uiState[y][x] = flaggedCell; 215 uiState[y][x] = flaggedCell;
216 ++detectedCount; 216 ++detectedCount;
217 } 217 }
218 app.setState((){}); 218 app.scheduleBuild();
219 } 219 }
220 220
221 // Recursively uncovers cells whose totalMineCount is zero. 221 // Recursively uncovers cells whose totalMineCount is zero.
222 void cull(int x, int y) { 222 void cull(int x, int y) {
223 if ((x < 0) || (x > rows - 1)) 223 if ((x < 0) || (x > rows - 1))
224 return; 224 return;
225 if ((y < 0) || (y > cols - 1)) 225 if ((y < 0) || (y > cols - 1))
226 return; 226 return;
227 227
228 if (uiState[y][x] == clearedCell) 228 if (uiState[y][x] == clearedCell)
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 } 363 }
364 364
365 Widget build() { 365 Widget build() {
366 return game.buildUI(); 366 return game.buildUI();
367 } 367 }
368 } 368 }
369 369
370 void main() { 370 void main() {
371 runApp(new MineDiggerApp()); 371 runApp(new MineDiggerApp());
372 } 372 }
OLDNEW
« no previous file with comments | « no previous file | sky/sdk/example/stocks/lib/stock_home.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698