Пример #1
0
 protected virtual void RaiseSurrenderRecieved(SurrenderMessage message)
 {
     if (SurrenderRecieved != null)
     {
         SurrenderRecieved(this, new MessageEventArgs <SurrenderMessage>(message));
     }
 }
Пример #2
0
        /// <summary>
        /// Sends the surrender message
        /// </summary>
        /// <returns><c>true</c>, if surrender was sent, <c>false</c> otherwise.</returns>
        /// <param name="message">Message.</param>
        public bool SendSurrender(SurrenderMessage message)
        {
            EnsureUsername(message);

            if (client.IsConnected && client.IsSubscribed(Channel))
            {
                string data = System.Web.HttpUtility.UrlEncode(JsonConvert.SerializeObject(message));
                client.Send(Channel, data);
                client.Unsubscribe(Channel);
            }
            else
            {
                throw new Exception("not connected. Call Join Game first");
            }

            return(true);
        }
Пример #3
0
            public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
            {
                JToken jObject = JToken.ReadFrom(reader);
                var    type    = jObject["MessageType"].ToString();

                BaseMessage message;

                switch (type)
                {
                case "FugitiveDistance":
                    message = new FugitiveDistanceMessage();
                    break;

                case "FugitiveLocation":
                    message = new FugitiveLocationMessage();
                    break;

                case "GameStartsAt":
                    message = new GameStartsAtMessage();
                    break;

                case "HelloMessage":
                    message = new HelloMessage();
                    break;

                case "Surrender":
                    message = new SurrenderMessage();
                    break;

                case "CaughtMessage":
                    message = new CaughtMessage();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                serializer.Populate(jObject.CreateReader(), message);

                return(message);
            }