示例#1
0
文件: Game.cs 项目: litsungyi/Hanabi
 private void PlayerPlayCard(IHanabiPlayer player, RequestPlayCard card)
 {
     player.Room.Play(player, card);
 }
示例#2
0
文件: Game.cs 项目: litsungyi/Hanabi
        public void DispatchRequest(IPlayer player, string message)
        {
            IHanabiPlayer hanabiPlayer = player as IHanabiPlayer;

            if (hanabiPlayer == null)
            {
                return;
            }

            Command    command = JsonConvert.DeserializeObject <Command>(message);
            ActionType action  = ( ActionType )Enum.Parse(typeof(ActionType), command.Action, false);

            switch (action)
            {
            case ActionType.EnterGame:
            {
                RequestEnterGame request = JsonConvert.DeserializeObject <RequestEnterGame>(command.Payload);
                PlayerEnterGame(hanabiPlayer, request);
                break;
            }

            case ActionType.ExitGame:
            {
                RequestExitGame request = JsonConvert.DeserializeObject <RequestExitGame>(command.Payload);
                PlayerExitGame(hanabiPlayer, request);
                break;
            }

            case ActionType.GetRoomList:
            {
                PlayerGetRoomList(hanabiPlayer);
                break;
            }

            case ActionType.JoinRoom:
            {
                RequestJoinRoom request = JsonConvert.DeserializeObject <RequestJoinRoom>(command.Payload);
                PlayerJoinRoom(hanabiPlayer, request);
                break;
            }

            case ActionType.QuitRoom:
            {
                RequestQuitRoom request = JsonConvert.DeserializeObject <RequestQuitRoom>(command.Payload);
                PlayerQuitRoom(hanabiPlayer, request);
                break;
            }

            case ActionType.Message:
            {
                // TODO:
                break;
            }

            case ActionType.Ready:
            {
                PlayerReady(hanabiPlayer);
                break;
            }

            case ActionType.PromptCard:
            {
                RequestPromptCard request = JsonConvert.DeserializeObject <RequestPromptCard>(command.Payload);
                PlayerPrompt(hanabiPlayer, request);
                break;
            }

            case ActionType.PlayCard:
            {
                RequestPlayCard request = JsonConvert.DeserializeObject <RequestPlayCard>(command.Payload);
                PlayerPlayCard(hanabiPlayer, request);
                break;
            }

            case ActionType.DiscardCard:
            {
                RequestDiscardCard request = JsonConvert.DeserializeObject <RequestDiscardCard>(command.Payload);
                PlayerDiscardCard(hanabiPlayer, request);
                break;
            }

            default:
                break;
            }
        }
示例#3
0
        public void Play(IHanabiPlayer player, RequestPlayCard card)
        {
            if (!IsCurrentPlayer(player))
            {
                ResponsePlayCard invalidResponse = new ResponsePlayCard();
                invalidResponse.Result = PlayCardResult.InvalidTurn;
                SendCommandToPlayer(player, ActionType.PlayCard, invalidResponse);
                return;
            }

            CardIndexType cardIndex = new CardIndexType(card.CardIndex);
            Card          oldCard   = player.GetCard(cardIndex);

            Card           newCard = null;
            PlayCardResult result  = Rule.PlayCard(cardIndex, player, Board, out newCard);

            if (result != PlayCardResult.Success && result != PlayCardResult.FailNoSlot)
            {
                ResponsePlayCard invalidResponse = new ResponsePlayCard();
                invalidResponse.Result = result;
                SendCommandToPlayer(player, ActionType.PlayCard, invalidResponse);
                return;
            }

            ResponsePlayCard response = new ResponsePlayCard();

            response.Result        = result;
            response.Nickname      = player.Nickname.Value;
            response.OldCard       = oldCard.Info;
            response.NewCard       = (newCard != null) ? newCard.Info : null;
            response.Token         = Board.Tokens.Info;
            response.DrawPileCount = Board.Size;

            CardInfo info = (newCard != null) ? newCard.Info : null;

            if (info != null)
            {
                info.Color = ( int )CardColorType.Unknown;
                info.Value = ( int )CardValueType.Unknown;
            }

            ResponsePlayCard notify = new ResponsePlayCard();

            notify.Result        = result;
            notify.Nickname      = player.Nickname.Value;
            notify.OldCard       = oldCard.Info;
            notify.NewCard       = info;
            notify.Token         = Board.Tokens.Info;
            notify.DrawPileCount = Board.Size;

            foreach (var notifyPlayer in Players)
            {
                if (notifyPlayer == player)
                {
                    SendCommandToPlayer(notifyPlayer, ActionType.PlayCard, notify);
                }
                else
                {
                    SendCommandToPlayer(notifyPlayer, ActionType.PlayCard, response);
                }
            }

            CheckLastRound();

            NextActivePlayer();
            NotifyNextPlayer();
        }