private void GameTimerOnTick(object sender, object e) { gameTimer.Stop(); var tile = tilesService.NextTile(); if (tile == null) { return; } var possibilities = tilesService.GetPossibilities(tile).ToList(); var possibility = possibilities.OrderByDescending(x => x.Score).FirstOrDefault(); if (possibility != null) { tilesService.PlaceTile(tile, possibility); Tiles.Add(new TileViewModel(100 * tile.X + 1000, 1000 - 100 * tile.Y, tile.Rotation, tile.ImageUri)); } gameTimer.Start(); }
public async Task GetNextTile() { if (tile != null && Possibilities.Any()) { return; } var follower = FollowerPossibilities.FirstOrDefault(f => f.IsSelected); if (follower != null) { Followers.Add(follower); currentPlayer.FollowersCount--; } FollowerPossibilities.Clear(); currentPlayer = players[playerIndex]; CurrentColour = new SolidColorBrush(currentPlayer.Colour); playerIndex = playerIndex >= players.Count - 1 ? 0 : playerIndex + 1; tile = tilesService.NextTile(); NextTile = tile == null ? null : new TileViewModel(100 * tile.X + 1000, 1000 - 100 * tile.Y, tile.Rotation, tile.ImageUri); if (tile == null) { return; } selectedPossibility = null; var possibilities = tilesService.GetPossibilities(tile).ToList(); if (!currentPlayer.IsInteractive) { var possibility = possibilities.OrderByDescending(x => x.Score).FirstOrDefault(); if (possibility != null) { tilesService.PlaceTile(tile, possibility); await Task.Delay(1000); Tiles.Add(new TileViewModel(100 * tile.X + 1000, 1000 - 100 * tile.Y, tile.Rotation, tile.ImageUri)); var followerLocation = tile.GetFollowers(possibility).OrderBy(x => Guid.NewGuid()).FirstOrDefault(); if (followerLocation != null && currentPlayer.FollowersCount > 0) { var followerViewModel = new FollowerViewModel(100 * tile.X + 1042 + followerLocation.X * 50, 1042 - 100 * tile.Y - followerLocation.Y * 50, currentPlayer.Colour); Followers.Add(followerViewModel); currentPlayer.FollowersCount--; } } await Task.Delay(1000); tile = null; await GetNextTile(); return; } foreach (var group in possibilities.GroupBy(x => x.Point)) { var vm = new TileViewModel(100 * group.Key.X + 1000, 1000 - 100 * group.Key.Y); vm.ClickCommand = new DelegateCommand(() => TryTile(group.ToList(), vm)); Possibilities.Add(vm); } }