Exemplo n.º 1
0
        public void FollowerPlacement()
        {
            if (tile == null || selectedPossibility == null)
            {
                return;
            }

            if (Possibilities.Any())
            {
                PlaceTile();
            }

            FollowerPossibilities.Clear();

            if (currentPlayer.FollowersCount == 0)
            {
                tile          = null;
                CurrentColour = null;
                return;
            }

            var followerLocations = tile.GetFollowers(selectedPossibility);

            foreach (var location in followerLocations)
            {
                var followerViewModel = new FollowerViewModel(100 * tile.X + 1042 + location.X * 50, 1042 - 100 * tile.Y - location.Y * 50, currentPlayer.Colour);
                var clickCommand      = new DelegateCommand(() => OnFollowerClick(followerViewModel));
                followerViewModel.ClickCommand = clickCommand;
                FollowerPossibilities.Add(followerViewModel);
            }

            tile = null;
        }
Exemplo n.º 2
0
        public async Task ResetGame()
        {
            await tilesService.Reset();

            Tiles.Clear();
            Possibilities.Clear();
            FollowerPossibilities.Clear();
            Followers.Clear();
            selectedPossibility = null;
            tile          = null;
            playerIndex   = 0;
            CurrentColour = null;
            if (NextTile != null)
            {
                NextTile.ImageSource = null;
            }
        }
Exemplo n.º 3
0
        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);
            }
        }