Chromium Code Reviews| 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..e817c66a6aa714764e61dd02b84b143199f4c5ae |
| --- /dev/null |
| +++ b/samples/pop_pop_win/lib/src/stage/square_element.dart |
| @@ -0,0 +1,97 @@ |
| +library pop_pop_win.stage.square_element; |
| + |
| +import 'package:stagexl/stagexl.dart'; |
| + |
| +import '../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', |
|
Siggi Cherem (dart-lang)
2014/04/21 22:00:56
it might be the editor doing this kind of indentat
kevmoo
2014/04/21 22:22:54
Done.
|
| + 'balloon_pieces_c', |
| + 'balloon_pieces_d']; |
| + |
| + static const List<String> _numberMap = const["game_board_center", |
| + "number_one", "number_two", |
|
Siggi Cherem (dart-lang)
2014/04/21 22:00:56
ditto
kevmoo
2014/04/21 22:22:54
Done.
|
| + "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.hidden, SquareState.flagged].contains(squareState); |
|
Siggi Cherem (dart-lang)
2014/04/21 22:00:56
80 ...
kevmoo
2014/04/21 22:22:54
Done.
|
| + |
| + _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; |
| +} |