public GameFieldUI(GameFieldView view) { this.view = view; tableUI = new TableUI(gameField, view.Table); playerUI = new PlayerUI(gameField.Players[0], view.PlayerDeck, tableUI); gameField.EventStartTurn += () => { if (gameField.CurrentPlayer == gameField.Players[0]) { view.PlayerDeck.IsEnabled = true; } else { view.PlayerDeck.IsEnabled = false; } }; botUI = new BotUI((Bot)gameField.Players[1], view.BotDeck, gameField); gameField.EventStartTurn += () => { if (gameField.CurrentPlayer == gameField.Players[1]) { botUI.MakeMove(); } }; gameField.EventGameOver += (state) => EndGame(state); gameField.EventGetDomino += () => view.GetButton.Content = $"Get({gameField.Pool.Count})"; view.GetButton.Content = $"Get({gameField.Pool.Count})"; view.GetButton.Click += playerUI.GetButtonClick; view.SkipButton.Click += (s, e) => { if (gameField.CheckPlayerForNoMoves(gameField.Players[0]) && !gameField.CanTakeDomino(gameField.Players[0])) { gameField.Players[0].EndMove(); } }; gameField.StartGame(); }
public async void MakeMove() { await Task.Run(() => Thread.Sleep(1000)); while (gameField.CheckPlayerForNoMoves(player)) { if (player.TakeDomino() == null) { player.EndMove(); return; } Update(); await Task.Run(() => Thread.Sleep(500)); } var randomImage = (Image)deck.Children[Generator.Random.Next(0, deck.Children.Count)]; Animation.Delete(randomImage, (s, e) => { ((Bot)player).MakeMove(); Update(); }, true); }