Exemplo n.º 1
0
    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");
    }
Exemplo n.º 2
0
    public override GameOperation LoadGame()
    {
        GameOperation operation = new GameOperation();

        StartCoroutine(CRDummyLoad(operation));
        return(operation);
    }
Exemplo n.º 3
0
    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);
    }
Exemplo n.º 4
0
        /// <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);
                    }
                }
            }
        }
Exemplo n.º 5
0
    /// <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;
    }
Exemplo n.º 6
0
 private void Awake()
 {
     if (_instance != null)
     {
         Destroy(this.gameObject); return;
     }
     _instance = this;
 }
Exemplo n.º 7
0
    public override GameOperation QuitGame()
    {
        state = State.quit;
        GameOperation operation = new GameOperation();

        StartCoroutine(CRDummyUnload(operation));
        return(operation);
    }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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
                }
            }
        }
Exemplo n.º 12
0
    /// <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();
    }
Exemplo n.º 13
0
    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;
        }
    }
Exemplo n.º 14
0
    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);
            }
        });
    }
Exemplo n.º 15
0
    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);
        }
    }
Exemplo n.º 16
0
 /// <summary>
 /// 构造函数,初始化
 /// </summary>
 public CharacterState_Idle(Character character)
 {
     this.character = character;
     Debug.Log("------------------------character in StandingState~!(进入站立状态!)");
     EventController.AddEventListener(character.PlayerID.ToString() + "_Input_" + GameOperation.ToString(); , Move);
Exemplo n.º 17
0
 public CommandOperation(GameOperation gameOperation) : base(gameOperation)
 {
 }
Exemplo n.º 18
0
 public InfoOperation(GameOperation gameOperation) : base(gameOperation)
 {
 }
Exemplo n.º 19
0
 /// <summary>
 /// 
 /// </summary>
 public UserOperationMessage(IClearMine game, GameOperation operation, IEnumerable<MineCell> effectedCells)
 {
     Source = game;
     UserOperation = operation;
     EffectedCells = effectedCells;
 }
Exemplo n.º 20
0
 public BaseOperation(GameOperation gameOperation)
 {
     this.gameOperation = gameOperation;
 }
Exemplo n.º 21
0
 public DataOperation(GameOperation gameOperation) : base(gameOperation)
 {
 }
Exemplo n.º 22
0
 /// <summary>
 ///
 /// </summary>
 public UserOperationMessage(IClearMine game, GameOperation operation, IEnumerable <MineCell> effectedCells)
 {
     Source        = game;
     UserOperation = operation;
     EffectedCells = effectedCells;
 }
Exemplo n.º 23
0
 public ObjectOperation(GameOperation gameOperation) : base(gameOperation)
 {
 }