Skip to content

Commit 20f15ce

Browse files
committed
Add logs and redundancy to GameManager.cs blockchain calls
1 parent 1927139 commit 20f15ce

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

‎unity-game/Assets/Scripts/GameManager.cs‎

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ public class GameManager : MonoBehaviour {
4242

4343
// This is public so the play button can see it.
4444
public async void StartGame() {
45+
// Deploy a new burner account for this game session
46+
// You should disable this on a actual game
47+
try {
48+
Debug.Log("Creating new burner account for this game session...");
49+
currentAccount = await burnerManager.DeployBurner();
50+
Debug.Log($"Created new burner account: {currentAccount.Address.Hex()}");
51+
} catch (System.Exception e) {
52+
Debug.LogError($"Failed to create burner account: {e.Message}");
53+
// Fall back to master account if burner creation fails
54+
currentAccount = masterAccount;
55+
}
56+
4557
// Hide/show the UI elements we don't/do want to see.
4658
playButton.SetActive(false);
4759
outOfTimeText.SetActive(false);
@@ -68,12 +80,14 @@ public async void StartGame() {
6880
}
6981
}
7082

71-
public void GameOver(int type) {
83+
public async void GameOver(int type) {
7284
// Show the message.
7385
if (type == 0) {
7486
outOfTimeText.SetActive(true);
87+
Debug.Log("Game over: Out of time");
7588
} else {
7689
bombText.SetActive(true);
90+
Debug.Log("Game over: Hit a bomb");
7791
}
7892
// Hide all moles.
7993
foreach (Mole mole in moles) {
@@ -83,11 +97,22 @@ public void GameOver(int type) {
8397
playing = false;
8498
playButton.SetActive(true);
8599

86-
// Blockchain game_over call
100+
// Blockchain game_over call with proper error handling
87101
if (actionsSystem != null && currentAccount != null)
88102
{
89-
byte reasonByte = (byte)type;
90-
_ = actionsSystem.game_over(currentAccount, (uint)score, reasonByte);
103+
try {
104+
byte reasonByte = (byte)type;
105+
Debug.Log($"Sending game_over for account {currentAccount.Address.Hex()} with score {score}");
106+
107+
// Add a small delay to allow other pending transactions to complete
108+
await Task.Delay(500);
109+
110+
await actionsSystem.game_over(currentAccount, (uint)score, reasonByte);
111+
Debug.Log("Game session closed successfully on blockchain");
112+
}
113+
catch (System.Exception e) {
114+
Debug.LogError($"Blockchain game_over failed: {e.Message}");
115+
}
91116
}
92117
}
93118

0 commit comments

Comments
 (0)