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(); }
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"); }
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); } }