| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 } |
| OLD | NEW |