Browse files

Add mosquito to the bench

  • Loading branch information...
1 parent a005def commit 9111c570e21c3e139d3fb9790a4b9ba4e35ab6b9 @chellmuth committed Jan 13, 2014
Showing with 19 additions and 6 deletions.
  1. +13 −5 lib/bench.dart
  2. +5 −0 lib/parser.dart
  3. +1 −1 web/hive.dart
View
18 lib/bench.dart
@@ -3,8 +3,15 @@ part of view;
class Bench {
static num height = 260;
+ List<Bug> expansionBugs;
String player1, player2;
- Bench(this.player1, this.player2);
+ Bench(this.expansionBugs, this.player1, this.player2);
+
+ List<Bug> get bugs {
+ var baseBugs = [ Bug.ANT, Bug.GRASSHOPPER, Bug.SPIDER, Bug.BEETLE, Bug.QUEEN ];
+ baseBugs.addAll(this.expansionBugs);
+ return baseBugs;
+ }
void draw(CanvasRenderingContext2D context, CanvasElement canvas, GameState gamestate) {
context.save();
@@ -14,9 +21,11 @@ class Bench {
context.fillStyle = 'rgba(236, 217, 176, .95)';
var widthRatio = .5;
- var left = canvas.width * (1 - widthRatio) / 2;
+ var extraWidth = expansionBugs.length * 260;
+
+ var left = canvas.width * (1 - widthRatio) / 2 - extraWidth / 2;
var top = canvas.height - height;
- var width = canvas.width * widthRatio;
+ var width = canvas.width * widthRatio + extraWidth;
context.beginPath();
context.rect(left, top, width, height + 1);
context.fill();
@@ -46,13 +55,12 @@ class Bench {
var totalBugWidth = 0;
var assetRatio = 3/4;
- var bugs = [ Bug.ANT, Bug.GRASSHOPPER, Bug.SPIDER, Bug.BEETLE, Bug.QUEEN ];
for (var bug in bugs) {
ImageElement asset = AssetLibrary.imageForPiece(new Piece(player, bug, 0));
totalBugWidth += asset.naturalWidth * assetRatio;
}
var xOrigin = (bounds.width - totalBugWidth) / 2 + bounds.left;
- for (var i = 0; i < 5; i++) {
+ for (var i = 0; i < bugs.length; i++) {
var count = benchPieces[bugs[i]];
if (count == 0) { continue; }
ImageElement asset = AssetLibrary.imageForPiece(new Piece(player, bugs[i], 0));
View
5 lib/parser.dart
@@ -13,6 +13,8 @@ class ParsedGame {
bool valid = true;
List<String> errors = [];
+
+ List<Bug> expansionBugs = [];
}
class SGF {
@@ -40,6 +42,9 @@ class SGF {
game.errors.add("Ultimate");
game.valid = false;
} else {
+ if (gameType.contains("m")) {
+ game.expansionBugs.add(Bug.MOSQUITO);
+ }
if (gameType.contains("l")) {
game.errors.add("Ladybug");
game.valid = false;
View
2 web/hive.dart
@@ -161,7 +161,7 @@ void setupSGF(String sgf, GameState gamestate) {
window.alert("Game type${plural} not supported: ${gameType}");
return;
}
- bench = new Bench(parsedGame.player1, parsedGame.player2);
+ bench = new Bench(parsedGame.expansionBugs, parsedGame.player1, parsedGame.player2);
selectionState.clear();
gamestate.initialize(parsedGame.gameEvents);
gamestate.step(1);

0 comments on commit 9111c57

Please sign in to comment.