Exemple #1
0
        public void MouseReleased(Vector2i mouse)
        {
            var      pos    = window.MapPixelToCoords(mouse, Cardsview);
            Location?target = GetTarget(mouse);

            Console.WriteLine($"{startingLocation }, { target}");
            if (startingLocation == Location.Cards)
            {
                if (selectedCard != null && target != Location.Deck) //check where to place card when mouse is released and if no valid slot is selected then drop the card back to previous spot
                {
                    if (selectedCard.Location == CardLocation.Moving)
                    {
                        selectedCard.Selected = false;
                        selectedCard.Location = CardLocation.Hand;
                        //player1.ResetCardPosition(selectedCard);
                        selectedCard.ResetCard();
                        selectedCard = null;
                        //Console.WriteLine("released");
                        startingLocation = null;

                        //player1.ResetCards();
                    }
                }
                else
                {
                    if (selectedCard != null && target == Location.Deck)
                    {
                        var added = activeDeck.AddCardToSavedDeck(selectedCard);
                        if (added)
                        {
                            cards.Remove(selectedCard);
                            selectedCard.Selected = false;
                            selectedCard.Location = CardLocation.Hand;
                            Database.InsertCardIntoDeck(player, activeDeck, selectedCard);
                            selectedCard = null;
                            SetCardPositions();
                            SetDeckCardPositions();
                        }
                        else
                        {
                            selectedCard.Selected = false;
                            selectedCard.Location = CardLocation.Hand;
                            //player1.ResetCardPosition(selectedCard);
                            selectedCard.ResetCard();
                            selectedCard = null;
                            //Console.WriteLine("released");
                            startingLocation = null;
                        }
                    }
                }
            }
            else
            {
                if (selectedCard != null && target != Location.Cards) //check where to place card when mouse is released and if no valid slot is selected then drop the card back to previous spot
                {
                    if (selectedCard.Location == CardLocation.Moving)
                    {
                        selectedCard.Selected = false;
                        selectedCard.Location = CardLocation.Hand;
                        //player1.ResetCardPosition(selectedCard);
                        selectedCard.ResetCard();
                        selectedCard = null;
                        //Console.WriteLine("released");
                        startingLocation = null;
                        //player1.ResetCards();
                    }
                }
                else
                {
                    if (selectedCard != null && target == Location.Cards)
                    {
                        activeDeck.savedCards.Remove(selectedCard);
                        Database.RemoveCardFromDeck(player, activeDeck, selectedCard);
                        //cards.Add(selectedCard);
                        SetAvailableCards();
                        SetDeckCardPositions();
                        selectedCard = null;
                        //activeDeck.AddCardToSavedDeck(selectedCard);
                        //selectedCard.Selected = false;
                        //selectedCard.Location = CardLocation.Hand;
                        ////player1.ResetCardPosition(selectedCard);
                        ////selectedCard.ResetCard();
                        //selectedCard = null;
                    }
                }
            }
        }