在完成了三消游戏的基本操作之后,就要给游戏添加一些道具和分数。在添加道具的时候 当满足一个条件的时候就给第一个点击的块添加一个道具。在移除的方法里面添加道具的功能,具体代码如下:
当满足添加的时候生成道具:
var specialCell = null;
var bigspeci = null;
if(end.length == 4){
specialCell = oldCell
};
if(end.length == 5){
bigspeci = oldCell
}
this.removeCell(end,specialCell,bigspeci);
在移除的方法体里面设置道具的效果:
removeCell:function(arrIndex,cell,bigCell){
var bigSpecial = [];
for(var index in arrIndex){
var bigIndex = arrIndex[index];
if(this.spArr[bigIndex.x][bigIndex.y].isSpecial){
for( var i = 0;i<GAMEDATA.LINE;i++){
bigSpecial.push(cc.p(i,bigIndex.y))
}for(var j = 0 ;j<GAMEDATA.LIST;j++){
bigSpecial.push(cc.p(bigIndex.x,j))
}
this.spArr[bigIndex.x][bigIndex.y].resetSpecal()
}
}
arrIndex = this.filterDelSame(bigSpecial,arrIndex)
if(bigCell) bigCell.setToSpecial()
var spspecialArr = [];
for(var index in arrIndex){
var spIndex = arrIndex[index];
if(this.spArr[spIndex.x][spIndex.y].isSpecial){
for( var i = 0;i<GAMEDATA.LINE;i++){
spspecialArr.push(cc.p(i,spIndex.y))
}
this.spArr[spIndex.x][spIndex.y].resetSpecal()
}
}
arrIndex = this.filterDelSame(spspecialArr,arrIndex)
if(cell) cell.setToSpecial()
//var removeArr = this.checkXl();
if(arrIndex.length>0){
for(var index in arrIndex){
var po = arrIndex[index]
if(this.spArr[po.x][po.y] == cell ){
continue
}
在cell类中添加道具的状态有两个方法,一个是设置道具状态的,一个是移除道具状态的
resetSpecal:function(){
// this.scale = 1
//this.color=cc.colorEqual
this.bossAdd.removeFromParent(true)
this.isSpecial = false
},
setToSpecial:function(){
//this.scale = 0.8;
//this.color=cc.color(0,0,200,255)
this.bossAdd = new cc.Sprite(res.boss)
this.bossAdd.setAnchorPoint(0,0)
this.addChild(this.bossAdd)
this.isSpecial = true
},
添加最高分;显示给每次的分数存在一个容器里面,然后每次游戏结束之后将现在的分数于之前的分数进行比较如果这次的分数比上次的要高则显示这次的分数为最高分,如果没有上次的分数高则就显示原来的。
代码如下:
var hightscoreLablel = new cc.LabelBMFont("High Scores:",res.mikado)
hightscoreLablel.setPosition((cc.winSize.width>>1)-50,cc.winSize.height>>1)
this.addChild(hightscoreLablel)
var hightscoreBox = new cc.LabelBMFont(" High Scores",res.mikado);
hightscoreBox.setPosition((cc.winSize.width>>1)+100,(cc.winSize.height>>1))
hightscoreBox.setColor(cc.color(255,0,0,100))
this.addChild(hightscoreBox)
this.HightScoreSave = cc.sys.localStorage;
//this.HightScoreSave.setItem("hightScore",0)
var result = this.HightScoreSave.getItem("hightScore")
cc.log(result)
cc.log(SAVEScore,"neiwia")
if(SAVEScore >= result)
this.HightScoreSave.setItem("hightScore",SAVEScore);
result = this.HightScoreSave.getItem("hightScore")
hightscoreBox.setString(result)