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

Unified Diff: samples/pop_pop_win/lib/src/stage/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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « samples/pop_pop_win/lib/src/stage/score_element.dart ('k') | samples/pop_pop_win/lib/src/textures.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/stage/square_element.dart
diff --git a/samples/pop_pop_win/lib/src/stage/square_element.dart b/samples/pop_pop_win/lib/src/stage/square_element.dart
new file mode 100644
index 0000000000000000000000000000000000000000..82852af53f63b62d5cc5d265fd361bde94e3f5b2
--- /dev/null
+++ b/samples/pop_pop_win/lib/src/stage/square_element.dart
@@ -0,0 +1,104 @@
+library pop_pop_win.stage.square_element;
+
+import 'package:stagexl/stagexl.dart';
+
+import 'package:pop_pop_win/src/game.dart';
+import 'board_element.dart';
+import 'game_element.dart';
+
+class SquareElement extends Sprite {
+ static const int SIZE = 80;
+
+ static const List<String> _balloonBits = const [
+ 'balloon_pieces_a',
+ 'balloon_pieces_b',
+ 'balloon_pieces_c',
+ 'balloon_pieces_d'
+ ];
+
+ static const List<String> _numberMap = const [
+ "game_board_center",
+ "number_one", "number_two",
+ "number_three", "number_four",
+ "number_five", "number_six",
+ "number_seven", "number_eight"
+ ];
+
+ final int x, y;
+ final Bitmap _bitmap = new Bitmap(new BitmapData(SIZE, SIZE, true,
+ Color.Transparent));
+
+ SquareElement(this.x, this.y) {
+ addChild(_bitmap);
+
+ onMouseClick.listen(_onClick);
+ onMouseRightClick.listen(_onClick);
+
+ useHandCursor = true;
+ }
+
+ void updateState() {
+ var textureName;
+ switch (squareState) {
+ case SquareState.hidden:
+ textureName = _getHiddenTexture();
+ break;
+ case SquareState.flagged:
+ textureName = 'balloon_tagged_frozen';
+ break;
+ case SquareState.revealed:
+ textureName = _numberMap[_adjacentCount];
+ break;
+ case SquareState.bomb:
+ textureName = 'crater_b';
+ break;
+ case SquareState.safe:
+ textureName = 'balloon_tagged_bomb';
+ break;
+ }
+
+ useHandCursor = !_game.gameEnded && (squareState == SquareState.hidden ||
+ squareState == SquareState.flagged);
+
+ _bitmap.bitmapData
+ ..clear()
+ ..drawPixels(_opaqueAtlas.getBitmapData(textureName),
+ new Rectangle(0, 0, SIZE, SIZE), new Point(0, 0));
+ }
+
+ void _onClick(MouseEvent e) {
+ if (!_game.gameEnded) {
+ bool alt = (e.type == MouseEvent.RIGHT_CLICK) || e.shiftKey;
+ _gameElement.click(x, y, alt);
+ }
+ }
+
+ String toString() => 'Square at [$x, $y]';
+
+ String _getHiddenTexture() {
+ assert(squareState == SquareState.hidden);
+ if (_game.state == GameState.lost) {
+ useHandCursor = false;
+ final index = (x + y) % _balloonBits.length;
+ return _balloonBits[index];
+ } else {
+ useHandCursor = true;
+ return 'balloon';
+ }
+ }
+
+ SquareState get squareState => _game.getSquareState(x, y);
+
+ int get _adjacentCount => _game.field.getAdjacentCount(x, y);
+
+ BoardElement get _board {
+ final BoardElement p = this.parent;
+ return p;
+ }
+
+ GameElement get _gameElement => _board.gameElement;
+
+ TextureAtlas get _opaqueAtlas => _board.opaqueAtlas;
+
+ Game get _game => _board.game;
+}
« no previous file with comments | « samples/pop_pop_win/lib/src/stage/score_element.dart ('k') | samples/pop_pop_win/lib/src/textures.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698