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

Unified Diff: samples/pop_pop_win/lib/src/game/field.dart

Issue 786443002: Delete pop-pop-win from the repo (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « samples/pop_pop_win/lib/src/game.dart ('k') | samples/pop_pop_win/lib/src/game/game.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samples/pop_pop_win/lib/src/game/field.dart
diff --git a/samples/pop_pop_win/lib/src/game/field.dart b/samples/pop_pop_win/lib/src/game/field.dart
deleted file mode 100644
index 8d301a27919d49c0b7b83444df9c92eb2448871a..0000000000000000000000000000000000000000
--- a/samples/pop_pop_win/lib/src/game/field.dart
+++ /dev/null
@@ -1,89 +0,0 @@
-// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-part of pop_pop_win.game;
-
-class Field extends Array2d<bool> {
- final int bombCount;
- final Array2d<int> _adjacents;
-
- factory Field([int bombCount = 40, int cols = 16, int rows = 16,
- int seed = null]) {
- var squares = new List<bool>.filled(rows * cols, false);
- assert(bombCount < squares.length);
- assert(bombCount > 0);
-
- var rnd = new Random(seed);
-
- // This is the most simple code, but it'll get slow as
- // bombCount approaches the square count.
- // But more efficient if bombCount << square count
- // which is expected.
- for (int i = 0; i < bombCount; i++) {
- int index;
- do {
- index = rnd.nextInt(squares.length);
- } while (squares[index]);
- squares[index] = true;
- }
-
- return new Field._internal(bombCount, cols,
- new UnmodifiableListView<bool>(squares));
- }
-
- factory Field.fromSquares(int cols, int rows, List<bool> squares) {
- assert(cols > 0);
- assert(rows > 0);
- assert(squares.length == cols * rows);
-
- int count = 0;
- for (final m in squares) {
- if (m) {
- count++;
- }
- }
- assert(count > 0);
- assert(count < squares.length);
-
- return new Field._internal(count, cols,
- new UnmodifiableListView<bool>(squares));
- }
-
- Field._internal(this.bombCount, int cols, UnmodifiableListView<bool> source)
- : this._adjacents = new Array2d<int>(cols, source.length ~/ cols),
- super.wrap(cols, source.toList()) {
- assert(width > 0);
- assert(height > 0);
- assert(bombCount > 0);
- assert(bombCount < length);
-
- int count = 0;
- for (var m in this) {
- if (m) {
- count++;
- }
- }
- assert(count == bombCount);
- }
-
- int getAdjacentCount(int x, int y) {
- if (get(x, y)) {
- return null;
- }
-
- int val = _adjacents.get(x, y);
-
- if (val == null) {
- val = 0;
- for (var i in getAdjacentIndices(x, y)) {
- if (this[i]) {
- val++;
- }
- }
- _adjacents.set(x, y, val);
- }
- return val;
- }
-
- String toString() => 'w${width}h${height}m${bombCount}';
-}
« no previous file with comments | « samples/pop_pop_win/lib/src/game.dart ('k') | samples/pop_pop_win/lib/src/game/game.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698