Skip to content

Commit 2247bfb

Browse files
Updated CardClasses.cs and PlantAfflictions.cs to implement Value setter in ICard interface and decrement card value daily in TickDay method for MealyBugs affliction.
Updated `ScoreManager`, `CardGameMaster`, and `TurnController` scripts: - Displayed money goal in the UI. - Added `GetMoneys` method for accessing current moneys. - Implemented level-based money goals and win screen functionality. Signed-off-by: donovan <dmontoya@unity.edu>
1 parent f91f365 commit 2247bfb

5 files changed

Lines changed: 58 additions & 6 deletions

File tree

Card Core/CardGameMaster.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
using JetBrains.Annotations;
44
using TMPro;
55
using UnityEngine;
6+
using UnityEngine.EventSystems;
67
using UnityEngine.Rendering;
7-
using UnityEngine.Serialization;
88

99
namespace _project.Scripts.Card_Core
1010
{
@@ -26,10 +26,12 @@ public class CardGameMaster : MonoBehaviour
2626
public ScoreManager scoreManager;
2727
public TurnController turnController;
2828
public Volume postProcessVolume;
29+
public EventSystem eventSystem;
2930
public bool isInspecting;
3031

31-
[FormerlySerializedAs("scoreText")] [CanBeNull] public TextMeshPro MoneysText;
32+
[CanBeNull] public TextMeshPro moneysText;
3233
[CanBeNull] public TextMeshPro turnText;
34+
[CanBeNull] public TextMeshPro roundText;
3335
[CanBeNull] public TextMeshPro treatmentCostText;
3436
[CanBeNull] public TextMeshPro potentialProfitText;
3537

Card Core/ScoreManager.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ public void ResetMoneys()
3636

3737
private static void UpdateMoneysText(int modifier = 0)
3838
{
39-
if (CardGameMaster.Instance.MoneysText)
40-
CardGameMaster.Instance.MoneysText.text = "Moneys: " + "$" + (Moneys + modifier);
39+
if (CardGameMaster.Instance.moneysText)
40+
CardGameMaster.Instance.moneysText.text = "Moneys: " + "$" + (Moneys + modifier)
41+
+ "/" + CardGameMaster.Instance.turnController.moneyGoal;
4142
}
4243

4344
private static void UpdateCostText(int totalCost) { TreatmentCostText.text = "Potential Loss: " + totalCost; }
@@ -72,6 +73,8 @@ public int CalculateScore()
7273
UpdateProfitText(0);
7374
return Moneys;
7475
}
76+
77+
public static int GetMoneys(){return Moneys;}
7578

7679
public int CalculateTreatmentCost()
7780
{

Card Core/TurnController.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@
44
using System.Linq;
55
using _project.Scripts.Classes;
66
using _project.Scripts.Core;
7+
using TMPro;
78
using UnityEngine;
9+
using UnityEngine.InputSystem.UI;
810
using Random = System.Random;
911

1012
namespace _project.Scripts.Card_Core
1113
{
1214
public class TurnController : MonoBehaviour
1315
{
1416
public GameObject lostGameObjects;
17+
public GameObject winScreen;
1518
public int turnCount = 4;
19+
public int level;
20+
public int moneyGoal;
1621
public int currentTurn;
1722
public int currentRound;
1823
public bool canClickEnd;
@@ -39,6 +44,13 @@ private void Awake()
3944

4045
private void Start()
4146
{
47+
moneyGoal = level switch
48+
{
49+
0 => 20,
50+
1 => 100,
51+
_ => moneyGoal
52+
};
53+
4254
_scoreManager.ResetMoneys();
4355
StartCoroutine(BeginTurnSequence());
4456
}
@@ -80,6 +92,8 @@ private void Update()
8092
{
8193
if (CardGameMaster.Instance.turnText)
8294
CardGameMaster.Instance.turnText.text = "Turn: " + currentTurn + "/" + turnCount;
95+
if (CardGameMaster.Instance.roundText)
96+
CardGameMaster.Instance.roundText.text = "Round: " + currentRound;
8397
}
8498

8599

@@ -109,6 +123,13 @@ private void Update()
109123
public void EndTurn()
110124
{
111125
if (_deckManager.updatingActionDisplay || !canClickEnd) return;
126+
127+
if (ScoreManager.GetMoneys() >= moneyGoal)
128+
{
129+
currentTurn++;
130+
EndLevel();
131+
return;
132+
}
112133

113134
// If we're ready for a new round, call setup and return
114135
if (newRoundReady)
@@ -327,6 +348,21 @@ private IEnumerator EndRound(float delayTime = 2f)
327348
}
328349
}
329350

351+
private void EndLevel()
352+
{
353+
winScreen.gameObject.SetActive(true);
354+
CardGameMaster.Instance.eventSystem.GetComponent<InputSystemUIInputModule>().enabled = true;
355+
winScreen.gameObject.GetComponentInChildren<TextMeshProUGUI>().text =
356+
"Good job! You beat level 1 in " + currentRound + " rounds. That's [excellent! / pretty good / average / " +
357+
"... well, it's something. Maybe play it again and see if you can do better!] " +
358+
"This game is still in development, so check back in for new levels." +
359+
" If you're interested in Integrated Pest Management as a subject," +
360+
" or in helping us develop the game further," +
361+
" sign up for Unity Environmental University's Integrated Pest Management course. " +
362+
"We're inviting students to help make this game as part of their schoolwork." +
363+
" Thank you for playing; we hope to see you again soon!";
364+
}
365+
330366
public void ResetGame()
331367
{
332368
currentRound = 0;

Classes/CardClasses.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
using System;
12
using System.Collections.Generic;
23
using _project.Scripts.Core;
34
using JetBrains.Annotations;
45
using UnityEngine;
6+
using Random = UnityEngine.Random;
57

68
// ReSharper disable UnusedAutoPropertyAccessor.Global
79

@@ -11,7 +13,12 @@ public interface ICard
1113
{
1214
string Name { get; }
1315
string Description => null;
14-
int? Value => null;
16+
int? Value
17+
{
18+
get => null;
19+
set => throw new NotImplementedException();
20+
}
21+
1522
PlantAfflictions.IAffliction Affliction => null;
1623
PlantAfflictions.ITreatment Treatment => null;
1724
GameObject Prefab => null;

Classes/PlantAfflictions.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ public void TreatWith(ITreatment treatment, PlantController plant)
102102
if (treatment.Name is "SoapyWater" or "Panacea") plant.RemoveAffliction(this);
103103
}
104104

105-
public void TickDay() { }
105+
public void TickDay()
106+
{
107+
var card = GetCard();
108+
card!.Value += -1;
109+
}
106110
public ICard GetCard() { return new MealyBugsCard(); }
107111
}
108112

0 commit comments

Comments
 (0)