public void PlayCard(PlayingCard toPlay, Coordinate onCoordinate)
 {
     toPlay.SetCoordinate(onCoordinate);
     toPlay.transform.SetParent(transform, true);
     PlayedCards.Add(toPlay);
     CurrentPlayField.SetCard(toPlay.RepresentingCard, onCoordinate);
 }
    public void GetNewHypotheticalPlacementEffects(PlayingCard forCard, Coordinate onCoordinate,
                                                   out HashSet <PlayingCard> newHypotheticalIncompleteableCards, out HashSet <PlayingCard> newHypotheticalHappyCards)
    {
        newHypotheticalIncompleteableCards = new HashSet <PlayingCard>();
        newHypotheticalHappyCards          = new HashSet <PlayingCard>();

        PlayFieldData hypotheticalPlayField = CurrentPlayField.CloneData();

        hypotheticalPlayField.SetCard(forCard.RepresentingCard, onCoordinate);

        IEnumerable <Coordinate> newHypotheticalIncompleteableCoordinates = hypotheticalPlayField.GetIncompleteableCoordinates().Except(CurrentPlayField.GetIncompleteableCoordinates());
        IEnumerable <Coordinate> newHypotheticalHappyCoordinates          = hypotheticalPlayField.GetHappyCoordinates().Except(CurrentPlayField.GetHappyCoordinates());

        newHypotheticalIncompleteableCards = new HashSet <PlayingCard>(PlayedCards.Where(card => newHypotheticalIncompleteableCoordinates.Contains(card.OnCoordinate)));
        newHypotheticalHappyCards          = new HashSet <PlayingCard>(PlayedCards.Where(card => newHypotheticalHappyCoordinates.Contains(card.OnCoordinate)));

        if (newHypotheticalIncompleteableCoordinates.Contains(onCoordinate))
        {
            newHypotheticalIncompleteableCards.Add(forCard);
        }

        if (newHypotheticalHappyCoordinates.Contains(onCoordinate))
        {
            newHypotheticalHappyCards.Add(forCard);
        }
    }
Example #3
0
    void HighlightHand()
    {
        Color c = CurrentPlayField.GetComponent <Image>().color;

        c.a = alphaHighlight;
        CurrentPlayField.GetComponent <Image>().color = c;
    }
    public void SeedInitialCard(CardData forCard)
    {
        PlayingCard newCard = GeneratePlayingCard(forCard);

        newCard.SetCoordinate(new Coordinate(0, 0), DegreesOfSpeed.Instantly);
        PlayedCards.Add(newCard);
        CurrentPlayField.SetCard(forCard, new Coordinate(0, 0));
    }
    public bool NoMovesArePossible(List <PlayingCard> hand)
    {
        if (PlayableSpots.Count == 0)
        {
            Debug.Log("There are no valid playable spaces, so no moves are possible");
            return(true);
        }

        return(!CurrentPlayField.AreAnyMovesPossible(hand.Select(card => card.RepresentingCard).ToList()));
    }
    public HashSet <PlayingCard> GetNewlyHappyCards()
    {
        HashSet <PlayingCard> newCards         = new HashSet <PlayingCard>();
        HashSet <Coordinate>  happyCoordinates = CurrentPlayField.GetHappyCoordinates();

        foreach (PlayingCard currentCard in PlayedCards.Where(card => happyCoordinates.Contains(card.OnCoordinate)))
        {
            if (!currentCard.IsHappy)
            {
                newCards.Add(currentCard);
            }
        }

        return(newCards);
    }
    public HashSet <PlayingCard> GetNewlyNotCompleteableCards()
    {
        HashSet <PlayingCard> newCards = new HashSet <PlayingCard>();
        HashSet <Coordinate>  incompleteableCoordinates = CurrentPlayField.GetIncompleteableCoordinates();

        foreach (PlayingCard currentCard in PlayedCards.Where(card => incompleteableCoordinates.Contains(card.OnCoordinate)))
        {
            if (!currentCard.CannotBeCompleted)
            {
                newCards.Add(currentCard);
            }
        }

        return(newCards);
    }
    public void UpdateCardVisuals()
    {
        foreach (PlayingCard currentCard in GetNewlyHappyCards())
        {
            currentCard.SetHappiness(true);
        }

        foreach (PlayingCard currentCard in GetNewlyNotCompleteableCards())
        {
            currentCard.SetIncompleteness(true);
        }

        foreach (PlayingCard currentCard in GetIncompleteCards())
        {
            currentCard.SetNeighborCount(CurrentPlayField.OccuppiedNeighborsAtCoordinate(currentCard.OnCoordinate));
        }
    }
    public void SetPlayableSpaces()
    {
        foreach (PlayableSpot spot in PlayableSpots)
        {
            ObjectPooler.ReturnObject <PlayableSpot>(spot);
        }

        PlayableSpots.Clear();

        HashSet <Coordinate> validPlayableSpaces = CurrentPlayField.GetValidPlayableSpaces();

        foreach (Coordinate curCoordinate in validPlayableSpaces)
        {
            GeneratePlayableSpot(curCoordinate);
        }

        UpdateValidityOfPlayableSpots(null);
    }
    public bool TryRemoveCardAtCoordinate(Coordinate toRemove, out PlayingCard foundCard)
    {
        foundCard = PlayedCards.FirstOrDefault(card => card.OnCoordinate == toRemove);

        if (foundCard == null)
        {
            return(false);
        }

        PlayedCards.Remove(foundCard);
        CurrentPlayField.RemoveCard(toRemove);

        HashSet <Coordinate> playableSpaces = CurrentPlayField.GetValidPlayableSpaces();

        foreach (PlayingCard card in PlayedCards)
        {
            card.SetHappiness(CurrentPlayField.ShouldCoordinateBeHappy(card.OnCoordinate));
            card.SetIncompleteness(CurrentPlayField.ShouldCoordinateBeIncompletable(card.OnCoordinate));
        }

        SetPlayableSpaces();

        return(true);
    }
 public bool IsSpotValidForCard(PlayingCard forCard, Coordinate onCoordinate)
 {
     return(CurrentPlayField.IsSpotValidForCard(forCard.RepresentingCard, onCoordinate));
 }