我是 Flash 和 AS3 的新手。我正在尝试使用 vitapoly.extension.gamekit 制作基于回合的 iOS 游戏。问题是 - 我无法理解用法。我已经尝试过他们告诉我的内容,但无法正确实施。如果有人能告诉我它是如何工作的,或者我如何以完美的方式实现它,我真的很感激。
请拜托拜托......帮助......
我现在想要的东西很简单——当游戏开始时,它会去游戏中心寻找玩家。一旦比赛开始 - 本地玩家将轮到。Ater 将轮到其他玩家。
这是我的代码 -
import com.vitapoly.nativeextensions.gamekit.*;
import com.vitapoly.nativeextensions.gamekit.events.*;
import com.vitapoly.nativeextensions.gamekit.ios.*;
import com.vitapoly.nativeextensions.gamekit.realtime.*;
import com.vitapoly.nativeextensions.gamekit.turnbased.*;
import flash.display.MovieClip;
import flash.events.MouseEvent;
var supported:Boolean = GameKit.isSupported;
if(supported){
var gamekit:GameKit = new GameKit();
}
init();
function init(){
btn_start.addEventListener(MouseEvent.CLICK, gameStart);
}
function gameStart(m:MouseEvent):void{
btn_start.visible = false;
gameCenterStart();
}
function gameCenterStart():void{
if(supported){
gamekit.addEventListener(GameKit.LOCAL_PLAYER_AUTHENTICATED_EVENT, function(e:Event):void {
trace("LOCAL_PLAYER_AUTHENTICATED_EVENT");
gameCenterMatch();
});
gamekit.addEventListener(GameKit.LOCAL_PLAYER_NOT_AUTHENTICATED_EVENT, function(e:ErrorEvent):void {
trace("LOCAL_PLAYER_NOT_AUTHENTICATED_EVENT: " + e.text);
// don’t allow to proceed if no single player
// or just disable multiplayer interface
disableMultiplayer(); // implement your own
});
gamekit.authenticateLocalPlayer();
var localPlayer:LocalPlayer = gamekit.localPlayer;
trace(localPlayer.displayName);
// load friends with a completion callback function
localPlayer.loadFriends(function(friends:Array):void {
// localPlayer.friends property is now loaded
for each (var friend:Player in localPlayer.friends)
trace("friend: " + friend.displayName);
});
gamekit.showGameCenter();
}
}
function startGame():void{
box_mc.visible = true;
box_mc.player_txt.text = "Game Started";
box_mc.addEventListener(MouseEvent.CLICK, done);
gameCenterMatch();
}
function takeTurn():void{
box_mc.addEventListener(MouseEvent.CLICK, done);
}
function done(m:MouseEvent):void{
box_mc.player_txt.text = "Local Player Turn";
gameCenterMatch();
}
function displayGame():void{
box_mc.player_txt.text = "Other's Turn";
gameCenterMatch();
}
function showMsg(a:String){
}
function disableMultiplayer():void{
box_mc.player_txt.text = "No Multi";
}
function gameCenterMatch():void{
if(supported){
gamekit.turnBasedMatchesController.addEventListener(TurnBasedMatchesController.MATCH_MAKER_FAILED_EVENT, function(e:ErrorEvent):void {
trace("MATCH_MAKER_FAILED_EVENT: " + e.errorID + ", " + e.text);
});
gamekit.turnBasedMatchesController.addEventListener(TurnBasedMatchesController.MATCH_MAKER_CANCELLED_EVENT, function(e:Event):void {
trace("MATCH_MAKER_CANCELLED_EVENT");
});
gamekit.turnBasedMatchesController.addEventListener(TurnBasedMatchesController.MY_TURN_EVENT, function(e:MatchEvent):void {
trace("MY_TURN_EVENT: " + JSON.stringify(e));
if (e.turnBasedMatch.isNewMatch)
startGame(); // local player just started the game, so show new game
else if (e.turnBasedMatch.isCurrentMatch)
takeTurn(); // it's the currently displaying match, so the local player take the turn
else
showMsg("It's your turn for another match: " + e.turnBasedMatch.matchID);
});
gamekit.turnBasedMatchesController.addEventListener(TurnBasedMatchesController.NOT_MY_TURN_EVENT, function(e:MatchEvent):void {
trace("NOT_MY_TURN_EVENT: " + JSON.stringify(e));
if (e.turnBasedMatch.isCurrentMatch)
displayGame(); // not the player's turn, just show it
else
showMsg("It's someone else's turn for another match: " + e.turnBasedMatch.matchID);
});
gamekit.turnBasedMatchesController.addEventListener(TurnBasedMatchesController.MATCH_ENDED_EVENT, function(e:MatchEvent):void {
trace("MATCH_ENDED_EVENT: " + JSON.stringify(e));
if (e.turnBasedMatch.isCurrentMatch)
displayGame(); // just show the end game
else
showMsg("Another match ended: " + e.turnBasedMatch.matchID);
});
gamekit.turnBasedMatchesController.addEventListener(TurnBasedMatchesController.PLAYER_QUIT_EVENT, function(e:MatchEvent):void {
trace("PLAYER_QUIT_EVENT: " + JSON.stringify(e));
// the player quit a match from match making interface
// quit it with a lost outcome
showMsg("player quit match: " + e.turnBasedMatch.matchID);
e.turnBasedMatch.quitDuringTurn(GKTurnBasedMatchOutcome.GKTurnBasedMatchOutcomeLost, e.turnBasedMatch.matchData);
});
gamekit.turnBasedMatchesController.addEventListener(TurnBasedMatchesController.INVITE_PLAYERS_EVENT, function(e:InvitePlayersEvent):void {
trace("INVITE_PLAYERS_EVENT: " + JSON.stringify(e));
// invited players from Game Center, bring up match making interface with the array of invited players
gamekit.turnBasedMatchesController.startMatch(2, 2, e.playersToInvite);
});
gamekit.turnBasedMatchesController.init();
gamekit.turnBasedMatchesController.startMatch(2, 12);
}
}