public void Player2_Wins_Test(int[] input) { GameOperation g = new GameOperation(input); int playerWinner = g.DrawResult(1); Assert.IsTrue(playerWinner % 2 == 0, "Player2 is the winner"); }
public override GameOperation LoadGame() { GameOperation operation = new GameOperation(); StartCoroutine(CRDummyLoad(operation)); return(operation); }
public void DoGameOperPlayerActionSyn(int action, params int[] card) { Debug.LogFormat("=>DoActionSyn action:{0},card1:{1},card2:{2}", ActionStr(action), card.Length > 0 ? GetCardStr(card[0]) : GetCardStr(-1), card.Length > 1 ? GetCardStr(card[1]) : GetCardStr(-1)); RoomMgr.actionNotify.actions = 0; GameOperPlayerActionSyn content = new GameOperPlayerActionSyn(); content.action = action; content.cardValue.AddRange(card); GameOperation request = new GameOperation() { operType = GameOperType.GameOperPlayerActionSyn }; request.content = NetSerilizer.Serialize <GameOperPlayerActionSyn>(content); PacketBase msg = new PacketBase() { packetType = PacketType.GameOperation }; msg.data = NetSerilizer.Serialize <GameOperation>(request); SocketNetTools.SendMsg(msg); }
/// <summary> /// GameOnComplete /// completion callback for Game() /// if true heal all players and start new game /// </summary> /// <param name="result"></param> private void GameOnComplete(IAsyncResult result) { bool iResult = false; GameOperation del; AsyncResult asyncObj = (AsyncResult)result; if (asyncObj.EndInvokeCalled == false) { del = (GameOperation)asyncObj.AsyncDelegate; iResult = del.EndInvoke(asyncObj); } asyncObj.AsyncWaitHandle.Close(); if (m_players.Count >= 5 && iResult) // if players agree to continue { GameOperation game = Game; AsyncCallback callback = GameOnComplete; foreach (var player in m_players) { player.Value.MaxHeal(); // heal players } m_boss = SelectBoss(); // select new boss game.BeginInvoke(callback, null); // async call to gamne } else { foreach (var user in m_clients) // remove all players from game { if (m_players.ContainsKey(user.Key.UserID)) { m_players.Remove(user.Key.UserID); } } } }
/// <summary> /// Unloads (destroy) the assets instantiates by this game. /// Introuces an artifical wait of one second. /// </summary> /// <param name="operation"></param> /// <returns></returns> protected IEnumerator CRDummyUnload(GameOperation operation) { Destroy(mapInstance.gameObject); yield return(new WaitForSeconds(1.0f)); OnGameQuit.Invoke(); operation.isDone = true; }
private void Awake() { if (_instance != null) { Destroy(this.gameObject); return; } _instance = this; }
public override GameOperation QuitGame() { state = State.quit; GameOperation operation = new GameOperation(); StartCoroutine(CRDummyUnload(operation)); return(operation); }
public async Task <ActionResult <GameState> > PostCompleteGame(string gameId) { string userId = User.GetUserId(); GameOperation operation = await this.gameStateProvider.CompleteGameAsync(userId, gameId); if (!operation.Succeeded) { return(new BadRequestObjectResult(operation.ErrorMessage)); } return(operation.GameState); }
public async Task <ActionResult <GameState> > Post(string gameId, [FromBody] string cardId) { string userId = User.GetUserId(); GameOperation operation = await this.gameStateProvider.PlayCardAsync(userId, gameId, cardId); if (!operation.Succeeded) { return(new BadRequestObjectResult(operation.ErrorMessage)); } return(operation.GameState); }
public async Task <ActionResult <GameState> > Post([FromBody] string deckId) { string userId = User.GetUserId(); string userName = User.GetUserName(); string authToken = this.Request.GetBearerAuthToken(); GameOperation operation = await this.gameStateProvider.StartGameAsync(userId, userName, deckId, authToken); if (!operation.Succeeded) { return(new BadRequestObjectResult(operation.ErrorMessage)); } return(operation.GameState); }
public void SelectHero(User user, Hero hero) { try { if (m_players.ContainsKey(user.UserID)) // change users hero { m_players[user.UserID] = hero; foreach (var item in m_clients) { item.Value.NotifyClient(user.UserName + " has joined the fray."); // notifies clients } } else if (m_players.Count < 12) // adds new player { m_players.Add(user.UserID, hero); foreach (var item in m_clients) { item.Value.NotifyClient(user.UserName + " has joined the fray."); // notifies clients } } else // notify the user that the serve is full { m_clients[user].NotifyClient("Server Full"); } if (m_players.Count == 5) // begin game { GameOperation gameDel = Game; AsyncCallback callback = this.GameOnComplete; gameDel.BeginInvoke(callback, null); // start game with async call } } catch (CommunicationException) { Console.WriteLine("Error Comunicating with client"); if (m_clients.ContainsKey(user)) // if there is an error communicating with the client { m_clients.Remove(user); // remove the client } } }
/// <summary> /// Instantiates the map and character. Listens to some events. /// Introduces an artifical wait of one second to simulate some loading, since these prefabs are /// already at hand and not being loaded from AssetBundles. /// </summary> /// <param name="operation"></param> /// <returns></returns> protected IEnumerator CRDummyLoad(GameOperation operation) { yield return(new WaitForSeconds(1.0f)); mapInstance = GameObject.Instantiate(mapPrefab); mapManipulator.mapPivot = mapInstance.transform; SetupTargets(); catInstance = GameObject.Instantiate(catPrefab); catInstance.transform.SetParent(mapInstance.transform); catInstance.transform.position = mapInstance.characterSpawnPoint.position; catInstance.transform.rotation = mapInstance.characterSpawnPoint.rotation; OnCatHealthChanged.AddListener(OnCatHealthChange); mapInstance.mapRaycastController.onRayCastHit.AddListener(catInstance.MoveTo); operation.isDone = true; state = State.loaded; OnGameLoaded.Invoke(); }
void _OnGameOperation(GameOperation response) { switch (response.operType) { case GameOperType.GameOperStartSyn: OnGameOperStartSyn(NetSerilizer.DeSerialize <GameOperStartSyn>(response.content)); break; case GameOperType.GameOperHandCardSyn: //OnGameOperHandCardSyn(NetSerilizer.DeSerialize<GameOperHandCardSyn>(response.content)); break; case GameOperType.GameOperPublicInfoSyn: OnGameOperPublicInfoSyn(NetSerilizer.DeSerialize <GameOperPublicInfoSyn>(response.content)); break; case GameOperType.GameOperPlayerHuSyn: OnGameOperPlayerHuSyn(NetSerilizer.DeSerialize <GameOperPlayerHuSyn>(response.content)); break; case GameOperType.GameOperPlayerActionNotify: OnGameOperPlayerActionNotify(NetSerilizer.DeSerialize <GameOperPlayerActionNotify>(response.content)); break; case GameOperType.GameOperActorSyn: OnGameOperActorSyn(NetSerilizer.DeSerialize <GameOperActorSyn>(response.content)); break; case GameOperType.GameOperPlayerActionSyn: OnGameOperPlayerActionSyn(NetSerilizer.DeSerialize <GameOperPlayerActionSyn>(response.content)); break; case GameOperType.GameOperBaoChangeSyn: OnGameOperBaoChangeSyn(NetSerilizer.DeSerialize <GameOperBaoChangeSyn>(response.content)); break; case GameOperType.GameOperFinalSettleSyn: OnGameOperFinalSettleSyn(NetSerilizer.DeSerialize <GameOperFinalSettleSyn>(response.content)); break; } }
void Start() { //EventDispatcher.AddEventListener(MessageCommand.LoginSucess, OnLogin); AddEventListener(PacketType.AuthRequest, OnAuth); AddEventListener(PacketType.PlayerSitSyn, OnPLAYER_SIT_SYN); AddEventListener(PacketType.KickOutSyn, OnKickOutSyn); AddEventListener(PacketType.PlayerGamingSyn, OnGAMING_SYN); AddEventListener(PacketType.EnrollRequest, OnENROLL); AddEventListener(PacketType.ReadySyn, OnREADY_SYN); AddEventListener(PacketType.GameStartSyn, OnAllReadySyn); AddEventListener(PacketType.GameStartDealCardSyn, OnStartDealSyn); AddEventListener(PacketType.GameStartPlaySyn, OnStartGamePlaySyn); AddEventListener(PacketType.GameOperation, OnGameOperation); AddEventListener(PacketType.DeskDestorySyn, OnDeskDestorySyn); AddEventListener(PacketType.ServerChangeSyn, Game.OnServerChangeSyn); AddEventListener(PacketType.LogoutSyn, OnLogoutSyn); //EventDispatcher.AddEventListener(MessageCommand.PopQueue, OnPopQueue); SocketNetTools.OnConnect -= OnConnect; SocketNetTools.OnConnect += OnConnect; StartRoom(); Game.DelayLoop(0.03f, () => { bool IsBusy = Game.MJMgr.players[0].MJHand.IsBusy || Game.MJMgr.players[1].MJHand.IsBusy || Game.MJMgr.players[2].MJHand.IsBusy || Game.MJMgr.players[3].MJHand.IsBusy; if (!IsBusy && queue.Count > 0) { GameOperation actionSyn = queue.Dequeue(); _OnGameOperation(actionSyn); } }); }
void OnGameOperation(PacketBase msg) { if (msg.code == 0) { GameOperation response = NetSerilizer.DeSerialize <GameOperation>(msg.data); //if (string.IsNullOrEmpty(Game.Instance.matchType) || Game.Instance.matchType == MatchType.G_DQMJ_MATCH_SINGLE.ToString()) //{ // queue.Enqueue(response); //}else //if (HandAnima.IsBusy || queue.Count>0) { queue.Enqueue(response); } //else //{ //_OnGameOperation(response); //} } else { Game.DialogMgr.PushDialog(UIDialog.SingleBtnDialog, "错误:code:" + msg.code + "; msg:" + msg.msg); } }
/// <summary> /// 构造函数,初始化 /// </summary> public CharacterState_Idle(Character character) { this.character = character; Debug.Log("------------------------character in StandingState~!(进入站立状态!)"); EventController.AddEventListener(character.PlayerID.ToString() + "_Input_" + GameOperation.ToString(); , Move);
public CommandOperation(GameOperation gameOperation) : base(gameOperation) { }
public InfoOperation(GameOperation gameOperation) : base(gameOperation) { }
/// <summary> /// /// </summary> public UserOperationMessage(IClearMine game, GameOperation operation, IEnumerable<MineCell> effectedCells) { Source = game; UserOperation = operation; EffectedCells = effectedCells; }
public BaseOperation(GameOperation gameOperation) { this.gameOperation = gameOperation; }
public DataOperation(GameOperation gameOperation) : base(gameOperation) { }
/// <summary> /// /// </summary> public UserOperationMessage(IClearMine game, GameOperation operation, IEnumerable <MineCell> effectedCells) { Source = game; UserOperation = operation; EffectedCells = effectedCells; }
public ObjectOperation(GameOperation gameOperation) : base(gameOperation) { }