fixed wordle
Some checks failed
Build project / Build for (StandaloneWindows64, 6000.0.37f1) (push) Waiting to run
Build project / Publish to itch.io (StandaloneLinux64) (push) Blocked by required conditions
Build project / Publish to itch.io (StandaloneWindows64) (push) Blocked by required conditions
Build project / Build for (StandaloneLinux64, 6000.0.37f1) (push) Has been cancelled

This commit is contained in:
nlevin6 2025-03-29 23:50:49 -04:00
parent 3288b328d8
commit cba7033371
4 changed files with 139 additions and 65 deletions

View File

@ -0,0 +1,24 @@
using UnityEngine;
using UnityEngine.EventSystems;
using TMPro;
public class TabletToggle : MonoBehaviour
{
public GameObject tablet;
void Update()
{
if (Input.GetKeyDown(KeyCode.T))
{
TMP_InputField inputField = null;
if (EventSystem.current != null && EventSystem.current.currentSelectedGameObject != null)
{
inputField = EventSystem.current.currentSelectedGameObject.GetComponent<TMP_InputField>();
}
if (inputField != null && inputField.isFocused)
return;
tablet.SetActive(!tablet.activeSelf);
}
}
}

View File

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 1f363690cf70e6449a55d819bd9503b6

View File

@ -17,11 +17,9 @@ public enum WGameState
public class WordPuzzle : MonoBehaviour public class WordPuzzle : MonoBehaviour
{ {
private TMP_Text[] allLetterTexts; private TMP_Text[] allLetterTexts;
private List<TMP_Text> usedLetterTexts = new List<TMP_Text>();
private List<string> words = new List<string>(); private List<string> words = new List<string>();
private int currentCount; private int currentCount;
private int currentSubmit = 0; private int currentSubmit = 0;
public GameObject congratulations; public GameObject congratulations;
public GameObject retry; public GameObject retry;
public TMP_Text retryText; public TMP_Text retryText;
@ -30,7 +28,6 @@ public class WordPuzzle : MonoBehaviour
public Color wrongColor = Color.red; public Color wrongColor = Color.red;
public string currentWord = string.Empty; public string currentWord = string.Empty;
public WGameState gameState = WGameState.Uninitialized; public WGameState gameState = WGameState.Uninitialized;
[SerializeField] private TextAsset textAsset = null; [SerializeField] private TextAsset textAsset = null;
public AudioClip loseSound; public AudioClip loseSound;
public AudioClip winSound; public AudioClip winSound;
@ -40,15 +37,14 @@ public class WordPuzzle : MonoBehaviour
allLetterTexts = GetComponentsInChildren<TMP_Text>(); allLetterTexts = GetComponentsInChildren<TMP_Text>();
foreach (var text in allLetterTexts) foreach (var text in allLetterTexts)
{ {
text.text = string.Empty; text.text = "";
text.color = Color.white;
} }
words = Regex.Split(textAsset.text, Environment.NewLine)
words = Regex.Split(textAsset.text, Environment.NewLine).ToList(); .Where(x => !string.IsNullOrEmpty(x))
if (string.IsNullOrEmpty(currentWord)) { .Select(x => x.Trim().ToLower())
currentWord = words[UnityEngine.Random.Range(0, words.Count)]; .ToList();
Debug.Log("Chosen random word: " + currentWord); ResetPuzzle();
}
gameState = WGameState.Uninitialized;
} }
private void Update() private void Update()
@ -89,76 +85,78 @@ public class WordPuzzle : MonoBehaviour
public void StartGame(string overrideWord) public void StartGame(string overrideWord)
{ {
currentWord = overrideWord; currentWord = overrideWord.ToLower();
ResetPuzzle(); ResetPuzzle();
} }
private void RemoveChar() private void RemoveChar()
{ {
if (!usedLetterTexts.Any() || currentCount <= 0) if (currentCount <= 0) return;
return; int index = currentSubmit * 5 + (currentCount - 1);
if (index < 0 || index >= allLetterTexts.Length) return;
usedLetterTexts.Last().text = string.Empty; allLetterTexts[index].text = "";
usedLetterTexts.RemoveAt(usedLetterTexts.Count - 1); allLetterTexts[index].color = Color.white;
currentCount--; currentCount--;
} }
private void DoKeyPress(char character) private void DoKeyPress(char character)
{ {
if (usedLetterTexts.Count >= allLetterTexts.Length || currentCount >= 5) if (currentCount >= 5) return;
return; int index = currentSubmit * 5 + currentCount;
if (index < allLetterTexts.Length)
var currentText = allLetterTexts[usedLetterTexts.Count]; {
currentText.text = character.ToString(); allLetterTexts[index].text = character.ToString();
usedLetterTexts.Add(currentText); currentCount++;
currentCount++; if (currentCount == 5)
{
SubmitButtonClick();
}
}
} }
private void SubmitButtonClick() private void SubmitButtonClick()
{ {
if (currentCount != 5) if (currentCount != 5) return;
return; string submittedWord = "";
for (int i = currentSubmit * 5; i < currentSubmit * 5 + 5; i++)
var submittedWord = string.Empty;
int ii = 0;
for (int i = 0 + (currentSubmit * 5); i < usedLetterTexts.Count; i++)
{ {
TMP_Text texts = usedLetterTexts[i]; submittedWord += allLetterTexts[i].text;
var textsChar = char.Parse(texts.text);
submittedWord += textsChar;
texts.color = wrongColor;
if (currentWord.Contains(textsChar))
{
texts.color = inWordColor;
if (textsChar == currentWord[ii])
texts.color = perfectMatchColor;
}
ii++;
} }
submittedWord = submittedWord.ToLower();
if (words.Contains(submittedWord)) if (!words.Contains(submittedWord))
{ {
if(submittedWord == currentWord) for (int i = currentSubmit * 5; i < currentSubmit * 5 + 5; i++)
{ {
congratulations.SetActive(true); allLetterTexts[i].text = "";
SetGameState(WGameState.Win); allLetterTexts[i].color = Color.white;
SoundFXManager.instance.PlaySound(winSound, transform, 1.0f);
return;
} }
currentSubmit++;
currentCount = 0; currentCount = 0;
return;
} }
else for (int i = currentSubmit * 5; i < currentSubmit * 5 + 5; i++)
{ {
for (int i = 0 + (currentSubmit * 5); i < usedLetterTexts.Count; i++) char letter = char.ToLower(allLetterTexts[i].text[0]);
allLetterTexts[i].color = wrongColor;
if (currentWord.Contains(letter))
{ {
TMP_Text texts = usedLetterTexts[i]; allLetterTexts[i].color = inWordColor;
texts.color = Color.white; int pos = i - (currentSubmit * 5);
if (letter == currentWord[pos])
{
allLetterTexts[i].color = perfectMatchColor;
}
} }
} }
if (submittedWord == currentWord)
if(currentSubmit == 6) {
congratulations.SetActive(true);
SetGameState(WGameState.Win);
SoundFXManager.instance.PlaySound(winSound, transform, 1.0f);
return;
}
currentSubmit++;
currentCount = 0;
if (currentSubmit == 6)
{ {
retry.SetActive(true); retry.SetActive(true);
retryText.text = currentWord; retryText.text = currentWord;
@ -172,18 +170,16 @@ public class WordPuzzle : MonoBehaviour
allLetterTexts = GetComponentsInChildren<TMP_Text>(); allLetterTexts = GetComponentsInChildren<TMP_Text>();
retry.SetActive(false); retry.SetActive(false);
congratulations.SetActive(false); congratulations.SetActive(false);
usedLetterTexts.Clear(); foreach (var text in allLetterTexts)
foreach (var texts in allLetterTexts)
{ {
texts.text = string.Empty; text.text = "";
texts.color = Color.white; text.color = Color.white;
} }
currentSubmit = 0; currentSubmit = 0;
currentCount = 0; currentCount = 0;
if (string.IsNullOrEmpty(currentWord)) { currentWord = words[UnityEngine.Random.Range(0, words.Count)];
currentWord = words[UnityEngine.Random.Range(0, words.Count)]; currentWord = currentWord.ToLower();
Debug.Log("Chosen random word: " + currentWord); Debug.Log("Chosen random word: " + currentWord);
}
SetGameState(WGameState.Playing); SetGameState(WGameState.Playing);
} }
} }

View File

@ -19334,6 +19334,8 @@ MonoBehaviour:
keyCardName: move rack keyCardName: move rack
keyCardPlayer: {fileID: 0} keyCardPlayer: {fileID: 0}
interactionDistance: 5 interactionDistance: 5
keyCardItem: {fileID: 0}
playerInventory: {fileID: 0}
--- !u!65 &1050845135 --- !u!65 &1050845135
BoxCollider: BoxCollider:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -24105,6 +24107,51 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 69125d056127da746a8a1ed8371ea8d6, type: 3} m_Script: {fileID: 11500000, guid: 69125d056127da746a8a1ed8371ea8d6, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
--- !u!1 &1328799368
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1328799370}
- component: {fileID: 1328799369}
m_Layer: 0
m_Name: TabletToggleManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1328799369
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1328799368}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1f363690cf70e6449a55d819bd9503b6, type: 3}
m_Name:
m_EditorClassIdentifier:
tablet: {fileID: 0}
--- !u!4 &1328799370
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1328799368}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.88123596, y: 23.22024, z: -4.681444}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1339936851 --- !u!1 &1339936851
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -37444,6 +37491,8 @@ MonoBehaviour:
keyCardName: move rack keyCardName: move rack
keyCardPlayer: {fileID: 0} keyCardPlayer: {fileID: 0}
interactionDistance: 5 interactionDistance: 5
keyCardItem: {fileID: 0}
playerInventory: {fileID: 0}
--- !u!65 &2090030717 --- !u!65 &2090030717
BoxCollider: BoxCollider:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -39966,6 +40015,8 @@ MonoBehaviour:
keyCardName: Deck C key card keyCardName: Deck C key card
keyCardPlayer: {fileID: 7685886779921947557} keyCardPlayer: {fileID: 7685886779921947557}
interactionDistance: 5 interactionDistance: 5
keyCardItem: {fileID: 0}
playerInventory: {fileID: 0}
--- !u!114 &4244626406387182888 --- !u!114 &4244626406387182888
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -40787,7 +40838,7 @@ Transform:
m_GameObject: {fileID: 7094977339719025836} m_GameObject: {fileID: 7094977339719025836}
serializedVersion: 2 serializedVersion: 2
m_LocalRotation: {x: -0, y: -0.6649941, z: -0, w: 0.7468486} m_LocalRotation: {x: -0, y: -0.6649941, z: -0, w: 0.7468486}
m_LocalPosition: {x: -49.75, y: -9.26, z: 23.94} m_LocalPosition: {x: -49.75, y: 7.59, z: 28.33}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: m_Children:
@ -41749,3 +41800,4 @@ SceneRoots:
- {fileID: 171829751} - {fileID: 171829751}
- {fileID: 1766395669} - {fileID: 1766395669}
- {fileID: 1232642964} - {fileID: 1232642964}
- {fileID: 1328799370}