using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using Godot; using Godot.Bridge; using Godot.NativeInterop; [ScriptPath("res://Scripts/Puzzles/MemoryGame.cs")] public partial class MemoryGame : Node2D { [Signal] public delegate void EndGameSignalEventHandler(); [Export(PropertyHint.None, "")] public string winDiag; [Export(PropertyHint.None, "")] public string loseDiag; [Export(PropertyHint.None, "")] private AudioStream music; [Export(PropertyHint.None, "")] public int defaultLives = 5; private List cards = new List(); public List flipped = new List(); public MemGameCards last; public bool running; public int lives; public const int max = 18; private static readonly int[] order = new int[18] { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9 }; public static bool result; public override void _Ready() { foreach (Node child in GetChildren()) { cards.Add(child.GetChild(0)); } base.Modulate = Main.colorClear; } public IEnumerator StartGame() { int[] array = order; if (Main.RandomRange(0, 31) == 0) { int num = Main.RandomRange(0, 8); array[num * 2] = 10; array[num * 2 + 1] = 10; } array = order.OrderBy((int x) => Guid.NewGuid()).ToArray(); for (int num2 = 0; num2 < cards.Count; num2++) { cards[num2].id = array[num2]; cards[num2].sprite.Frame = 0; cards[num2].flipped = false; } Audio.PlaySound("snd_shadowpendant_ch1.wav"); Audio.ChangeMusic(music); float a = 0f; for (float b = 30f; a <= b + 1f; a += Main.deltaTime) { base.Modulate = Main.colorClear.Lerp(Main.colorWhite, Mathf.Min(a / b, 1f)); yield return null; } Coroutine s = Coroutine.Start(CameraController.PanToObj(this, 2f)); while (!s.done) { yield return null; } Audio.PlaySound("snd_wing_ch1.wav", 1.2f); for (int num3 = 0; num3 < cards.Count; num3++) { Coroutine.Start(cards[num3].FlipAnim(cards[num3].id, noSound: true)); } for (float b = 0f; b < 300f; b += Main.deltaTime) { if (Input.IsActionJustPressed(Main.keys[4])) { break; } if (Input.IsActionJustPressed(Main.keys[5])) { break; } yield return null; } Audio.PlaySound("snd_wing_ch1.wav", 1.2f); for (int num4 = 0; num4 < cards.Count; num4++) { Coroutine.Start(cards[num4].FlipAnim(0, noSound: true)); } for (float b = 0f; b < 30f; b += Main.deltaTime) { yield return null; } s = Coroutine.Start(CameraController.PanToObj(Player.instance, 2f)); while (!s.done) { yield return null; } flipped.Clear(); lives = defaultLives; running = true; } public IEnumerator EndGame(bool won) { running = false; result = won; if (won) { Audio.PlaySound("snd_won.wav"); TextSystem.GetText(winDiag); } else { TextSystem.GetText(loseDiag); } while (TextSystem.instance.Visible) { yield return null; } Room.current.DoMusic(); float a = 0f; for (float b = 30f; a <= b + 1f; a += Main.deltaTime) { base.Modulate = Main.colorWhite.Lerp(Main.colorClear, Mathf.Min(a / b, 1f)); yield return null; } EmitSignal(SignalName.EndGameSignal); } }