/// <summary> /// Adds a card to the hand /// </summary> /// <param name="card">The card to be added to the hand</param> public void AddCard(Card card) { _cards.Add(card); // Be a tidy kiwi this.Sort(); }
/// <summary> /// Checks if a card in the player's hand has been clicked. /// if it has, the appropriate card is selected. /// </summary> /// <param name="hand">The hand to check</param> /// <param name="x">The x position of the cursor</param> /// <param name="y">The y position of the cursor</param> /// <returns>Whether or not a card was selected</returns> public bool CheckCardInHandForClick(Hand hand, int x, int y) { Contract.Requires(x >= 0 && y >= 0, "x and y values must be positive as they are co-ordinates"); for (int i = 0; i < hand.Cards.Count; i++) { if (hand.Cards[i].MouseOn(x, y)) { if (selectedCard != null) selectedCard.Selected = false; // Unselect current selected card selectedCard = hand.Cards[i]; // Set selectedCard to the card that was clicked hand.Cards[i].Selected = true; // Set the card's selected property this.Invalidate(); // Redraw everything return true; // A card in the hand was at the cursor } } return false; // The cursor was not on a card }
/// <summary> /// Creates a new move /// </summary> /// <param name="cardToPlay">The card to be played</param> /// <param name="slotToPlay">The slot to play into</param> public Move(Card cardToPlay, CardSlot slotToPlay) { CardToPlay = cardToPlay; SlotToPlay = slotToPlay; }
/// <summary> /// Sets this cardslot's current card /// </summary> /// <param name="c">The card to place in this cardslot</param> public void SetCard(Card c) { CurrentCard = c; CurrentCard.Move(this.X, this.Y); }
/// <summary> /// Handle all click events /// </summary> private void Form1_MouseClick(object sender, MouseEventArgs e) { if (!GameLocked) { // Try select a card from the player's hand for (int i = 0; i < human.Hand.Cards.Count; i++) { if (human.Hand.Cards[i].MouseOn(e.X, e.Y)) { if (selectedCard != null) selectedCard.Selected = false; // Unselect current selected card selectedCard = human.Hand.Cards[i]; // Set selectedCard to the card that was clicked human.Hand.Cards[i].Selected = true; // Set the card's selected property this.Invalidate(); // Redraw everything } } // A card has already been selected if (selectedCard != null) { // If we're over a slot if (CursorIsOnSlot(e.X, e.Y)) { // Get that slot CardSlot selectedSlot = GetSlotAt(e.X, e.Y); if (WhoseTurn == human) { Output("Human played " + selectedCard + " to " + selectedSlot); if (Play(new Move(selectedCard, selectedSlot), human)) // Play the move { Output("Robot's turn.."); WhoseTurn = robot; // It's the robot's turn if the play was valid } } if (WhoseTurn == robot) { // Play the robot's turn Move robotMove = robot.GetMove(tiles, deck, discardPile); Output("Robot played " + robotMove.CardToPlay + " to " + robotMove.SlotToPlay); if (Play(robotMove, robot)) // Play the move { Output("Human's turn.."); WhoseTurn = human; // It's the human's turn if the play was valid } else throw new Exception("The robot tried to make an invalid move"); } selectedCard.Selected = false; // Remove selected colours selectedCard = null; // Card is no longer selected this.Invalidate(); return; } } } // Select a card in the hand if we're over one // If not, deselect any selected cards if (!CheckCardInHandForClick(human.Hand, e.X, e.Y) && selectedCard != null) { selectedCard.Selected = false; selectedCard = null; // No card was selected this time, unselect anything currently selected this.Invalidate(); } }
/// <summary> /// Checks if this side of the tile has a spare slot for this colour. /// e.g. If the number of Red Cards is equal to the number of Red Cubes, this returns false /// because the player needs to fill the other colours. /// </summary> /// <param name="card">The card to check for</param> /// <param name="slot">The slot to check against</param> /// <returns>The validity of the move</returns> public bool HasEmptySlotWithMatchingCube(Card card, CardSlot slot) { ColouredObject.Colours colour = card.Colour; CardSlot.Position position = slot.SlotPosition; return HasEmptySlotWithMatchingCube(colour, position); }
/// <summary> /// Removes a card from the hand /// </summary> /// <param name="c">The card to be removed from the hand</param> public void RemoveCard(Card c) { _cards.Remove(c); }