Some checks failed
Build project / Build for (StandaloneWindows64, 6000.0.37f1) (push) Has been cancelled
Build project / Publish to itch.io (StandaloneLinux64) (push) Has been cancelled
Build project / Publish to itch.io (StandaloneWindows64) (push) Has been cancelled
Build project / Build for (StandaloneLinux64, 6000.0.37f1) (push) Has been cancelled
247 lines
7.9 KiB
C#
247 lines
7.9 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using System.Collections;
|
|
using Unity.VisualScripting;
|
|
public enum TabletScreen {
|
|
Word,
|
|
Mines,
|
|
SimonSays,
|
|
Untangle,
|
|
MainMenu,
|
|
Clear
|
|
}
|
|
|
|
public enum PuzzleGameState {
|
|
Uninitialized,
|
|
Playing,
|
|
Win,
|
|
Lose
|
|
}
|
|
|
|
public class TabletScript : MonoBehaviour
|
|
{
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
public bool puzzleComplete = false;
|
|
[SerializeField] private TextMeshProUGUI targetDoorText = null;
|
|
[SerializeField] private TextMeshProUGUI targetDoorTimeLimit = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// objects containing the interactions for the different puzzles
|
|
[SerializeField] private GameObject minesPuzzleSheet = null;
|
|
[SerializeField] private GameObject wordPuzzleSheet = null;
|
|
[SerializeField] private GameObject simonSaysPuzzleSheet = null;
|
|
[SerializeField] private GameObject untanglePuzzleSheet = null;
|
|
[SerializeField] private GameObject mainMenuSheet = null;
|
|
|
|
|
|
|
|
|
|
public PuzzleGameState gameState = PuzzleGameState.Uninitialized;
|
|
public TabletScreen currentScreen = TabletScreen.MainMenu;
|
|
|
|
// Update is called once per frame
|
|
// void Update()
|
|
// {
|
|
// // if user press enter
|
|
// if (Input.GetKeyDown(KeyCode.Return))
|
|
// {
|
|
// // set puzzleComplete to true
|
|
// puzzleComplete = true;
|
|
// }
|
|
|
|
|
|
// }
|
|
// control script for each puzzle
|
|
[SerializeField] private ControlScript minesControlScript = null;
|
|
[SerializeField] private WordPuzzle wordPuzzleScript = null;
|
|
[SerializeField] private SimonSaysGameManager simonSaysGameManager = null;
|
|
[SerializeField] private UntangleGameManager untangleGameManager = null;
|
|
|
|
|
|
public void Start()
|
|
{
|
|
SetScreen(TabletScreen.Clear);
|
|
// mainMenuSheet.SetActive(false);
|
|
}
|
|
|
|
public void SetScreen(TabletScreen screen)
|
|
{
|
|
// Debug.Log("Setting screen to: " + screen);
|
|
currentScreen = screen;
|
|
switch (screen)
|
|
{
|
|
case TabletScreen.Word:
|
|
wordPuzzleSheet.SetActive(true);
|
|
minesPuzzleSheet.SetActive(false);
|
|
simonSaysPuzzleSheet.SetActive(false);
|
|
untanglePuzzleSheet.SetActive(false);
|
|
break;
|
|
case TabletScreen.Mines:
|
|
wordPuzzleSheet.SetActive(false);
|
|
minesPuzzleSheet.SetActive(true);
|
|
simonSaysPuzzleSheet.SetActive(false);
|
|
untanglePuzzleSheet.SetActive(false);
|
|
break;
|
|
case TabletScreen.SimonSays:
|
|
wordPuzzleSheet.SetActive(false);
|
|
minesPuzzleSheet.SetActive(false);
|
|
simonSaysPuzzleSheet.SetActive(true);
|
|
untanglePuzzleSheet.SetActive(false);
|
|
break;
|
|
case TabletScreen.Untangle:
|
|
wordPuzzleSheet.SetActive(false);
|
|
minesPuzzleSheet.SetActive(false);
|
|
simonSaysPuzzleSheet.SetActive(false);
|
|
untanglePuzzleSheet.SetActive(true);
|
|
break;
|
|
|
|
case TabletScreen.MainMenu:
|
|
wordPuzzleSheet.SetActive(false);
|
|
minesPuzzleSheet.SetActive(false);
|
|
simonSaysPuzzleSheet.SetActive(false);
|
|
untanglePuzzleSheet.SetActive(false);
|
|
mainMenuSheet.SetActive(true);
|
|
break;
|
|
case TabletScreen.Clear:
|
|
wordPuzzleSheet.SetActive(false);
|
|
minesPuzzleSheet.SetActive(false);
|
|
simonSaysPuzzleSheet.SetActive(false);
|
|
untanglePuzzleSheet.SetActive(false);
|
|
mainMenuSheet.SetActive(false);
|
|
break;
|
|
default:
|
|
wordPuzzleSheet.SetActive(false);
|
|
minesPuzzleSheet.SetActive(false);
|
|
simonSaysPuzzleSheet.SetActive(false);
|
|
untanglePuzzleSheet.SetActive(false);
|
|
mainMenuSheet.SetActive(false);
|
|
break;
|
|
|
|
}
|
|
}
|
|
|
|
public void SetScreenMines(int gridSize, int bombs, int timeLimitSeconds)
|
|
{
|
|
mainMenuSheet.SetActive(false);
|
|
wordPuzzleSheet.SetActive(false);
|
|
simonSaysPuzzleSheet.SetActive(false);
|
|
untanglePuzzleSheet.SetActive(false);
|
|
minesPuzzleSheet.SetActive(true);
|
|
|
|
minesControlScript.GridSizeX = gridSize;
|
|
minesControlScript.GridSizeY = gridSize;
|
|
minesControlScript.TotalMines = bombs;
|
|
minesControlScript.timeLimitSeconds = timeLimitSeconds;
|
|
minesControlScript.Restart();
|
|
|
|
StartCoroutine(WaitForPuzzleCompletionMines());
|
|
|
|
}
|
|
|
|
private IEnumerator WaitForPuzzleCompletionMines()
|
|
{
|
|
Debug.Log("Waiting for puzzle completion");
|
|
yield return new WaitUntil(() => minesControlScript.GameState == EGameState.Win);
|
|
|
|
yield return new WaitForSeconds(1.0f);
|
|
|
|
minesControlScript.GameState = EGameState.Uninitialized; // reset the game state to default state
|
|
gameState = PuzzleGameState.Win;
|
|
SetScreen(TabletScreen.MainMenu);
|
|
}
|
|
|
|
|
|
public void SetScreenWord(string word)
|
|
{
|
|
wordPuzzleSheet.SetActive(true);
|
|
wordPuzzleScript.StartGame(word);
|
|
mainMenuSheet.SetActive(false);
|
|
minesPuzzleSheet.SetActive(false);
|
|
simonSaysPuzzleSheet.SetActive(false);
|
|
untanglePuzzleSheet.SetActive(false);
|
|
|
|
StartCoroutine(WaitForPuzzleCompletionWord());
|
|
}
|
|
|
|
private IEnumerator WaitForPuzzleCompletionWord()
|
|
{
|
|
yield return new WaitUntil(() => wordPuzzleScript.gameState == WGameState.Win);
|
|
|
|
yield return new WaitForSeconds(1.0f);
|
|
|
|
wordPuzzleScript.gameState = WGameState.Uninitialized; // reset the game state to default state
|
|
wordPuzzleScript.ResetPuzzle();
|
|
gameState = PuzzleGameState.Win;
|
|
SetScreen(TabletScreen.MainMenu);
|
|
}
|
|
|
|
public void SetScreenSimonSays(int simonSaysPuzzleIndex)
|
|
{
|
|
simonSaysPuzzleSheet.SetActive(true);
|
|
simonSaysGameManager.currentPuzzle = simonSaysPuzzleIndex;
|
|
simonSaysGameManager.gameState = SGameState.Uninitialized;
|
|
simonSaysGameManager.StartGame();
|
|
mainMenuSheet.SetActive(false);
|
|
minesPuzzleSheet.SetActive(false);
|
|
wordPuzzleSheet.SetActive(false);
|
|
untanglePuzzleSheet.SetActive(false);
|
|
|
|
StartCoroutine(WaitForPuzzleCompletionSimonSays());
|
|
}
|
|
|
|
private IEnumerator WaitForPuzzleCompletionSimonSays()
|
|
{
|
|
yield return new WaitUntil(() => simonSaysGameManager.gameState == SGameState.Win);
|
|
|
|
yield return new WaitForSeconds(1.0f);
|
|
|
|
simonSaysGameManager.gameState = SGameState.Uninitialized; // reset the game state to default state
|
|
gameState = PuzzleGameState.Win;
|
|
SetScreen(TabletScreen.MainMenu);
|
|
}
|
|
|
|
public void SetScreenUntangle(int pointCount)
|
|
{
|
|
untanglePuzzleSheet.SetActive(true);
|
|
untangleGameManager.pointCount = pointCount;
|
|
untangleGameManager.StartGame();
|
|
mainMenuSheet.SetActive(false);
|
|
minesPuzzleSheet.SetActive(false);
|
|
wordPuzzleSheet.SetActive(false);
|
|
simonSaysPuzzleSheet.SetActive(false);
|
|
|
|
StartCoroutine(WaitForPuzzleCompletionUntangle());
|
|
}
|
|
|
|
private IEnumerator WaitForPuzzleCompletionUntangle()
|
|
{
|
|
yield return new WaitUntil(() => untangleGameManager.gameState == UGameState.Win);
|
|
|
|
yield return new WaitForSeconds(1.0f);
|
|
|
|
untangleGameManager.gameState = UGameState.Uninitialized; // reset the game state to default state
|
|
gameState = PuzzleGameState.Win;
|
|
SetScreen(TabletScreen.MainMenu);
|
|
}
|
|
|
|
public void SetGameState(PuzzleGameState state)
|
|
{
|
|
gameState = state;
|
|
}
|
|
|
|
public void SetDoorTargetText(string text)
|
|
{
|
|
targetDoorText.text = text;
|
|
|
|
}
|
|
public void SetDoorTimeLimitText(string text)
|
|
{
|
|
targetDoorTimeLimit.text = text;
|
|
}
|
|
}
|