|
|
|
|
@ -13,11 +13,23 @@ export enum moduleState {
|
|
|
|
|
INIT1 = 0,
|
|
|
|
|
INIT2 = 1,
|
|
|
|
|
Ready = 2,
|
|
|
|
|
Spining = 3,
|
|
|
|
|
Stopping = 4,
|
|
|
|
|
SetSpin = 3,
|
|
|
|
|
Spining = 4,
|
|
|
|
|
Stopping = 5,
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export interface columnCondition {
|
|
|
|
|
finalResult:Array<number>; // 預期的最後結果 可為空
|
|
|
|
|
delayTime:number; // 轉動前的延遲 單位 ms
|
|
|
|
|
accelerateTime:number; // 加速時間 單位 s
|
|
|
|
|
slowdownTime:number; // 減速時間 單位 s
|
|
|
|
|
holdspeedTime:number; // delete
|
|
|
|
|
N:number; // 持平速度的item數量 (-1 表示永動 需要手動停)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ccclass("gameMY")
|
|
|
|
|
export class gameMY extends cc.Component {
|
|
|
|
|
|
|
|
|
|
@ -49,9 +61,14 @@ export class gameMY extends cc.Component {
|
|
|
|
|
private balanceNumber: number;
|
|
|
|
|
private bigFrameNumber: number;
|
|
|
|
|
|
|
|
|
|
private stopCount:number;
|
|
|
|
|
private isColumnSpin = {}; // 記錄各個 column 的是否旋轉
|
|
|
|
|
private columnsID: Array<string> = []; // 記錄各個 column 的 node name
|
|
|
|
|
|
|
|
|
|
keepSpin:boolean = false;
|
|
|
|
|
|
|
|
|
|
nowState: moduleState = 0;
|
|
|
|
|
columnConditionList = {}; // 放置所有 column spin codition
|
|
|
|
|
|
|
|
|
|
nowState: moduleState = moduleState.INIT1; // 狀態機
|
|
|
|
|
|
|
|
|
|
// item 圖片資源存放區
|
|
|
|
|
itemNameMapping = {
|
|
|
|
|
@ -63,23 +80,23 @@ export class gameMY extends cc.Component {
|
|
|
|
|
item_spriteFrame = {};
|
|
|
|
|
itemBlur_spriteFrame = {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected onLoad () {
|
|
|
|
|
|
|
|
|
|
this.unitTestInit(); // for engineer use
|
|
|
|
|
|
|
|
|
|
this.onColumnsSignal()
|
|
|
|
|
this.onColumnsSignal();
|
|
|
|
|
|
|
|
|
|
// 讀取 item 圖片資源
|
|
|
|
|
cc.resources.loadDir('item',cc.SpriteFrame, (err: any, sF) => {
|
|
|
|
|
sF.forEach( (eachSpriteFrame)=>{
|
|
|
|
|
this.item_spriteFrame[ this.itemNameMapping[eachSpriteFrame.name] ] = eachSpriteFrame
|
|
|
|
|
this.item_spriteFrame[ this.itemNameMapping[eachSpriteFrame.name] ] = eachSpriteFrame;
|
|
|
|
|
})
|
|
|
|
|
} );
|
|
|
|
|
cc.resources.loadDir('item_blur',cc.SpriteFrame, (err: any, sF) => {
|
|
|
|
|
sF.forEach( (eachSpriteFrame)=>{
|
|
|
|
|
this.itemBlur_spriteFrame[ this.itemNameMapping[eachSpriteFrame.name] ] = eachSpriteFrame
|
|
|
|
|
this.itemBlur_spriteFrame[ this.itemNameMapping[eachSpriteFrame.name] ] = eachSpriteFrame;
|
|
|
|
|
})
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
@ -90,15 +107,17 @@ export class gameMY extends cc.Component {
|
|
|
|
|
protected start () {
|
|
|
|
|
this.betNumber = 50;
|
|
|
|
|
|
|
|
|
|
this.slotBoard.addChild( cc.instantiate(this.columnPrefab), 1 )
|
|
|
|
|
this.slotBoard.addChild( cc.instantiate(this.columnPrefab), 2 )
|
|
|
|
|
this.slotBoard.addChild( cc.instantiate(this.columnPrefab), 3 )
|
|
|
|
|
this.slotBoard.addChild( cc.instantiate(this.columnPrefab), 4 )
|
|
|
|
|
|
|
|
|
|
this.slotBoard.children[0].name = "0";
|
|
|
|
|
this.slotBoard.addChild( cc.instantiate(this.columnPrefab), 1 , "1");
|
|
|
|
|
this.slotBoard.addChild( cc.instantiate(this.columnPrefab), 2 , "2");
|
|
|
|
|
this.slotBoard.addChild( cc.instantiate(this.columnPrefab), 3 , "3");
|
|
|
|
|
this.slotBoard.addChild( cc.instantiate(this.columnPrefab), 4 , "4");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected update (dt) {
|
|
|
|
|
|
|
|
|
|
let isAnySpin:boolean = false;
|
|
|
|
|
let isAllSpin:boolean = true;
|
|
|
|
|
switch(this.nowState){
|
|
|
|
|
case moduleState.INIT1:
|
|
|
|
|
// 檢查圖片載入完成後
|
|
|
|
|
@ -114,19 +133,45 @@ export class gameMY extends cc.Component {
|
|
|
|
|
break;
|
|
|
|
|
case moduleState.INIT2:
|
|
|
|
|
for(let i=0; i<this.columnCount; i++){
|
|
|
|
|
cc.log(this.slotBoard.children[i].x)
|
|
|
|
|
this.columnsID.push(this.slotBoard.children[i].name); // 直接取位置資訊當ID
|
|
|
|
|
this.isColumnSpin[this.slotBoard.children[i].name] = false;
|
|
|
|
|
}
|
|
|
|
|
this.simulateCondition(); // dev
|
|
|
|
|
// cc.log(this.columnsID) // dev
|
|
|
|
|
// cc.log(this.isColumnSpin) // dev
|
|
|
|
|
this.nowState = moduleState.Ready;
|
|
|
|
|
break;
|
|
|
|
|
case moduleState.Ready:
|
|
|
|
|
break;
|
|
|
|
|
case moduleState.SetSpin:
|
|
|
|
|
Object.values(this.isColumnSpin).forEach((x:boolean)=>{
|
|
|
|
|
isAllSpin = isAllSpin && x;
|
|
|
|
|
});
|
|
|
|
|
if(isAllSpin) {
|
|
|
|
|
this.nowState = moduleState.Spining;
|
|
|
|
|
// TODO: 避免重複使用 columnConditionList 應該適當處理
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case moduleState.Spining:
|
|
|
|
|
this.stopCount = 0;
|
|
|
|
|
Object.values(this.isColumnSpin).forEach((x:boolean)=>{
|
|
|
|
|
isAnySpin = isAnySpin || x;
|
|
|
|
|
});
|
|
|
|
|
if( !isAnySpin ){
|
|
|
|
|
if(this.keepSpin){
|
|
|
|
|
// get new condition
|
|
|
|
|
this.nowState = moduleState.SetSpin;
|
|
|
|
|
break;
|
|
|
|
|
}else{
|
|
|
|
|
this.nowState = moduleState.Stopping;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case moduleState.Stopping:
|
|
|
|
|
if(this.stopCount == 5){
|
|
|
|
|
this.nowState = moduleState.Ready;
|
|
|
|
|
}
|
|
|
|
|
Object.values(this.isColumnSpin).forEach((x:boolean)=>{
|
|
|
|
|
isAnySpin = isAnySpin || x;
|
|
|
|
|
});
|
|
|
|
|
if( !isAnySpin ) this.nowState = moduleState.Ready;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
@ -144,16 +189,15 @@ export class gameMY extends cc.Component {
|
|
|
|
|
else{
|
|
|
|
|
this.betNumber -= 50;
|
|
|
|
|
}
|
|
|
|
|
this.betString.string = "" + this.betNumber
|
|
|
|
|
this.betString.string = "" + this.betNumber;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onSpinBtnClick():void {
|
|
|
|
|
|
|
|
|
|
switch(this.nowState){
|
|
|
|
|
case moduleState.Ready:
|
|
|
|
|
this.nowState = moduleState.Spining;
|
|
|
|
|
this.nowState = moduleState.SetSpin;
|
|
|
|
|
break;
|
|
|
|
|
case moduleState.Spining:
|
|
|
|
|
this.nowState = moduleState.Stopping;
|
|
|
|
|
@ -166,9 +210,13 @@ export class gameMY extends cc.Component {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onColumnsSignal():void {
|
|
|
|
|
this.node.on('AColumnStop', ()=>{
|
|
|
|
|
this.stopCount += 1;
|
|
|
|
|
this.node.on('AColumnStop', (ID)=>{
|
|
|
|
|
this.isColumnSpin[ID] = false;
|
|
|
|
|
}, this)
|
|
|
|
|
|
|
|
|
|
this.node.on('AColumnStart',(ID)=>{
|
|
|
|
|
this.isColumnSpin[ID] = true;
|
|
|
|
|
} ,this)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -178,11 +226,23 @@ export class gameMY extends cc.Component {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
simulateCondition():void {
|
|
|
|
|
for(let i=0; i<this.columnCount; i++){
|
|
|
|
|
let a:columnCondition = {
|
|
|
|
|
finalResult:[i+1,i+1,i+1],
|
|
|
|
|
delayTime:200*i,
|
|
|
|
|
accelerateTime:5,
|
|
|
|
|
slowdownTime:2,
|
|
|
|
|
holdspeedTime:0.5,
|
|
|
|
|
N:3}
|
|
|
|
|
this.columnConditionList[this.columnsID[i]]=a
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unitTestInit():void {
|
|
|
|
|
// for unitTest 1
|
|
|
|
|
this.node.on('Bob', (arg1)=>{
|
|
|
|
|
cc.log("gameModule Recieve Bob say " + arg1)
|
|
|
|
|
cc.log("gameModule Recieve Bob say " + arg1);
|
|
|
|
|
}, this)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|