예제 #1
0
        internal static void Load(int index)
        {
            if (GameListLoader.Games.Count >= index)
            {
                _game = GameListLoader.Games[index];

                string map = _game.map.ToString();
                _map = MapLoaderFactory.CreateLoader(map);
                _map.LoadContent(Global.Content);

                var result = ApiReq.CreateReq()
                             .WithMethod("api/map/" + map, "get")
                             .GetResult(out string json);
                if (result == HttpStatusCode.OK)
                {
                    _map.SetMapData(DynamicJson.Parse(json));
                    Global.RunState = RunState.Run;
                }
            }
        }
예제 #2
0
        public static void Update()
        {
            //init a new thread to refresh the game list
            if (!_started)
            {
                Task.Factory.StartNew(() => {
                    while (Global.RunState == RunState.Init)
                    {
                        var result = ApiReq.CreateReq()
                                     .WithMethod("api/Game", "get")
                                     .GetResult(out string json);
                        if (result == HttpStatusCode.OK)
                        {
                            dynamic array = DynamicJson.Parse(json);
                            if (array.IsArray)
                            {
                                lock (Games)
                                {
                                    Games.Clear();
                                    foreach (var item in array)
                                    {
                                        Games.Add(item);
                                    }
                                }
                            }
                        }

                        Thread.Sleep(2000);
                    }
                }).ContinueWith((task) => {
                    _started = false;
                });

                _started = true;
            }

            KeyboardHandler.Update();
        }
예제 #3
0
        public static void Update()
        {
            //init a new thread to refresh the game list
            if (!_started)
            {
                Task.Factory.StartNew(() => {
                    while (Global.RunState == RunState.Run)
                    {
                        string url = "api/Game/" + _game.id.ToString();
                        var result = ApiReq.CreateReq()
                                     .WithMethod(url, "get")
                                     .GetResult(out string json);
                        if (result == HttpStatusCode.OK)
                        {
                            dynamic data = DynamicJson.Parse(json);
                            if (json != "{}")
                            {
                                LoadGameData(data);
                            }

                            if (_state > 1)
                            {
                                break;
                            }
                        }

                        Thread.Sleep(1000);
                    }
                }).ContinueWith((task) => {
                    _started = false;
                });

                _started = true;
            }

            KeyboardHandler.Update();
        }