private void TryTile(IList <FitProperties> possibilities, TileViewModel tileViewModel) { foreach (var possibility in Possibilities) { possibility.ImageSource = null; } tileViewModel.ImageSource = NextTile.ImageSource; var previousPossibility = possibilities.FirstOrDefault(p => p.Rotation == tileViewModel.Rotation); var index = previousPossibility == null ? 0 : possibilities.IndexOf(previousPossibility) + 1; index = index >= possibilities.Count ? 0 : index; selectedPossibility = possibilities[index]; tileViewModel.Rotation = selectedPossibility.Rotation; }
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); } }