Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add damage display

  • Loading branch information...
commit c5addc69da196fae84d61ec2fdb9636da9032724 1 parent 33993d6
nicholasvan nicholasvan authored

Showing 4 changed files with 126 additions and 28 deletions. Show diff stats Hide diff stats

  1. +76 17 board.js
  2. +2 1  dm.js
  3. +23 6 game.js
  4. +25 4 gem.js
93 board.js
@@ -28,13 +28,20 @@ dm.Board = function(rows,cols,game) {
28 28 * @const
29 29 * @type {number}
30 30 */
31   -
32   - this.SIZE = 690;
  31 +
  32 + this.SIZE = dm.BOARDSIZE;
33 33
34 34 this.rows = rows;
35 35 this.cols = cols;
36 36 this.gems = new Array(cols);
37 37
  38 + //用于显示的数值
  39 +
  40 + this.fp = this.game.user.fp;
  41 + this.show_att = this.fp.a1;
  42 + this.show_dmg = 0;
  43 +
  44 + //
38 45 this.setSize(this.SIZE, this.SIZE).setAnchorPoint(0, 0);
39 46
40 47 // mask out edges so bubbles flowing in won't be over game controls.
@@ -114,7 +121,7 @@ dm.Board.prototype.fillGems = function() {
114 121 this.layers[c].appendChild(gem);
115 122 }
116 123 }
117   -
  124 + this.show_dmg = this.getDamage();
118 125 };
119 126
120 127 /**
@@ -166,6 +173,9 @@ dm.Board.prototype.randExtra = function(basev,randratio,baseadd,ratio) {
166 173 }
167 174 return 0;
168 175 }
  176 +
  177 +
  178 +
169 179 /**
170 180 * 计算分数
171 181 */
@@ -178,8 +188,6 @@ dm.Board.prototype.checkSolutions = function() {
178 188 ).enableOptimizations();
179 189
180 190
181   - var indexes = [];
182   -
183 191 var s = this.selectedGems,g,type,i
184 192 ,fp = this.game.user.fp,keep
185 193 ,attack = fp.a1
@@ -188,6 +196,8 @@ dm.Board.prototype.checkSolutions = function() {
188 196 ,exp = 0
189 197 ,blood = 0
190 198 ,p_type = [];
  199 +
  200 + var indexes = 1;
191 201
192 202 //计算攻击力
193 203 for(i = 0; i < s.length; i++){
@@ -195,7 +205,7 @@ dm.Board.prototype.checkSolutions = function() {
195 205 //计算经验
196 206 if(type == 'sword'){
197 207 attack += fp.a2
198   - }else if(type != 'monstor'){
  208 + }else if(type != 'monster'){
199 209 g = 1;
200 210 break;
201 211 }
@@ -206,10 +216,10 @@ dm.Board.prototype.checkSolutions = function() {
206 216 g = s[i]
207 217 type = g.type
208 218 s[i].keep = false;
209   - if(type == 'monstor'){
  219 + if(type == 'monster'){
210 220 if(attack >= g.hp ){
211 221 g.hp = 0;
212   - exp += fp.a23
  222 + exp += fp.a23;
213 223 if(i > 2){
214 224 exp += this.randExtra(fp.a24,fp.a25,fp.a26,fp.a27)
215 225 }
@@ -274,13 +284,15 @@ dm.Board.prototype.checkSolutions = function() {
274 284 }
275 285 }
276 286
277   - this.game.setScore(solutions.length * indexes.length);
278   - //计算剩余防御和hp
  287 + this.game.setScore(solutions.length * (solutions.length - 2));
  288 +
  289 +//计算剩余防御和hp
279 290 var total_dmg = this.getDamage(),
280 291 reduce_dmg = Math.round(total_dmg/2),
281 292 hp_dmg = Math.max(0, total_dmg - reduce_dmg);
282 293
283 294 this.game.data['def'] -= reduce_dmg;
  295 + this.game.data['def'] = Math.max(0,this.game.data['def'])
284 296 this.game.data['hp'] -= hp_dmg;
285 297 //
286 298 goog.events.listen(action, lime.animation.Event.STOP, function() {
@@ -303,10 +315,33 @@ dm.Board.prototype.checkSolutions = function() {
303 315 this.game.show_vars['def']._pg.setProgress(this.game.data['def']/100);
304 316 this.game.show_vars['hp']._lct.setText(this.game.data['hp']+'/'+100);
305 317 this.game.show_vars['def']._lct.setText(this.game.data['def']+'/'+100);
  318 +
  319 + this.show_att = this.fp.a2;
  320 +
306 321 return true;
307 322 };
308 323
309   -
  324 +/**
  325 + * 计算选中序列
  326 + */
  327 + dm.Board.prototype.checkLine = function( line ) {
  328 + var killed = 0;
  329 + for(var element in line){
  330 + if(line[element].type == 'monster'){
  331 + if(this.show_att >= line[element].hp){
  332 + //杀死怪物了
  333 + line[element].setSpecial('Killed!');
  334 + killed += line[element].attack
  335 + }else{
  336 + line[element].unsetSpecial();
  337 + }
  338 + }
  339 + }
  340 + this.game.att.setText(this.show_att);
  341 + this.game.mon.setText(Math.max(0,this.getDamage() - killed));
  342 + //
  343 + }
  344 +
310 345 /**
311 346 * Return possible solutions for current board layout.
312 347 * @return {Array.<lime.Gem>} Array of solutions.
@@ -424,7 +459,7 @@ dm.Board.prototype.pressHandler_ = function(e) {
424 459
425 460 }
426 461 this.selectedGems = this.selectedGems || [];
427   -
  462 + this.checkLine(this.selectedGems);
428 463 //结束
429 464 if(e.type == 'mouseup' || e.type == 'touchend' /*|| e.type == 'touchcancel'*/){
430 465 this.doing_ = false;
@@ -437,7 +472,11 @@ dm.Board.prototype.pressHandler_ = function(e) {
437 472 }
438 473 for( i = 0 ;i < this.selectedGems.length ; i ++){
439 474 this.selectedGems[i].deselect();
440   - if(h_exist == 1 && this.selectedGems[i].type == 'monstor'){
  475 + if(this.selectedGems[i].type == 'sword'){
  476 + this.show_att -= this.fp.a2;
  477 + this.game.att.setText(this.show_att);
  478 + }
  479 + if(h_exist == 1 && this.selectedGems[i].type == 'monster'){
441 480 cancel = 0;
442 481 }
443 482 }
@@ -477,7 +516,9 @@ dm.Board.prototype.pressHandler_ = function(e) {
477 516 if(lastg === g){
478 517 return ; //
479 518 }
  519 +
480 520
  521 +
481 522 var selid = -1;
482 523 for( var i = 0 ; i < this.selectedGems.length - 1; i++){
483 524 if( this.selectedGems[i] === g){
@@ -493,6 +534,17 @@ dm.Board.prototype.pressHandler_ = function(e) {
493 534 while(this.selectedGems.length > selid +1){
494 535 this.cancelGem = this.selectedGems.pop();
495 536 this.cancelGem.deselect();
  537 + if(this.cancelGem.type == 'sword'){
  538 + this.show_att -= this.fp.a2;
  539 + this.game.att.setText(this.show_att);
  540 +
  541 + }
  542 + if(this.cancelGem.type == 'monster'){
  543 + this.cancelGem.unsetSpecial();
  544 + this.show_dmg += this.cancelGem.attack;
  545 + this.game.dmg.setText(this.show_dmg);
  546 + }
  547 +
496 548 this.updateLine();
497 549 return;
498 550 }
@@ -501,7 +553,7 @@ dm.Board.prototype.pressHandler_ = function(e) {
501 553
502 554 }
503 555
504   -
  556 +
505 557 // flick from one cell to another is also supported
506 558 if (e.type == 'mousedown' || e.type == 'touchstart') {
507 559 for( i = 0 ;i < this.selectedGems.length ; i ++){
@@ -518,10 +570,17 @@ dm.Board.prototype.pressHandler_ = function(e) {
518 570 console.log('pressHandler_ not connect ',g,lastg)
519 571 return;
520 572 }
521   -
  573 +
522 574 g.select();
  575 +
  576 + //实时计算伤害:
  577 + if(g.type == 'sword'){
  578 + this.show_att += this.fp.a2;
  579 +
  580 + //显示
  581 + this.game.att.setText(this.show_att);
  582 + }
523 583 this.selectedGems.push(g);
524   -
525 584 this.updateLine();
526 585
527 586
@@ -576,7 +635,7 @@ dm.Board.prototype.getDamage = function(){
576 635 var c, r, damage = 0;
577 636 for (c = 0; c < this.cols; c++) {
578 637 for (r = 0; r < this.gems[c].length; r++) {
579   - if(this.gems[c][r].type == "monstor"){
  638 + if(this.gems[c][r].type == "monster"){
580 639 console.log(this.gems[c][r].attack);
581 640 damage += this.gems[c][r].attack;
582 641 }
3  dm.js
@@ -17,7 +17,8 @@ goog.require('dm.User');
17 17 //constant iPad size
18 18 dm.WIDTH = 720;
19 19 dm.HEIGHT = 1004;
20   -dm.GEMTYPES = ['monstor','blood','defend','sword','gold'];
  20 +dm.BOARDSIZE = 690;
  21 +dm.GEMTYPES = ['monster','blood','defend','sword','gold'];
21 22 //等级到每个属性定义
22 23 dm.LVLCONF = [
23 24 {
29 game.js
@@ -86,16 +86,15 @@ dm.Game = function(size,user){
86 86 var score_lbl = new lime.Label().setFontFamily('Trebuchet MS').setFontColor('#4f96ed').setFontSize(24).
87 87 setPosition(lx, lh).setText('分数').setAnchorPoint(0, 0);
88 88 layer.appendChild(score_lbl);
  89 +
  90 +
89 91
90 92 // score message label
91 93 this.score = new lime.Label().setFontColor('#000').setFontSize(24).setText('0').setPosition(lxx,lh).setAnchorPoint(0, 0).setFontWeight(700);
92   -
  94 +
93 95
94 96 layer.appendChild(this.score);
95 97
96   -
97   -
98   -
99 98
100 99 lh += gap+h;
101 100 // graphical lines for visual effect
@@ -143,14 +142,32 @@ dm.Game = function(size,user){
143 142 this.appendChild(this.btn_menu);
144 143
145 144 // Hint button
146   - this.btn_hint = new dm.Button('提示').setSize(140, 70).setPosition(640, lh).setOpacity(0);
  145 + this.btn_hint = new dm.Button('提示').setSize(140, 70).setPosition(640, lh);
147 146 goog.events.listen(this.btn_hint, 'click', function() {
148 147 if (this.hint)
149 148 this.board.showHint();
150 149 },false, this);
151 150 this.appendChild(this.btn_hint);
152 151
  152 + //其他显示的数据
  153 + var monster_lbl = new lime.Label().setFontFamily('Trebuchet MS').setFontColor('#000').setFontSize(24).
  154 + setPosition(250, lh -25).setText('怪物伤害').setAnchorPoint(0, 0);
  155 +
  156 + this.appendChild(monster_lbl);
  157 +
  158 + var att_lbl = new lime.Label().setFontFamily('Trebuchet MS').setFontColor('#000').setFontSize(24).
  159 + setPosition(250, lh+5).setText('玩家攻击').setAnchorPoint(0, 0);
  160 + this.appendChild(att_lbl);
  161 +
  162 + this.mon = new lime.Label().setFontColor('#000').setFontSize(24).setText('0').setPosition(360,lh -25
  163 + ).setAnchorPoint(0, 0).setFontWeight(700);
  164 +
  165 + this.att = new lime.Label().setFontColor('#000').setFontSize(24).setText('0').setPosition(360,lh + 5).setAnchorPoint(0, 0).setFontWeight(700);
  166 +
  167 + this.appendChild(this.mon);
  168 + this.appendChild(this.att);
153 169
  170 +
154 171 // update score when points have changed
155 172 lime.scheduleManager.scheduleWithDelay(this.updateScore, this, 100);
156 173
@@ -172,7 +189,7 @@ dm.Game.prototype.newGem = function() {
172 189 gem.index = id;
173 190 gem.type = dm.GEMTYPES[id];
174 191 gem.label.setText(gem.type);
175   - if(gem.type == 'monstor'){
  192 + if(gem.type == 'monster'){
176 193 gem.attack = 1;
177 194 gem.blood = 2;
178 195 }
29 gem.js
@@ -14,10 +14,17 @@ dm.Gem = function() {
14 14 this.circle = new lime.Sprite();
15 15 this.label = new lime.Label().setFontSize(15);
16 16 this.label.domClassName = goog.getCssName('lime-button');
  17 +
17 18 this.domClassName = goog.getCssName('lime-button');
18 19 this.appendChild(this.circle);
19 20 this.appendChild(this.label);
20   -
  21 +
  22 + //最上层 特殊效果文字
  23 + this.special = new lime.Label().setFontFamily('Trebuchet MS').setFontColor('#000').setFontSize(30).setAnchorPoint(0.5, 0.5).setOpacity(0);
  24 + this.appendChild(this.special);
  25 + //*/
  26 +
  27 +
21 28 this.selected_ = false;
22 29
23 30 this.index = -1;
@@ -36,7 +43,7 @@ goog.inherits(dm.Gem, lime.Sprite);
36 43 dm.Gem.prototype.canConnect = function(g) {
37 44 return (Math.abs(g.r - this.r) < 2 && Math.abs(g.c - this.c) < 2 )
38 45 && (g.index == this.index ||
39   - (g.type == 'monstor' && this.type == 'sword')|| (this.type == 'monstor' && g.type == 'sword'))
  46 + (g.type == 'monster' && this.type == 'sword')|| (this.type == 'monster' && g.type == 'sword'))
40 47 }
41 48
42 49 /**
@@ -53,7 +60,7 @@ dm.Gem.random = function() {
53 60 gem.index = id;
54 61 gem.type = dm.GEMTYPES[id];
55 62 gem.label.setText(gem.type);
56   - if(gem.type == 'monstor'){
  63 + if(gem.type == 'monster'){
57 64 gem.attack = 1;
58 65 gem.hp = 4;
59 66 }
@@ -70,8 +77,8 @@ dm.Gem.prototype.select = function() {
70 77 var size = this.getSize().clone();
71 78 this.highlight = this.highlight || new lime.Sprite().setSize(size).setFill('assets/selection.png');
72 79 this.appendChild(this.highlight, 0);
73   -
74 80 this.selected_ = true;
  81 +
75 82 };
76 83
77 84 /**
@@ -81,8 +88,22 @@ dm.Gem.prototype.deselect = function() {
81 88 if (!this.selected_) return;
82 89 this.removeChild(this.highlight);
83 90 this.selected_ = false;
  91 +
  92 + if(this.type == 'monster'){
  93 +
  94 + }
84 95 };
85 96
  97 +
  98 +dm.Gem.prototype.setSpecial = function(str) {
  99 + this.special.setText(str).setOpacity(1);
  100 +}
  101 +
  102 +dm.Gem.prototype.unsetSpecial = function() {
  103 + this.special.setOpacity(0);
  104 +}
  105 +
  106 +
86 107 /**
87 108 * @inheritDoc
88 109 */

0 comments on commit c5addc6

Please sign in to comment.
Something went wrong with that request. Please try again.