Esempio n. 1
0
        /// <summary>
        /// 交換カード受け取り時処理
        /// </summary>
        /// <param name="playerId"></param>
        /// <param name="cards"></param>
        /// <returns></returns>
        private ResultOfPlaying ReceivedTradingCards(int playerId, List <Card> cards)
        {
            var result = ResultOfPlaying.Accepted;

            do
            {
                // カード枚数チェック
                if (players[playerId].tradingCardCount != cards.Count)
                {
                    result = ResultOfPlaying.NotAccepted;
                    break;
                }

                // 交換相手を特定
                var           player   = players[playerId];
                PrivateStatus opponent = null;
                switch (player.roleRank)
                {
                case RoleRank.Daifugo:
                    opponent = players.FirstOrDefault(p => p.roleRank == RoleRank.Daihinmin);
                    break;

                case RoleRank.Fugo:
                    opponent = players.FirstOrDefault(p => p.roleRank == RoleRank.Hinmin);
                    break;

                default:
                    // logger(LogLevel.Error, "Player rank must be Daifugo or Fugo!");
                    break;
                }

                // 交換相手存在チェック
                if (opponent == null)
                {
                    // logger( LogLevel.Error, "Not found opponent!");
                    result = ResultOfPlaying.NotAccepted;
                    break;
                }

                // 交換処理
                if (!DaifugoFunction.TradeCards(player.hand, cards, opponent.hand))
                {
                    // 不正なカードが指定されていた
                    // logger( LogLevel.Error, "Received card is invalid!");
                    result = ResultOfPlaying.NotAccepted;
                    break;
                }
            } while (false);
            players[playerId].tradingCardCount = 0;

            return(result);
        }
Esempio n. 2
0
        public PrivateStatus Clone()
        {
            var clone = new PrivateStatus();

            clone.id       = id;
            clone.seat     = seat;
            clone.roleRank = roleRank;
            foreach (var card in hand)
            {
                hand.Add(card);
            }
            clone.tradingCardCount = tradingCardCount;
            clone.hasPassed        = hasPassed;

            return(clone);
        }
Esempio n. 3
0
        /// <summary>
        /// プレイヤーを追加
        /// 参加不可の場合-1を返す
        /// </summary>
        /// <returns>プレイヤーID</returns>
        private int LetPlayerJoin()
        {
            if (players.Count >= playerCount)
            {
                return(-1);
            }

            var id     = players.Count;
            var player = new PrivateStatus
            {
                id   = id,
                hand = new List <Card>()
            };

            players.Add(player);

            return(id);
        }
Esempio n. 4
0
        /// <summary>
        /// ゲーム情報通知
        /// </summary>
        /// <param name="connectionId"></param>
        /// <param name="publicStatus"></param>
        /// <param name="privateStatus"></param>
        /// <returns></returns>
        public Task SendStatusAsync(
            string connectionId,
            PublicStatus publicStatus,
            PrivateStatus privateStatus)
        {
            var task = new Task(() =>
            {
                if (string.IsNullOrEmpty(connectionId))
                {
                    return;
                }
                SingleProcessMessageTransceiver client;
                if (_connectedClientTable.TryGetValue(connectionId, out client))
                {
                    client.ReceivedStatus?.Invoke(this, new ReceivedStatusArgs(publicStatus, privateStatus));
                }
            });

            task.RunSynchronously();
            return(task);
        }
Esempio n. 5
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        public Player(IClientMessageTransceiver messageTransceiver)
        {
            this.messageTransceiver = messageTransceiver;

            EventHandler <ReceivedPlayerIdArgs> receivedPlayerIdHandler = (sender, args) =>
            {
                id = args.PlayerId;
            };

            this.messageTransceiver.ReceivedPlayerId += receivedPlayerIdHandler;

            EventHandler <ReceivedStatusArgs> receivedStatusHandler = (sender, args) =>
            {
                publicStatus  = args.PublicStatus;
                privateStatus = args.PrivateStatus;
                UpdatedStatus?.Invoke(this, new UpdatedStatusArgs(publicStatus, privateStatus));
            };

            this.messageTransceiver.ReceivedStatus += receivedStatusHandler;

            EventHandler <ReceivedEndMessageArgs> receivedEndMessageHandler = (sender, args) =>
            {
                switch (args.EndMessage)
                {
                case EndMessage.NotEnd:
                    break;

                case EndMessage.EndRound:
                    EndedRound?.Invoke(this, new EndedRoundArgs());
                    break;

                case EndMessage.EndGame:
                    EndedGame?.Invoke(this, new EndedGameArgs());
                    break;
                }
            };

            this.messageTransceiver.ReceivedEndMessage += receivedEndMessageHandler;
        }
Esempio n. 6
0
 public UpdatedStatusArgs(PublicStatus publicStatus, PrivateStatus privateStatus)
 {
     PublicStatus  = publicStatus;
     PrivateStatus = privateStatus;
 }
Esempio n. 7
0
 public ReceivedStatusArgs(PublicStatus publicStatus, PrivateStatus privateStatus)
 {
     PublicStatus  = publicStatus;
     PrivateStatus = privateStatus;
 }