210 lines
6.3 KiB
ActionScript
210 lines
6.3 KiB
ActionScript
package net.pixvi.myr.center
|
|
{
|
|
import flash.events.Event;
|
|
import net.pixvi.common.center.PopCenter;
|
|
import net.pixvi.common.system.language.lang;
|
|
import net.pixvi.common.utils.Alert;
|
|
import net.pixvi.myr.element.bag.ItemVo;
|
|
import net.pixvi.myr.element.reward.RewardResultVo;
|
|
import net.pixvi.myr.net.NetMiniGame;
|
|
import net.pixvi.myr.panel.gameroom.MiniGameVo;
|
|
import net.pixvi.myr.panel.minigame.BaseMiniGame;
|
|
import net.pixvi.myr.panel.minigame.minigame1.MiniGame1_Runner;
|
|
import net.pixvi.myr.panel.minigame.minigame2.MiniGame2_MoleHitter;
|
|
import net.pixvi.myr.panel.minigame.minigame3.MiniGame3_SlimCombiner;
|
|
import net.pixvi.myr.panel.minigame.minigame4.MiniGame4_WCCommander;
|
|
import net.pixvi.myr.panel.minigame.minigame5.MiniGame5_TaoDaE;
|
|
import net.pixvi.myr.panel.minigame.minigame6.MiniGame6_BrickHero;
|
|
import net.pixvi.myr.panel.reward.RewardShowPanel;
|
|
import net.pixvi.pfw.utils.Saver;
|
|
import net.pixvi.pfw.utils.core.Singleton;
|
|
|
|
public class MiniGameCenter
|
|
{
|
|
|
|
public var gameRecords:Object;
|
|
|
|
private var onMiniGameStartComplete:Function;
|
|
|
|
private var onMiniGameStart_vo:MiniGameVo;
|
|
|
|
private var onMiniGameOverComplete:Function;
|
|
|
|
private var onMiniGameOver_id:int;
|
|
|
|
private var onMiniGameOver_point:int;
|
|
|
|
private var onGetRecordComplete:Function;
|
|
|
|
public function MiniGameCenter()
|
|
{
|
|
super();
|
|
}
|
|
|
|
public static function getIns() : MiniGameCenter
|
|
{
|
|
return Singleton.getInstanceOrCreate(MiniGameCenter) as MiniGameCenter;
|
|
}
|
|
|
|
public function miniGameStart(id:int, onComplete:Function) : void
|
|
{
|
|
onMiniGameStartComplete = onComplete;
|
|
var gamevo:MiniGameVo = new MiniGameVo();
|
|
gamevo.typeId = id;
|
|
onMiniGameStart_vo = gamevo;
|
|
NetMiniGame.getIns().miniGameStart(onMiniGameStart_vo.type,miniGameStartHandler);
|
|
}
|
|
|
|
public function miniGameStartHandler(re:Object = null) : void
|
|
{
|
|
BagCenter.getIns().subNumByType(int(onMiniGameStart_vo.coinType),onMiniGameStart_vo.coin,true,"",true);
|
|
if(onMiniGameStartComplete != null)
|
|
{
|
|
onMiniGameStartComplete();
|
|
onMiniGameStartComplete = null;
|
|
}
|
|
}
|
|
|
|
public function miniGameOver(id:int, point:int, onComplete:Function) : void
|
|
{
|
|
onMiniGameOverComplete = onComplete;
|
|
onMiniGameOver_id = id;
|
|
onMiniGameOver_point = point;
|
|
NetMiniGame.getIns().miniGameOver(point,miniGameOverHandler);
|
|
}
|
|
|
|
private function miniGameOverHandler(re:Object = null) : void
|
|
{
|
|
var vo:MiniGameVo = new MiniGameVo();
|
|
vo.typeId = onMiniGameOver_id;
|
|
if(gameRecords[onMiniGameOver_id.toString()] == null)
|
|
{
|
|
gameRecords[onMiniGameOver_id.toString()] = {
|
|
"type":vo.type,
|
|
"maxScore":onMiniGameOver_point,
|
|
"num":0
|
|
};
|
|
}
|
|
if(re.newRecord == true)
|
|
{
|
|
Alert.showMsg(lang("创造了新的个人记录!"));
|
|
gameRecords[onMiniGameOver_id.toString()].maxScore = onMiniGameOver_point;
|
|
}
|
|
gameRecords[onMiniGameOver_id.toString()].num++;
|
|
var itemvo:ItemVo = new ItemVo();
|
|
itemvo.id = re.itemId;
|
|
itemvo.num = re.num;
|
|
var gamevovo:MiniGameVo = new MiniGameVo();
|
|
gamevovo.typeId = onMiniGameOver_id;
|
|
itemvo.type = gamevovo.ticketType;
|
|
BagCenter.getIns().addItem(itemvo);
|
|
var rewardre:RewardResultVo = new RewardResultVo();
|
|
RewardShowPanel.show([itemvo],minigameOverRewardshowHandler);
|
|
if(onMiniGameOverComplete != null)
|
|
{
|
|
onMiniGameOverComplete(re);
|
|
onMiniGameOverComplete = null;
|
|
}
|
|
}
|
|
|
|
public function minigameOverRewardshowHandler(e:Event = null) : void
|
|
{
|
|
PopCenter.getIns().setMaskAlpha();
|
|
}
|
|
|
|
public function getRecord(onComplete:Function) : void
|
|
{
|
|
onGetRecordComplete = onComplete;
|
|
NetMiniGame.getIns().getRecord(getRecordHandler);
|
|
}
|
|
|
|
private function getRecordHandler(re:Object = null) : void
|
|
{
|
|
if(re.gameRecords == null)
|
|
{
|
|
gameRecords = {};
|
|
}
|
|
else
|
|
{
|
|
gameRecords = {};
|
|
for each(var o:Object in re.gameRecords)
|
|
{
|
|
gameRecords[Table.mini_game[o.type].typeId] = o;
|
|
}
|
|
}
|
|
if(onGetRecordComplete != null)
|
|
{
|
|
onGetRecordComplete(re);
|
|
onGetRecordComplete = null;
|
|
}
|
|
}
|
|
|
|
public function getMiniGame(gameType:int) : BaseMiniGame
|
|
{
|
|
var game:BaseMiniGame = null;
|
|
switch(gameType - 1)
|
|
{
|
|
case 0:
|
|
game = new MiniGame1_Runner();
|
|
break;
|
|
case 1:
|
|
game = new MiniGame2_MoleHitter();
|
|
break;
|
|
case 2:
|
|
game = new MiniGame3_SlimCombiner();
|
|
break;
|
|
case 3:
|
|
game = new MiniGame4_WCCommander();
|
|
break;
|
|
case 4:
|
|
game = new MiniGame5_TaoDaE();
|
|
break;
|
|
case 5:
|
|
game = new MiniGame6_BrickHero();
|
|
}
|
|
return game;
|
|
}
|
|
|
|
public function getRecordScore(gameType:int) : int
|
|
{
|
|
var vo:MiniGameVo = new MiniGameVo();
|
|
vo.typeId = gameType;
|
|
return vo.topPoint;
|
|
}
|
|
|
|
public function saveLocalRecordScore(gameType:int, score:int) : void
|
|
{
|
|
var masterId:int = 0;
|
|
if(Master == null)
|
|
{
|
|
masterId = 0;
|
|
}
|
|
else
|
|
{
|
|
masterId = int(Master.id);
|
|
}
|
|
Saver.saveAuto(masterId + "_game" + gameType,score);
|
|
}
|
|
|
|
public function getLocalRecordScore(gameType:int) : int
|
|
{
|
|
var masterId:int = 0;
|
|
if(Master == null)
|
|
{
|
|
masterId = 0;
|
|
}
|
|
else
|
|
{
|
|
masterId = int(Master.id);
|
|
}
|
|
var re:Object = Saver.getAuto(masterId + "game" + gameType);
|
|
if(re == null)
|
|
{
|
|
return 0;
|
|
}
|
|
return int(re);
|
|
}
|
|
}
|
|
}
|
|
|