예제 #1
0
        public void RobberEventHandler(PlayerViewModel player, int numberOfResourcesToSelect)
        {
            if (numberOfResourcesToSelect > 0)
            {
                // Display resources for player to discard
                this.workingNumberOfResourcesToSelect         = numberOfResourcesToSelect;
                this.ResourceSelectionMessage                 = $"Select {this.workingNumberOfResourcesToSelect} more resources to drop";
                this.ResourceSelectionConfirmButton.IsEnabled = false;

                var width  = 100;
                var gutter = 10;
                var midX   = 400;
                var midY   = 200;
                var x      = midX - ((player.Resources.Count * width) + ((player.Resources.Count - 1) * gutter) / 2);

                int resourceIndex = 0;
                for (; resourceIndex < player.Resources.Count; resourceIndex++)
                {
                    if (resourceIndex >= this.resourceControls.Count)
                    {
                        // Need a new resource control
                        var newButton = new ResourceButton(this.ResourceSelectedEventHandler);
                        this.resourceControls.Add(newButton);
                        this.ResourceSelectionLayer.Children.Add(newButton);
                    }

                    var resourceButton = this.resourceControls[resourceIndex];

                    var resourceType = this.GetResourceTypeAt(resourceIndex, player.Resources);
                    this.GetResourceCardImages(resourceType, out var imagePath, out var selectedImagePath);
                    resourceButton.OriginalImagePath = resourceButton.ImagePath = imagePath;
                    resourceButton.SelectedImagePath = selectedImagePath;
                    resourceButton.ResourceType      = resourceType;

                    Canvas.SetLeft(resourceButton, x);
                    Canvas.SetTop(resourceButton, midY);
                    x += width + gutter;

                    resourceButton.Visibility = Visibility.Visible;
                }

                // Hide resource controls that are not needed this time.
                var resourceControlIndex = resourceIndex;
                for (; resourceControlIndex < this.resourceControls.Count; resourceControlIndex++)
                {
                    this.resourceControls[resourceControlIndex].Visibility = Visibility.Hidden;
                }

                this.ResourceSelectionLayer.Visibility = Visibility.Visible;
                return;
            }

            // Select hex to place robber
            this.RobberSelectionLayer.Visibility = Visibility.Visible;
        }
예제 #2
0
 private void ResourceSelectedEventHandler(ResourceButton resourceButton)
 {
     this.workingNumberOfResourcesToSelect        -= resourceButton.IsSelected ? 1 : -1;
     this.ResourceSelectionMessage                 = $"Select {this.workingNumberOfResourcesToSelect} more resources to drop";
     this.ResourceSelectionConfirmButton.IsEnabled = this.workingNumberOfResourcesToSelect == 0;
 }