using TMPro; using UnityEngine; using System.Collections; using Unity.VisualScripting; public enum TabletScreen { Word, Mines, SimonSays, MainMenu } 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 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; public void Awake() { SetScreen(TabletScreen.MainMenu); } public void SetScreen(TabletScreen screen) { currentScreen = screen; switch (screen) { case TabletScreen.Word: wordPuzzleSheet.SetActive(true); minesPuzzleSheet.SetActive(false); simonSaysPuzzleSheet.SetActive(false); break; case TabletScreen.Mines: wordPuzzleSheet.SetActive(false); minesPuzzleSheet.SetActive(true); simonSaysPuzzleSheet.SetActive(false); break; case TabletScreen.MainMenu: wordPuzzleSheet.SetActive(false); minesPuzzleSheet.SetActive(false); simonSaysPuzzleSheet.SetActive(false); break; case TabletScreen.SimonSays: wordPuzzleSheet.SetActive(false); minesPuzzleSheet.SetActive(false); simonSaysPuzzleSheet.SetActive(true); break; } } public void SetScreenMines(int gridSize, int bombs, int timeLimitSeconds) { mainMenuSheet.SetActive(false); wordPuzzleSheet.SetActive(false); simonSaysPuzzleSheet.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); 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() { simonSaysPuzzleSheet.SetActive(true); simonSaysGameManager.currentPuzzle = 0; simonSaysGameManager.gameState = SGameState.Uninitialized; mainMenuSheet.SetActive(false); minesPuzzleSheet.SetActive(false); wordPuzzleSheet.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 SetGameState(PuzzleGameState state) { gameState = state; } public void SetDoorTargetText(string text) { targetDoorText.text = text; } public void SetDoorTimeLimitText(string text) { targetDoorTimeLimit.text = text; } }