/// <summary> /// Checks which square a user has selected. /// </summary> /// <param name="player">The player who makes the selection.</param> /// <param name="point">The location of the player's cursor.</param> /// <param name="rect">The rectangle the user is hovering over.</param> public void CheckSelect(Player player, Point point, Rectangle rect) { // Iterate through each button... foreach (Rectangle button in buttons) { int index = (int)button.Tag; // Determine which button matches the one passed in... if (!selectedButtons.Contains(index)) { if (button == rect) { if (IsOver(button, point)) { // If it's available, select that colour for the current player. bool canBeChosen = true; foreach(Player p in players) { if (p.PlayerColour == button.Fill) { canBeChosen = false; } } if (canBeChosen) { ButtonSelected(button, player); player.PlayerColour = button.Fill; if (player.Name == "player1") { playerOneArea.Background = button.Fill; } else { playerTwoArea.Background = button.Fill; } } } } } } }
/// <summary> /// Marks a button as having been selected by the given player. /// </summary> /// <param name="button">The button to highlight.</param> /// <param name="player">The player who selected it.</param> private void ButtonSelected(Rectangle button, Player player) { foreach (Rectangle rect in buttons) { if (rect.Fill == player.PlayerColour) { ButtonNormal(rect); break; } } button.Stroke = Brushes.BlanchedAlmond; button.StrokeThickness = 10; }
/// <summary> /// Resets the users for the ColourPicker. /// </summary> /// <param name="playerToRemove"></param> private void ResetUser(Player playerToRemove) { foreach (Rectangle button in buttons) { if (button.Fill == playerToRemove.PlayerColour) { ButtonNormal(button); break; } } if (playerToRemove.Name == "player1") { //clear out any specifics } else if (playerToRemove.Name == "player2") { //clear out any specifics for that player } }