diff --git a/Assets/Scenes/Game.unity b/Assets/Scenes/Game.unity index 9bc80eb..f21658b 100644 --- a/Assets/Scenes/Game.unity +++ b/Assets/Scenes/Game.unity @@ -901,7 +901,7 @@ RectTransform: - {fileID: 1058458553} - {fileID: 349139944} m_Father: {fileID: 1716128836} - m_RootOrder: 1 + m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} @@ -983,92 +983,6 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 948965529} m_CullTransparentMesh: 1 ---- !u!1 &970415716 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 970415717} - - component: {fileID: 970415719} - - component: {fileID: 970415718} - - component: {fileID: 970415720} - m_Layer: 5 - m_Name: BackgroundImage - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!224 &970415717 -RectTransform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 970415716} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 1716128836} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 0} - m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 0, y: 0} - m_Pivot: {x: 0.5, y: 0.5} ---- !u!114 &970415718 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 970415716} - m_Enabled: 0 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 1344c3c82d62a2a41a3576d8abb8e3ea, type: 3} - m_Name: - m_EditorClassIdentifier: - m_Material: {fileID: 0} - m_Color: {r: 1, g: 1, b: 1, a: 1} - m_RaycastTarget: 1 - m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} - m_Maskable: 1 - m_OnCullStateChanged: - m_PersistentCalls: - m_Calls: [] - m_Texture: {fileID: 0} - m_UVRect: - serializedVersion: 2 - x: 0 - y: 0 - width: 1 - height: 1 ---- !u!222 &970415719 -CanvasRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 970415716} - m_CullTransparentMesh: 1 ---- !u!114 &970415720 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 970415716} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: c337eac6b9fd2ab44b3f305c52c07cbf, type: 3} - m_Name: - m_EditorClassIdentifier: - rawImage: {fileID: 970415718} --- !u!1 &1004586247 GameObject: m_ObjectHideFlags: 0 @@ -2598,7 +2512,6 @@ RectTransform: m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0, y: 0, z: 0} m_Children: - - {fileID: 970415717} - {fileID: 931885379} - {fileID: 1924515355} m_Father: {fileID: 0} @@ -2898,7 +2811,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 3d3fbe337bfa95945a2f79e080012c3b, type: 3} m_Name: m_EditorClassIdentifier: - time: 300 timerText: {fileID: 2110031176} fillImage: {fileID: 948965531} --- !u!1 &1804704519 @@ -3103,7 +3015,7 @@ RectTransform: m_Children: - {fileID: 1629749210} m_Father: {fileID: 1716128836} - m_RootOrder: 2 + m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} diff --git a/Assets/Scripts/BackgroundImage.cs b/Assets/Scripts/BackgroundImage.cs deleted file mode 100644 index d0a5f43..0000000 --- a/Assets/Scripts/BackgroundImage.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using System.IO; -using UnityEngine; -using UnityEngine.Networking; -using UnityEngine.UI; - -// loads a background image for the game if one is found in the files -public class BackgroundImage : MonoBehaviour -{ - [SerializeField] RawImage rawImage; - - void Start() - { - var path = Path.Combine(Application.dataPath, "..", "background.png"); - if(File.Exists(path)) - { - StartCoroutine(LoadImage(path)); - } - } - - IEnumerator LoadImage(string url) - { - using(UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(url)) - { - yield return uwr.SendWebRequest(); - - if(uwr.result != UnityWebRequest.Result.Success) - { - Debug.LogError(uwr.error); - } - else - { - var texture = DownloadHandlerTexture.GetContent(uwr); - rawImage.texture = texture; - rawImage.enabled = true; - } - } - } -} diff --git a/Assets/Scripts/BackgroundImage.cs.meta b/Assets/Scripts/BackgroundImage.cs.meta deleted file mode 100644 index 42dda17..0000000 --- a/Assets/Scripts/BackgroundImage.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c337eac6b9fd2ab44b3f305c52c07cbf -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/EndScreen.cs b/Assets/Scripts/EndScreen.cs index be3a860..c04631d 100644 --- a/Assets/Scripts/EndScreen.cs +++ b/Assets/Scripts/EndScreen.cs @@ -4,7 +4,9 @@ using UnityEngine; using UnityEngine.SceneManagement; -// handles the screen that displays at the end of the game +/// +/// Handles the screen that displays at the end of the game +/// public class EndScreen : MonoBehaviour { [SerializeField] GameObject gameScreen; @@ -25,6 +27,9 @@ void Start() endScreen.SetActive(false); } + /// + /// Hide the game and show the end screen, and prepare for the user to restart + /// void OnTimeExpired() { gameScreen.SetActive(false); @@ -32,6 +37,9 @@ void OnTimeExpired() InputManager.OnSubmit += OnSubmit; } + /// + /// Called when the user presses enter while the end screen is open. Restarts the game + /// void OnSubmit() { InputManager.OnSubmit -= OnSubmit; diff --git a/Assets/Scripts/InputManager.cs b/Assets/Scripts/InputManager.cs index 46e6a36..1568bca 100644 --- a/Assets/Scripts/InputManager.cs +++ b/Assets/Scripts/InputManager.cs @@ -3,7 +3,9 @@ using System.Collections.Generic; using UnityEngine; -// handle any keyboard input for the entire game +/// +/// Handle player input for the entire game +/// public class InputManager : MonoBehaviour { KeyCode[] letters = new KeyCode[] { KeyCode.A, KeyCode.B, KeyCode.C, KeyCode.D, KeyCode.E, KeyCode.F, KeyCode.G, KeyCode.H, KeyCode.I, KeyCode.J, KeyCode.K, KeyCode.L, KeyCode.M, KeyCode.N, KeyCode.O, KeyCode.P, KeyCode.Q, KeyCode.R, KeyCode.S, KeyCode.T, KeyCode.U, KeyCode.V, KeyCode.W, KeyCode.X, KeyCode.Y, KeyCode.Z }; diff --git a/Assets/Scripts/Keyboard.cs b/Assets/Scripts/Keyboard.cs index fc0a734..75aca5c 100644 --- a/Assets/Scripts/Keyboard.cs +++ b/Assets/Scripts/Keyboard.cs @@ -2,7 +2,9 @@ using System.Collections.Generic; using UnityEngine; -// a keyboard which displays missing keys +/// +/// An in-game keyboard which displays missing keys +/// public class Keyboard : MonoBehaviour { public static Keyboard Instance; @@ -27,7 +29,9 @@ void Start() Generate(); } - // clear all the keys on the keyboard and generate a new one + /// + /// Clear all the keys on the keyboard and generate a new one + /// public void Clear() { foreach(var row in rows) @@ -41,7 +45,9 @@ public void Clear() Generate(); } - // generate the keys on the keyboard + /// + /// Generate the keys on the keyboard + /// void Generate() { for(int i = 0; i < layout.Length; i++) diff --git a/Assets/Scripts/KeyboardKeyBox.cs b/Assets/Scripts/KeyboardKeyBox.cs index 34f63d3..a29a96d 100644 --- a/Assets/Scripts/KeyboardKeyBox.cs +++ b/Assets/Scripts/KeyboardKeyBox.cs @@ -5,7 +5,9 @@ using UnityEngine; using UnityEngine.UI; -// an individual key on the keyboard, which will turn gray when it's found missing +/// +/// An individual key on the in-game keyboard, which will turn gray when it's found missing +/// public class KeyboardKeyBox : MonoBehaviour { [SerializeField] TMP_Text text; @@ -13,6 +15,10 @@ public class KeyboardKeyBox : MonoBehaviour char key; + /// + /// Construct the KeyboardKeyBox + /// + /// The key for the key box to represent on the keyboard public void Initialize(char key) { this.key = key; @@ -29,6 +35,9 @@ void OnDisable() Row.OnSubmit -= OnSubmit; } + /// + /// Called when enter is pressed. Update the visuals based on the missing letters + /// void OnSubmit() { if(Wordle.ConfirmedMissingLetters.Contains(key)) diff --git a/Assets/Scripts/LetterBox.cs b/Assets/Scripts/LetterBox.cs index 8492532..382bf7a 100644 --- a/Assets/Scripts/LetterBox.cs +++ b/Assets/Scripts/LetterBox.cs @@ -5,7 +5,9 @@ using UnityEngine.UI; using DG.Tweening; -// an individual letter of a row +/// +/// An individual letter of a row +/// public class LetterBox : MonoBehaviour { [SerializeField] Style style; @@ -20,28 +22,38 @@ public class LetterBox : MonoBehaviour Sequence revealSequence; + /// + /// Construct the LetterBox + /// + /// The index of this letter box in the row that created it public void Initialize(int letterIndexInRow) { this.letterIndexInRow = letterIndexInRow; } - // set the letter and state + /// + /// Set the letter and state + /// + /// The letter to assign + /// The state to assign public void SetLetter(KeyCode letter, LetterState state) { // set the data Letter = letter; - SetState(state); + SetAnimatedState(state); // update the UI PlayTypeAnimation(); text.text = Letter.ToString().ToUpper(); } - // completely reset the letterbox + /// + /// Completely reset the letterbox + /// public void Clear() { // reset the data - SetState(LetterState.Empty); + SetAnimatedState(LetterState.Empty); Letter = KeyCode.None; // reset the UI @@ -50,9 +62,11 @@ public void Clear() DOTween.Complete(all.transform); } - // assign a state to this letterbox, and update the UI accordingly. - // like if a letter is missing or correct. - public void SetState(LetterState state) + /// + /// Assign a state to this letterbox. Play an animation if it's available + /// + /// The state to assign + public void SetAnimatedState(LetterState state) { if(state == LetterState.Invalid) { @@ -64,26 +78,33 @@ public void SetState(LetterState state) } else { - ApplyState(state); + SetState(state); } } - // apply a state, updating the UI accordingly - void ApplyState(LetterState state) + /// + /// Apply a state instantly, updating the UI accordingly + /// + /// The state to assign + void SetState(LetterState state) { background.color = style.GetLetterColor(state); background.sprite = style.GetBackgroundSprite(state); State = state; } - // play the animation for when a letter is typed out + /// + /// Play the animation for when a letter is typed out + /// void PlayTypeAnimation() { all.transform.DOScale(1.4f, 0f); all.transform.DOScale(1f, 0.3f).SetEase(Ease.OutExpo); } - // play the animation for when a letter is not allowed + /// + /// Play the animation for when a letter is not allowed + /// void PlayInvalidAnimation() { var seq = DOTween.Sequence(); @@ -95,8 +116,10 @@ void PlayInvalidAnimation() seq.Play(); } - // play the animation for revealing the result once the word - // has been submitted + /// + /// play the animation for revealing the result once the word has been submitted + /// + /// The state to set the LetterBox to while it is hidden in the middle of the animation void PlayRevealAnimation(LetterState state) { revealSequence = DOTween.Sequence(); @@ -104,7 +127,7 @@ void PlayRevealAnimation(LetterState state) revealSequence.Append(all.DOScaleY(0.001f, 0.2f)); revealSequence.AppendCallback(() => { - ApplyState(state); + SetState(state); }); revealSequence.Append(all.DOScaleY(1f, 0.2f)); revealSequence.Play(); diff --git a/Assets/Scripts/PlayButton.cs b/Assets/Scripts/PlayButton.cs index e833b23..79d70ce 100644 --- a/Assets/Scripts/PlayButton.cs +++ b/Assets/Scripts/PlayButton.cs @@ -3,7 +3,9 @@ using UnityEngine; using UnityEngine.SceneManagement; -// a button which loads the game +/// +/// A button which loads the game +/// public class PlayButton : MonoBehaviour { public void Play() diff --git a/Assets/Scripts/RestartGame.cs b/Assets/Scripts/RestartGame.cs index ad1fd60..05f56ae 100644 --- a/Assets/Scripts/RestartGame.cs +++ b/Assets/Scripts/RestartGame.cs @@ -3,7 +3,9 @@ using UnityEngine; using UnityEngine.SceneManagement; -// allows the game to be restarted while in progress for demonstration purposes +/// +/// Allows the game to be restarted while in progress by pressing CTRL + SHIFT + R for demonstration purposes +/// public class RestartGame : MonoBehaviour { void Update() diff --git a/Assets/Scripts/ResultsText.cs b/Assets/Scripts/ResultsText.cs index 75900ee..31e19db 100644 --- a/Assets/Scripts/ResultsText.cs +++ b/Assets/Scripts/ResultsText.cs @@ -1,7 +1,9 @@ using TMPro; using UnityEngine; -// displays the results at the end of the game +/// +/// Displays the results at the end of the game +/// public class ResultsText : MonoBehaviour { void Start() @@ -14,6 +16,9 @@ void OnDestroy() Timer.OnTimeExpired -= OnTimeExpired; } + /// + /// Called then the game timer has expired. Updates the results text with the player's score + /// void OnTimeExpired() { GetComponent().text = $"Time Expired\n\nScore: {Wordle.Instance.GetWins()}\n\nPress Enter to Restart"; diff --git a/Assets/Scripts/Row.cs b/Assets/Scripts/Row.cs index 06be81e..7c264a9 100644 --- a/Assets/Scripts/Row.cs +++ b/Assets/Scripts/Row.cs @@ -4,7 +4,9 @@ using System.Text; using UnityEngine; -// a row of the wordle board +/// +/// A row of the Wordle board, which contains letters +/// public class Row : MonoBehaviour { public static event Action OnSubmit; @@ -47,7 +49,9 @@ public bool TryAddLetter(KeyCode letter) return true; } - // completely reset the row + /// + /// Completely reset the row + /// public void Clear() { for(int i = 0; i < letterBoxes.Length; i++) @@ -58,7 +62,9 @@ public void Clear() inputIndex = 0; } - // delete the last letter from the row + /// + /// Delete the last letter from the row + /// public void DeleteLetter() { inputIndex--; @@ -66,7 +72,9 @@ public void DeleteLetter() letterBoxes[inputIndex].Clear(); } - // convert the row to a string and validate it + /// + /// Validate the row and update the UI + /// public void Submit() { // convert the row into a string @@ -80,7 +88,7 @@ public void Submit() LetterState[] letterStates = Wordle.Instance.ValidateRow(sb.ToString()); for(int i = 0; i < letterBoxes.Length; i++) { - letterBoxes[i].SetState(letterStates[i]); + letterBoxes[i].SetAnimatedState(letterStates[i]); } OnSubmit?.Invoke(); diff --git a/Assets/Scripts/Style.cs b/Assets/Scripts/Style.cs index 118dac1..334b721 100644 --- a/Assets/Scripts/Style.cs +++ b/Assets/Scripts/Style.cs @@ -4,7 +4,9 @@ public enum LetterState { Empty, Missing, Somewhere, Correct, Invalid, PreviouslyUsed }; -// supplies the graphics for the wordle board +/// +/// Supplies the graphics for the Wordle board +/// [CreateAssetMenu(menuName = "Style")] public class Style : ScriptableObject { diff --git a/Assets/Scripts/TimeSetManager.cs b/Assets/Scripts/TimeSetManager.cs index 30558e1..6ac4220 100644 --- a/Assets/Scripts/TimeSetManager.cs +++ b/Assets/Scripts/TimeSetManager.cs @@ -3,12 +3,18 @@ using TMPro; using UnityEngine; -// manages the time to play being set in the main menu +/// +/// Allows the player to set the play time +/// public class TimeSetManager : MonoBehaviour { public static float Time = 300f; [SerializeField] TMP_Text timeText; + /// + /// Called via a UI slider + /// + /// The value in seconds to set the play time to public void SetTimer(float value) { Time = value; diff --git a/Assets/Scripts/Timer.cs b/Assets/Scripts/Timer.cs index e68f761..5a16075 100644 --- a/Assets/Scripts/Timer.cs +++ b/Assets/Scripts/Timer.cs @@ -6,7 +6,9 @@ using UnityEngine; using UnityEngine.UI; -// handles the countdown timer for the game +/// +/// Handles the countdown timer for the game +/// public class Timer : MonoBehaviour { public static Timer Instance; diff --git a/Assets/Scripts/Wordle.cs b/Assets/Scripts/Wordle.cs index 63b2ccf..e0a2cd4 100644 --- a/Assets/Scripts/Wordle.cs +++ b/Assets/Scripts/Wordle.cs @@ -9,7 +9,9 @@ using UnityEngine; using Random = UnityEngine.Random; -// handles the game logic and score tracking +/// +/// Handles the game logic and score tracking +/// public class Wordle : MonoBehaviour { public static Wordle Instance { get; private set; } @@ -64,7 +66,10 @@ void Start() Clear(); } - // if the user presses a key, try to add it to the current row + /// + /// Called when a letter is pressed. If the pllayer presses a key, try to add it to the current row + /// + /// The letter that was pressed void OnLetter(KeyCode letter) { if(paused) @@ -73,13 +78,17 @@ void OnLetter(KeyCode letter) rows[rowIndex].TryAddLetter(letter); } - // if the user presses the delete key, delete a letter from the row + /// + /// Called when the delete key is pressed. If the player presses the delete key, delete a letter from the row + /// void OnDelete() { rows[rowIndex].DeleteLetter(); } - // if the user presses the submit key, submit or clear if the game is over + /// + /// Called when the submit key is pressed. If the player presses the submit key, submit or clear if the game is over + /// void OnSubmit() { if(paused) @@ -88,7 +97,11 @@ void OnSubmit() rows[rowIndex].Submit(); } - // validate a row and return the state of each letter in the row + /// + /// Validate a row and return the state of each letter in the row + /// + /// The content of the row to validate + /// An array of LetterStates, which correspond to LetterBoxes in a row public LetterState[] ValidateRow(string content) { LetterState[] letterStates = new LetterState[content.Length]; @@ -171,6 +184,10 @@ public LetterState[] ValidateRow(string content) return letterStates; } + /// + /// Called to complete the game. This happens when a player has submitted the final row, or guessed correctly + /// + /// Whether the player won or not void CompleteGame(bool won) { paused = true; @@ -194,7 +211,11 @@ public int GetWins() return wins; } - // play an animation of the wordle board sliding out and back in, clearing when it's off screen + /// + /// Play an animation of the wordle board sliding out and back in, clearing when it's off screen + /// + /// The time in seconds to wait before playing the animation + /// Whether the player won or not IEnumerator I_PlayClearAnimation(float delay, bool won) { // pause the timer so it doesn't go down while the animation is playing @@ -226,7 +247,9 @@ IEnumerator I_PlayClearAnimation(float delay, bool won) Timer.Instance.Resume(); } - // clear the entire wordle board and generate a new word + /// + /// Completely reset the Wordle board and generate a new word + /// void Clear() { // clear all the rows @@ -259,7 +282,9 @@ void Clear() paused = false; } - // class for all the wordle data, loaded from a JSON file + /// + /// Container for all the Wordle data, loaded from a JSON file + /// class WordData { public string[] answers;