Exemplo n.º 1
0
 public void UserChoose(ShapeModel clientModel)
 {
     _model    = clientModel;
     _userPick = true;
     //_hubContext.Clients.AllExcept(_model.LastUpdatedBy).userChoose(_model);
     //_hubContext.Clients.All.userChoose(_model);
 }
Exemplo n.º 2
0
        public Task UpdateScore(ShapeModel clientModel)
        {
            if (System.Web.HttpContext.Current.Application["score"] == null)
            {
                System.Web.HttpContext.Current.Application["score"] = 0;
            }
            else
            {
                System.Web.HttpContext.Current.Application["score"] = Convert.ToInt32(System.Web.HttpContext.Current.Application["score"]) + 1;
            }

            int testScore = Convert.ToInt32(System.Web.HttpContext.Current.Application["score"]);

            ShapeModel sm = new ShapeModel();

            _connections.TryGetValue(Context.ConnectionId, out sm);

            sm.CoinScore += 5;

            foreach (var item in _connections.Values)
            {
                if (item.CoinScore > 100)
                {
                    return(Clients.All.winner(item));
                }
            }

            return(Clients.All.updateScore(sm));
            // Update the shape model within our broadcaster
        }
Exemplo n.º 3
0
 public void UpdateModel(ShapeModel clientModel)
 {
     clientModel.LastUpdatedBy = Context.ConnectionId;
     // Update the shape model within our broadcaster
     //Clients.AllExcept(clientModel.LastUpdatedBy).UpdateShape(clientModel);
     _broadcaster.UpdateShape(clientModel);
 }
Exemplo n.º 4
0
        public Task OtherPlayer(ShapeModel clientModel)
        {
            clientModel.ShapeOwner = Context.ConnectionId;
            ShapeModel temp = new ShapeModel();

            _connections.TryGetValue(clientModel.ShapeOwner, out temp);
            return(Clients.Others.otherPlayer(temp));
        }
Exemplo n.º 5
0
 private Broadcaster()
 {
     // 获取连接上下文
     _hubContext   = GlobalHost.ConnectionManager.GetHubContext <MoveShapeHub>();
     _model        = new ShapeModel();
     _modelUpdated = false;
     // 初始化定时器
     _broadcastLoop = new Timer(BroadcastShape, null, BroadcastInterval, BroadcastInterval);
 }
Exemplo n.º 6
0
        public void UpdateModel(ShapeModel clientModel)
        {
            clientModel.LastUpdateBy = Context.ConnectionId;
            // 调用客户端定义的updateShape方法
            // Clients.AllExcept(clientModel.LastUpdateBy).updateShape(clientModel);

            // 调用广播的更新图形方法
            _broadcaster.UpdateShape(clientModel);
        }
Exemplo n.º 7
0
 public void UserChoose(ShapeModel clientModel)
 {
     if (clientModel.ShapeOwner == null ||
         clientModel.ShapeOwner.Equals("none"))
     {
         clientModel.LastUpdatedBy = Context.ConnectionId;
         clientModel.ShapeOwner    = Context.ConnectionId;
         _broadcaster.UserChoose(clientModel);
     }
 }
Exemplo n.º 8
0
 public Broadcaster()
 {
     _hubContext    = GlobalHost.ConnectionManager.GetHubContext <MoveShapeHub>();
     _model         = new ShapeModel();
     _modelUpdated  = false;
     _broadcastLoop = new Timer(
         BroadcastShape,
         null,
         BroadcastInterval,
         BroadcastInterval
         );
 }
Exemplo n.º 9
0
        public void MoveCoin(ShapeModel coinModel)
        {
            //Move coin to random position within game area
            Random rnd      = new Random();
            int    randLeft = rnd.Next(1, 800);
            int    randTop  = rnd.Next(1, 600);

            coinModel.Left = randLeft;
            coinModel.Top  = randTop;

            // Update the shape model within our broadcaster
            _broadcaster.UpdateCoinShape(coinModel);
        }
Exemplo n.º 10
0
        public override Task OnConnected()
        {
            int        free = 0;
            ShapeModel sm   = new ShapeModel();

            sm.ShapeOwner = Context.ConnectionId;
            //sm.PlayerId = "player" + (_connections.Count + 1).ToString();
            _connections.ReturnFreeId(out free);
            sm.PlayerId = "player" + free.ToString();
            sm.ShapeId  = free;
            _connections.TryAdd(Context.ConnectionId, sm);
            return(Clients.All.clientConnected(sm));
        }
Exemplo n.º 11
0
        public override Task OnDisconnected()
        {
            ShapeModel sm = new ShapeModel();

            sm.ShapeOwner = Context.ConnectionId;
            sm.PlayerId   = "player" + _connections.Count.ToString();
            sm.CoinScore  = 0;
            ShapeModel value;

            _connections.TryRemove(Context.ConnectionId, out value);
            sm.PlayerId = value.PlayerId;
            return(Clients.AllExcept(Context.ConnectionId).clientDisconnected(sm));
        }
Exemplo n.º 12
0
 public Broadcaster()
 {
     // Save our hub context so we can easily use it
     // to send to its connected clients
     _hubContext = GlobalHost.ConnectionManager.GetHubContext<MoveShapeHub>();
     _model = new ShapeModel();
     _modelUpdated = false;
     // Start the broadcast loop
     _broadcastLoop = new Timer(
         BroadcastShape,
         null,
         BroadcastInterval,
         BroadcastInterval);
 }
Exemplo n.º 13
0
 public Broadcaster()
 {
     // Save our hub context so we can easily use it
     // to send to its connected clients
     _hubContext   = GlobalHost.ConnectionManager.GetHubContext <MoveShapeHub>();
     _model        = new ShapeModel();
     _modelUpdated = false;
     // Start the broadcast loop
     _broadcastLoop = new Timer(
         BroadcastShape,
         null,
         BroadcastInterval,
         BroadcastInterval);
 }
Exemplo n.º 14
0
        public void UpdateScore(ShapeModel clientModel)
        {
            if (System.Web.HttpContext.Current.Application["score"] == null)
            {
                System.Web.HttpContext.Current.Application["score"] = 0;
            }
            else
            {
                System.Web.HttpContext.Current.Application["score"] = Convert.ToInt32(System.Web.HttpContext.Current.Application["score"]) + 1;
            }

            int testScore = Convert.ToInt32(System.Web.HttpContext.Current.Application["score"]);

            clientModel.LastUpdatedBy = Context.ConnectionId;
            // Update the shape model within our broadcaster
            _broadcaster.UpdateShape(clientModel);
        }
Exemplo n.º 15
0
        /// <summary>
        ///  客户端将调用这个方法.
        /// </summary>
        /// <param name="clientModel"></param>
        public void UpdateModel(ShapeModel clientModel)
        {
            clientModel.LastUpdatedBy = Context.ConnectionId;



            // ----------  Version  1.0 ----------

            // 初期版本的代码.
            // 也就是 除了当前操作的用户以外, 其他用户都调用 updateShape 方法。
            // Clients.AllExcept(clientModel.LastUpdatedBy).updateShape(clientModel);

            // 因为这个例子是 拖矩形的, 和 聊天室不同。
            // 聊天室是 用户发送一个消息, 然后全部人都收到。

            // 这里 拖矩形的人, 拖动操作已经完成了, 就不能让这个人的画面再发生更新操作。

            // ----------  Version  1.0 ----------



            // Update the shape model within our broadcaster
            _broadcaster.UpdateShape(clientModel);
        }
Exemplo n.º 16
0
        public Broadcaster()
        {
            // Save our hub context so we can easily use it
            // Faskdklas
            // to send to its connected clients
            _hubContext   = GlobalHost.ConnectionManager.GetHubContext <MoveShapeHub>();
            _model        = new ShapeModel();
            _modelUpdated = false;
            // Start the broadcast loop
            _broadcastLoop = new Timer(
                BroadcastShape,
                null,
                BroadcastInterval,
                BroadcastInterval);



            ////Test of API usage

            ////Image im = new Image();
            ////im = http://api.met.no/weatherapi/weathericon/1.1/?symbol=5;content_type=image/png;


            ////Bitmap bitmap = new Bitmap(@"C:\image.png");

            ////Bitmap bitmap = new Bitmap(@"http://api.met.no/weatherapi/weathericon/1.1/?symbol=5;content_type=image/png");


            //using (WebClient webClient = new WebClient())
            //{
            //    webClient.DownloadFile("http://api.met.no/weatherapi/weathericon/1.1/?symbol=5;content_type=image/png", "weatherImage.png");
            //}



            //string url = string.Format(@"http://api.openweathermap.org/data/2.5/weather?q=Stockholm&APPID=0efffa3566c0a86b9a03fb679a5bab08");
            //WebClient client = new WebClient();

            //string jsonstring = client.DownloadString(url);

            //var obj = JObject.Parse(jsonstring);

            ////Longitude and latitude of chosen city
            //string lon = (string)obj["coord"]["lon"];
            //string lat = (string)obj["coord"]["lat"];

            ////Weather icon representing weather at chosen city, to be used in backgrond image
            //string weatherIcon = (string)obj["weather"][0]["icon"];

            //string timeStamp = DateTime.Now.ToString();
            //TimeSpan span = DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0));
            //double currentTimeDouble = span.TotalSeconds;
            //currentTimeDouble = Math.Round(currentTimeDouble);

            //string currentTimeString = currentTimeDouble.ToString();


            //string url2 = string.Format(@"https://maps.googleapis.com/maps/api/timezone/json?location=" + lat + "," + lon + "&timestamp=" + currentTimeString + "& key=AIzaSyAbWTrXF9-X76XxEZH2SsFFNLtdb2ojtAU");


            //WebClient client2 = new WebClient();

            //string jsonstring2 = client.DownloadString(url2);
            //var obj2 = JObject.Parse(jsonstring2);

            ////Time difference in seconds of chosen place compared to GMT(?) time
            ////To be used to calculate if night or day
            //string timeDifference = (string)obj2["dstOffset"];



            //int test = new int();

            ////string url = string.Format(@"http://localhost:49468/api/Subscribers/SubscriberNumber/{0}", id);
            ////WebClient client = new WebClient();

            ////string jsonstring = client.DownloadString(url);

            ////Subscriber new_subscriber = JsonConvert.DeserializeObject<Subscriber>(jsonstring);
        }
Exemplo n.º 17
0
 public void UpdateShape(ShapeModel clientModel)
 {
     _model = clientModel;
     _modelUpdated = true;
 }
Exemplo n.º 18
0
 public void UpdateModel(ShapeModel clientModel)
 {
     clientModel.LastUpdatedBy = Context.ConnectionId;
     // Update the shape model within our broadcaster
     _broadcaster.UpdateShape(clientModel);
 }
Exemplo n.º 19
0
 public void UpdateModel(ShapeModel clientModel)
 {
     clientModel.LastUpdatedBy = Context.ConnectionId;
     // update the shape model within our broadcaster
     _broadcaster.UpdateShape(clientModel);
 }
Exemplo n.º 20
0
 public void UpdateCoinShape(ShapeModel coinModel)
 {
     _coinModel   = coinModel;
     _coinUpdated = true;
 }
Exemplo n.º 21
0
 public void UpdateModel(ShapeModel clientModal)
 {
     clientModal.LastUpdatedBy = Context.ConnectionId;
     Clients.AllExcept(clientModal.LastUpdatedBy).updateShape(clientModal);
 }
Exemplo n.º 22
0
 public void UpdateShape(ShapeModel clientModel)
 {
     _model        = clientModel;
     _modelUpdated = true;
 }
Exemplo n.º 23
0
 public void UpdateModel(ShapeModel clientModal)
 {
     clientModal.LastUpdatedBy = Context.ConnectionId;
     Clients.AllExcept(clientModal.LastUpdatedBy).updateShape(clientModal);
 }