Exemplo n.º 1
0
    public void UndoButton()
    {
        if (GameActions.Count == 0)
        {
            Debug.Log("Could not undo, there were no actions.");
            return;
        }

        if (GameActions.Peek().ActionUndoType == UndoType.CannotUndo)
        {
            Debug.Log("Cannot undo the next action");
            Debug.Log(GameActions.Peek().GetActionText());
            return;
        }

        GameAction previousAction = GameActions.Pop();

        UndoAction(previousAction);

        if (previousAction.ActionUndoType == UndoType.ContinueAfter)
        {
            UndoButton();
        }

        CameraManagerInstance.UpdateCamera(ActivePlayField);
        ResetCardsInHandPosition();
        UpdateScoreLabels();
        ActivePlayField.UpdateCardVisuals();
    }
Exemplo n.º 2
0
    void NewPlayingField(bool logAction = true)
    {
        if (deck.Count == 0)
        {
            Debug.Log("Trying to make a new playing field, but the deck is empty");
            return;
        }

        if (ActivePlayField != null)
        {
            // For now, we're going to just... jettison the PlayedCards to space.
            // Need to figure out something more, ah, elegant than that
            Debug.Log("Moving the existing playing field far out of the way");
            ActivePlayField.transform.position = (Vector3.right * 1000 + Vector3.up * 500);
            CameraManagerInstance.ResetCamera();
        }

        CardData seedCard = DrawCard();

        if (logAction && ActivePlayField != null)
        {
            GameActions.Push(GameAction.FromNewPlayingField(seedCard, ActivePlayField));
            previousPlayfieldIncompleteCards    += ActivePlayField.GetIncompleteCards().Count;
            previousPlayfieldTotalFaceValue     += ActivePlayField.GetIncompleteCards().Sum(card => card.RepresentingCard.FaceValue);
            previousPlayfieldSatisfiedCount     += ActivePlayField.GetHappyCards().Count;
            previousPlayfieldSatisfiedFaceValue += ActivePlayField.GetHappyCards().Sum(card => card.RepresentingCard.FaceValue);
        }

        ActivePlayField = ObjectPooler.GetObject <PlayFieldRuntime>(PlayFieldRuntimePF, transform);
        ActivePlayField.SeedInitialCard(seedCard);

        ActivePlayField.UpdateCardVisuals();
        ActivePlayField.SetPlayableSpaces();
        UpdateScoreLabels();
    }
Exemplo n.º 3
0
    public bool TryPlayerPlaysCard(PlayingCard playedCard, Coordinate toCoordinate)
    {
        if (!ActivePlayField.IsSpotValidForCard(playedCard, toCoordinate))
        {
            return(false);
        }

        cardsInHand.Remove(playedCard);
        ActivePlayField.PlayCard(playedCard, toCoordinate);

        GameActions.Push(GameAction.FromCardPlayed(playedCard.RepresentingCard, toCoordinate));

        CameraManagerInstance.UpdateCamera(ActivePlayField);

        ActivePlayField.UpdateCardVisuals();
        ActivePlayField.SetPlayableSpaces();
        UpdateScoreLabels();

        DealToPlayer();

        if (ActivePlayField.NoMovesArePossible(cardsInHand))
        {
            NewPlayingField();
        }

        ResetCardsInHandPosition();

        return(true);
    }
Exemplo n.º 4
0
    void UpdateScoreLabels()
    {
        TotalCardFaceValue.text   = (previousPlayfieldTotalFaceValue + ActivePlayField.GetIncompleteCards().Sum(card => card.RepresentingCard.FaceValue)).ToString();
        IncompleteCardsValue.text = (previousPlayfieldIncompleteCards + ActivePlayField.GetIncompleteCards().Count).ToString();

        SatisfiedCountValue.text = ((float)(previousPlayfieldSatisfiedCount + ActivePlayField.GetHappyCards().Count) / (float)totalDeckSize).ToString("P0");
        SatisfiedFaceValue.text  = ((float)(previousPlayfieldSatisfiedFaceValue + ActivePlayField.GetHappyCards().Sum(card => card.RepresentingCard.FaceValue)) / (float)totalDeckFaceValue).ToString("P0");
    }
Exemplo n.º 5
0
    void UndoAction(GameAction action)
    {
        if (action.CardPlayed.HasValue)
        {
            PlayingCard foundCard;

            if (!ActivePlayField.TryRemoveCardAtCoordinate(action.CoordinatePlayedOn.Value, out foundCard))
            {
                Debug.LogError("Tried to remove a card from the active field, but it doesn't exist");
            }
            else
            {
                cardsInHand.Add(foundCard);
                foundCard.Reset();
                ResetCardsInHandPosition();
            }
        }

        if (action.CardDrawn.HasValue)
        {
            PlayingCard matchingCardInHand = cardsInHand.FirstOrDefault(card => card.RepresentingCard == action.CardDrawn.Value);

            if (matchingCardInHand == null)
            {
                Debug.LogError("Tried to remove a card from hand, but it doesn't exist");
            }
            else
            {
                cardsInHand.Remove(matchingCardInHand);
                ObjectPooler.ReturnObject(matchingCardInHand);

                deck.Push(action.CardDrawn.Value);
                DeckCountLabel.text = $"x{deck.Count}";
                ResetCardsInHandPosition();
            }
        }

        if (action.SeedCard.HasValue)
        {
            PlayingCard foundCard;

            if (!ActivePlayField.TryRemoveCardAtCoordinate(action.CoordinatePlayedOn.Value, out foundCard))
            {
                Debug.LogError("Tried to remove a card from the active field, but it doesn't exist");
            }
            else
            {
                ObjectPooler.ReturnObject(foundCard);

                deck.Push(action.SeedCard.Value);
                DeckCountLabel.text = $"x{deck.Count}";
            }
        }

        if (action.PreviousPlayfield != null)
        {
            ObjectPooler.ReturnObject(ActivePlayField);
            ActivePlayField = action.PreviousPlayfield;
            ActivePlayField.transform.position   = Vector3.zero;
            previousPlayfieldIncompleteCards    -= ActivePlayField.GetIncompleteCards().Count;
            previousPlayfieldTotalFaceValue     -= ActivePlayField.GetIncompleteCards().Sum(card => card.RepresentingCard.FaceValue);
            previousPlayfieldSatisfiedCount     -= ActivePlayField.GetHappyCards().Count;
            previousPlayfieldSatisfiedFaceValue -= ActivePlayField.GetHappyCards().Sum(card => card.RepresentingCard.FaceValue);
        }
    }
Exemplo n.º 6
0
 public void UpdateValidityOfPlayableSpots(PlayingCard forCard)
 {
     ActivePlayField.UpdateValidityOfPlayableSpots(forCard);
 }