예제 #1
0
        //
        //  this allows us to deal with the polymorphic deserialization of these log records
        //  "json" has the full object graph of the LogHeader, PlayedDevCardModel, and any
        //  derived class
        //
        static public PlayedDevCardModel Deserialize(object unparsedJson)
        {
            string action = ((JsonElement)unparsedJson).GetProperty("devCard").GetString();

            if (String.IsNullOrEmpty(action))
            {
                return(null);
            }
            bool ret = Enum.TryParse(action, true, out DevCardType devCard);

            if (!ret)
            {
                return(null);
            }
            string json = unparsedJson.ToString();

            switch (devCard)
            {
            case DevCardType.Knight:
                KnightPlayedLog pk = CatanProxy.Deserialize <KnightPlayedLog>(json);
                return(pk as PlayedDevCardModel);

            case DevCardType.YearOfPlenty:
                PlayedPlayedYearOfPlentyLog yop = CatanProxy.Deserialize <PlayedPlayedYearOfPlentyLog>(json);
                return(yop as PlayedDevCardModel);

            case DevCardType.RoadBuilding:
                return(CatanProxy.Deserialize <PlayedDevCardModel>(json));

            case DevCardType.Monopoly:
                PlayedMonopoly mono = CatanProxy.Deserialize <PlayedMonopoly>(json);
                return(mono as PlayedMonopoly);

            case DevCardType.Back:
            case DevCardType.Unknown:
            case DevCardType.VictoryPoint:
            default:
                break;
            }

            return(null);
        }
예제 #2
0
        public Task <PlayerResources> KnightPlayed(string gameName, string playerName, KnightPlayedLog log)
        {
            if (String.IsNullOrEmpty(gameName) || String.IsNullOrEmpty(playerName))
            {
                throw new ArgumentException("names can't be null or empty");
            }
            string url = $"{HostName}/api/catan/devcard/play/knight/{gameName}/{playerName}";

            return(Post <PlayerResources>(url, Serialize(log)));
        }