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

View File

@ -19334,6 +19334,8 @@ MonoBehaviour:
keyCardName: move rack
keyCardPlayer: {fileID: 0}
interactionDistance: 5
keyCardItem: {fileID: 0}
playerInventory: {fileID: 0}
--- !u!65 &1050845135
BoxCollider:
m_ObjectHideFlags: 0
@ -24105,6 +24107,51 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 69125d056127da746a8a1ed8371ea8d6, type: 3}
m_Name:
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
GameObject:
m_ObjectHideFlags: 0
@ -37444,6 +37491,8 @@ MonoBehaviour:
keyCardName: move rack
keyCardPlayer: {fileID: 0}
interactionDistance: 5
keyCardItem: {fileID: 0}
playerInventory: {fileID: 0}
--- !u!65 &2090030717
BoxCollider:
m_ObjectHideFlags: 0
@ -39966,6 +40015,8 @@ MonoBehaviour:
keyCardName: Deck C key card
keyCardPlayer: {fileID: 7685886779921947557}
interactionDistance: 5
keyCardItem: {fileID: 0}
playerInventory: {fileID: 0}
--- !u!114 &4244626406387182888
MonoBehaviour:
m_ObjectHideFlags: 0
@ -40787,7 +40838,7 @@ Transform:
m_GameObject: {fileID: 7094977339719025836}
serializedVersion: 2
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_ConstrainProportionsScale: 0
m_Children:
@ -41749,3 +41800,4 @@ SceneRoots:
- {fileID: 171829751}
- {fileID: 1766395669}
- {fileID: 1232642964}
- {fileID: 1328799370}