Browse files

rename cell to entity

  • Loading branch information...
1 parent dfc5a18 commit 555dc3eed53f7184425a64979e917a1d207cb497 @Rob-ot Rob-ot committed Mar 26, 2012
Showing with 93 additions and 22 deletions.
  1. +9 −9 public/css/main.css
  2. +1 −1 public/css/main.less
  3. +1 −0 public/views/Entity.html
  4. +51 −0 public/views/Entity.js
  5. +19 −0 public/views/Entity.less
  6. +12 −12 public/views/GameBoard.js
View
18 public/css/main.css
@@ -11,23 +11,23 @@
top: 0;
width: 75%;
}
-.cell {
+.entity {
background: no-repeat center center;
background-size: auto 90%;
position: absolute;
- -webkit-transition: all 1s linear;
- -moz-transition: all 1s linear;
- -ms-transition: all 1s linear;
- -o-transition: all 1s linear;
- transition: all 1s linear;
+ -webkit-transition: all 250ms linear;
+ -moz-transition: all 250ms linear;
+ -ms-transition: all 250ms linear;
+ -o-transition: all 250ms linear;
+ transition: all 250ms linear;
}
-.cell.mine {
+.entity.mine {
background-image: url("/img/mine.png");
}
-.cell.finish {
+.entity.finish {
background-image: url("/img/finish_flag.png");
}
-.cell.player {
+.entity.player {
background-image: url("/img/blue_robot.png");
}
.selection {
View
2 public/css/main.less
@@ -3,6 +3,6 @@
@import "lib";
@import "../views/GameBoard";
-@import "../views/Cell";
+@import "../views/Entity";
@import "../views/Selection";
@import "../views/SelectionItem";
View
1 public/views/Entity.html
@@ -0,0 +1 @@
+<article class="entity"></article>
View
51 public/views/Entity.js
@@ -0,0 +1,51 @@
+define( [ "views/View"
+ , "text!views/Entity.html"
+ ],
+
+function (View
+ , template
+ ) {
+
+ return View.extend({
+ template: template,
+
+ initialize: function (model, type) {
+ this.model = model
+ this.type = type
+
+ this.$el.addClass(type)
+
+
+
+ this.render()
+ },
+
+ render: function () {
+ if (!this.scale) return
+ this.$el.css({
+ left: (this.model.x * this.scale) + "px",
+ top: this.model.y * this.scale,
+ width: this.scale,
+ height: this.scale
+ })
+ },
+
+ updateModel: function (model) {
+ this.model = model
+ this.render()
+ },
+
+ getX: function () {
+ return this.x
+ },
+
+ getY: function () {
+ return this.y
+ },
+
+ setScale: function (scale) {
+ this.scale = scale
+ this.render()
+ }
+ })
+})
View
19 public/views/Entity.less
@@ -0,0 +1,19 @@
+.entity {
+ background: no-repeat center center;
+ background-size: auto 90%;
+ position: absolute;
+
+ .transition(all 250ms linear);
+
+ &.mine {
+ background-image: url("/img/mine.png");
+ }
+
+ &.finish {
+ background-image: url("/img/finish_flag.png");
+ }
+
+ &.player {
+ background-image: url("/img/blue_robot.png");
+ }
+}
View
24 public/views/GameBoard.js
@@ -1,13 +1,13 @@
define( [ "underscore"
, "views/View"
, "text!views/GameBoard.html"
- , "views/Cell"
+ , "views/Entity"
],
function (_
, View
, template
- , CellView
+ , EntityView
) {
return View.extend({
@@ -41,25 +41,25 @@ function (_
},
addEntity: function (type, entityModel) {
- var entity = new CellView(entityModel, type)
+ var entity = new EntityView(entityModel, type)
this.$el.append(entity.$el)
entity.setScale(this.scale)
this.entitiesById[entityModel.id] = entity
- this.cells.push(entity)
+ this.entities.push(entity)
},
- updateCellScales: function () {
- for (var i = 0; i < this.cells.length; i++) {
- this.cells[i].setScale(this.scale)
+ updateEntityScales: function () {
+ for (var i = 0; i < this.entities.length; i++) {
+ this.entities[i].setScale(this.scale)
}
},
resize: function () {
if (!this.model) return
this.calculateScale()
- this.updateCellScales()
+ this.updateEntityScales()
this.render()
},
@@ -105,13 +105,13 @@ function (_
reset: function () {
this.stop()
- if (this.cells) {
- for (var i = 0; i < this.cells.length; i++) {
- this.cells[i].destroy()
+ if (this.entities) {
+ for (var i = 0; i < this.entities.length; i++) {
+ this.entities[i].destroy()
}
}
- this.cells = []
+ this.entities = []
this.currentTurn = 0
this.entitiesById = {}
}

0 comments on commit 555dc3e

Please sign in to comment.