public GameObject() { InitializeComponent(); foreach (Window item in Application.Current.Windows) { if (item.Name == "Window1") { diff = Convert.ToSingle(((Options)item).slider1.Value); cat = ((Options)item).comboBox_Copy.Text; } } Game_ fertigesgame = CreateGameAsync(diff, cat).Result; Cover(); DispatcherTimer timer = new DispatcherTimer(); timer.Tick += Remove; timer.Interval = new TimeSpan(0, 0, 1);//Zeit wird vom Server übergeben timer.Start(); }
static async Task <Game_> CreateGameAsync(float difficultyScale, string category) { Game_ game = new Game_(); // Call asynchronous network methods in a try/catch block to handle exceptions. try { var response = client.PostAsJsonAsync("http://77.244.251.110:81/api/games", new GameStartObject { difficultyScale = difficultyScale, category = category }).Result; var answer = await response.Content.ReadAsStringAsync(); JObject json = JObject.Parse(answer); Difficulty difficulty = new Difficulty(); foreach (var item in json.Children()) // macht ein richtiges Game... { switch (item.Path) { case "id": game.Id = (Guid)item.Last; break; case "pictureID": game.pictureID = (Guid)item.Last; break; case "isFinished": game.isFinished = (bool)item.Last; break; case "difficulty": foreach (var item2 in item.Children().Children()) { switch (item2.Path) { case "difficulty.difficultyScale": difficulty.DifficultyScale = (float)item2.Last; break; case "difficulty.rows": difficulty.rows = (int)item2.Last; break; case "difficulty.cols": difficulty.cols = (int)item2.Last; break; case "difficulty.revealDelay": difficulty.revealDelay = (float)item2.Last; break; default: break; } } break; default: MessageBox.Show("Da war was falsch..."); break; } } game.Difficulty = difficulty; MessageBox.Show(Convert.ToString(game.Difficulty.revealDelay) + " " + Convert.ToString(game.Difficulty.rows) + " " + Convert.ToString(game.Difficulty.cols) + " " + Convert.ToString(game.Difficulty.DifficultyScale) + " " + Convert.ToString(game.Id) + " " + Convert.ToString(game.isFinished) + " " + Convert.ToString(game.pictureID) + " "); } catch (HttpRequestException e) { MessageBox.Show("\nException Caught!"); MessageBox.Show("Message :{0} ", e.Message); } return(game); }