127 lines
3.8 KiB
ActionScript
127 lines
3.8 KiB
ActionScript
package net.pixvi.myr.net
|
|
{
|
|
import net.pixvi.myr.center.TimeCenter;
|
|
import net.pixvi.pfw.utils.core.Singleton;
|
|
|
|
public class NetMiniGame
|
|
{
|
|
|
|
public static const GAME_START:String = "miniGameService/gameStart";
|
|
|
|
public static const GAME_OVER:String = "miniGameService/gameOver";
|
|
|
|
public static const GET_RECORD:String = "miniGameService/getRecord";
|
|
|
|
public static const SAVE_DATA:String = "archiveInfoService/saveInfo";
|
|
|
|
public static const LOAD_DATA:String = "archiveInfoService/getArchiveInfo";
|
|
|
|
private var onSaveDataComplete:Function;
|
|
|
|
private var onLoadDataComplete:Function;
|
|
|
|
private var onMiniGameStartComplete:Function;
|
|
|
|
private var onMiniGameStart_type:String;
|
|
|
|
private var onMiniGameOverComplete:Function;
|
|
|
|
private var onGetRecordComplete:Function;
|
|
|
|
public function NetMiniGame()
|
|
{
|
|
super();
|
|
}
|
|
|
|
public static function getIns() : NetMiniGame
|
|
{
|
|
return Singleton.getInstanceOrCreate(NetMiniGame) as NetMiniGame;
|
|
}
|
|
|
|
public function saveData(typeId:String, data:String, keyValue1:String, keyValue2:String, onComplete:Function) : void
|
|
{
|
|
onSaveDataComplete = onComplete;
|
|
var para:Object = {
|
|
"typeId":typeId,
|
|
"data":data,
|
|
"keyValue1":keyValue1,
|
|
"keyValue2":keyValue2,
|
|
"dataTime":TimeCenter.timestamp
|
|
};
|
|
NetCenter.getIns().send("archiveInfoService/saveInfo",para,saveDataHandler,false);
|
|
}
|
|
|
|
public function saveDataHandler(re:Object) : void
|
|
{
|
|
if(onSaveDataComplete != null)
|
|
{
|
|
onSaveDataComplete(re);
|
|
onSaveDataComplete = null;
|
|
}
|
|
}
|
|
|
|
public function loadData(typeId:String, onComplete:Function) : void
|
|
{
|
|
onLoadDataComplete = onComplete;
|
|
var para:Object = {"typeId":typeId};
|
|
NetCenter.getIns().send("archiveInfoService/getArchiveInfo",para,loadDataHandler,false);
|
|
}
|
|
|
|
public function loadDataHandler(re:Object) : void
|
|
{
|
|
onLoadDataComplete(re.archiveInfo);
|
|
onLoadDataComplete = null;
|
|
}
|
|
|
|
public function miniGameStart(gameType:String, onComplete:Function) : void
|
|
{
|
|
onMiniGameStartComplete = onComplete;
|
|
onMiniGameStart_type = gameType;
|
|
var para:Object = {"type":onMiniGameStart_type};
|
|
NetCenter.getIns().send("miniGameService/gameStart",para,miniGameStartHandler,false);
|
|
}
|
|
|
|
public function miniGameStartHandler(re:Object = null) : void
|
|
{
|
|
if(onMiniGameStartComplete != null)
|
|
{
|
|
onMiniGameStartComplete();
|
|
onMiniGameStartComplete = null;
|
|
}
|
|
}
|
|
|
|
public function miniGameOver(point:int, onComplete:Function) : void
|
|
{
|
|
onMiniGameOverComplete = onComplete;
|
|
var para:Object = {"score":point};
|
|
NetCenter.getIns().send("miniGameService/gameOver",para,miniGameOverHandler,false);
|
|
}
|
|
|
|
private function miniGameOverHandler(re:Object = null) : void
|
|
{
|
|
if(onMiniGameOverComplete != null)
|
|
{
|
|
onMiniGameOverComplete(re);
|
|
onMiniGameOverComplete = null;
|
|
}
|
|
}
|
|
|
|
public function getRecord(onComplete:Function) : void
|
|
{
|
|
onGetRecordComplete = onComplete;
|
|
var para:Object = {};
|
|
NetCenter.getIns().send("miniGameService/getRecord",para,getRecordHandler,false);
|
|
}
|
|
|
|
private function getRecordHandler(re:Object = null) : void
|
|
{
|
|
if(onGetRecordComplete != null)
|
|
{
|
|
onGetRecordComplete(re);
|
|
onGetRecordComplete = null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|