summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/SimonSaysGame.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-12-30 20:59:04 +0800
committerchai <chaifix@163.com>2020-12-30 20:59:04 +0800
commite9ea621b93fbb58d9edfca8375918791637bbd52 (patch)
tree19ce3b1c1f2d51eda6878c9d0f2c9edc27f13650 /Client/Assembly-CSharp/SimonSaysGame.cs
+init
Diffstat (limited to 'Client/Assembly-CSharp/SimonSaysGame.cs')
-rw-r--r--Client/Assembly-CSharp/SimonSaysGame.cs243
1 files changed, 243 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/SimonSaysGame.cs b/Client/Assembly-CSharp/SimonSaysGame.cs
new file mode 100644
index 0000000..a66114f
--- /dev/null
+++ b/Client/Assembly-CSharp/SimonSaysGame.cs
@@ -0,0 +1,243 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class SimonSaysGame : Minigame
+{
+ private int IndexCount
+ {
+ get
+ {
+ return (int)this.MyNormTask.Data[0];
+ }
+ set
+ {
+ this.MyNormTask.Data[0] = (byte)value;
+ }
+ }
+
+ private byte this[int idx]
+ {
+ get
+ {
+ return this.MyNormTask.Data[idx + 1];
+ }
+ set
+ {
+ this.MyNormTask.Data[idx + 1] = value;
+ }
+ }
+
+ private Queue<int> operations = new Queue<int>();
+
+ private const int FlashOp = 256;
+
+ private const int AnimateOp = 128;
+
+ private const int ReAnimateOp = 32;
+
+ private const int FailOp = 64;
+
+ private Color gray = new Color32(141, 141, 141, byte.MaxValue);
+
+ private Color blue = new Color32(68, 168, byte.MaxValue, byte.MaxValue);
+
+ private Color red = new Color32(byte.MaxValue, 58, 0, byte.MaxValue);
+
+ private Color green = Color.green;
+
+ public SpriteRenderer[] LeftSide;
+
+ public SpriteRenderer[] Buttons;
+
+ public SpriteRenderer[] LeftLights;
+
+ public SpriteRenderer[] RightLights;
+
+ private float flashTime = 0.25f;
+
+ private float userButtonFlashTime = 0.175f;
+
+ public AudioClip ButtonPressSound;
+
+ public AudioClip FailSound;
+
+ public override void Begin(PlayerTask task)
+ {
+ for (int i = 0; i < this.LeftSide.Length; i++)
+ {
+ this.LeftSide[i].color = Color.clear;
+ }
+ base.Begin(task);
+ if (this.IndexCount == 0)
+ {
+ this.operations.Enqueue(128);
+ }
+ else
+ {
+ this.operations.Enqueue(32);
+ }
+ base.StartCoroutine(this.CoRun());
+ }
+
+ public void HitButton(int bIdx)
+ {
+ if (this.MyNormTask.IsComplete || this.MyNormTask.taskStep >= this.IndexCount)
+ {
+ return;
+ }
+ if ((int)this[this.MyNormTask.taskStep] == bIdx)
+ {
+ this.MyNormTask.NextStep();
+ this.SetLights(this.RightLights, this.MyNormTask.taskStep);
+ if (this.MyNormTask.IsComplete)
+ {
+ this.SetLights(this.LeftLights, this.LeftLights.Length);
+ for (int i = 0; i < this.Buttons.Length; i++)
+ {
+ SpriteRenderer spriteRenderer = this.Buttons[i];
+ spriteRenderer.color = this.gray;
+ base.StartCoroutine(this.FlashButton(-1, spriteRenderer, this.flashTime));
+ }
+ base.StartCoroutine(base.CoStartClose(0.75f));
+ return;
+ }
+ this.operations.Enqueue(256 | bIdx);
+ if (this.MyNormTask.taskStep >= this.IndexCount)
+ {
+ this.operations.Enqueue(128);
+ return;
+ }
+ }
+ else
+ {
+ this.IndexCount = 0;
+ this.operations.Enqueue(64);
+ this.operations.Enqueue(128);
+ }
+ }
+
+ private IEnumerator CoRun()
+ {
+ for (;;)
+ {
+ if (this.operations.Count <= 0)
+ {
+ yield return null;
+ }
+ else
+ {
+ int num = this.operations.Dequeue();
+ if (num.HasAnyBit(256))
+ {
+ int num2 = num & -257;
+ yield return this.FlashButton(num2, this.Buttons[num2], this.userButtonFlashTime);
+ }
+ else if (num.HasAnyBit(128))
+ {
+ yield return this.CoAnimateNewLeftSide();
+ }
+ else if (num.HasAnyBit(32))
+ {
+ yield return this.CoAnimateOldLeftSide();
+ }
+ else if (num.HasAnyBit(64))
+ {
+ if (Constants.ShouldPlaySfx())
+ {
+ SoundManager.Instance.PlaySound(this.FailSound, false, 1f);
+ }
+ this.SetAllColor(this.red);
+ yield return new WaitForSeconds(this.flashTime);
+ this.SetAllColor(Color.white);
+ yield return new WaitForSeconds(this.flashTime);
+ this.SetAllColor(this.red);
+ yield return new WaitForSeconds(this.flashTime);
+ this.SetAllColor(Color.white);
+ yield return new WaitForSeconds(this.flashTime / 2f);
+ }
+ }
+ }
+ yield break;
+ }
+
+ private void AddIndex(int idxToAdd)
+ {
+ this[this.IndexCount] = (byte)idxToAdd;
+ int indexCount = this.IndexCount;
+ this.IndexCount = indexCount + 1;
+ }
+
+ private IEnumerator CoAnimateNewLeftSide()
+ {
+ this.SetLights(this.RightLights, 0);
+ for (int i = 0; i < this.Buttons.Length; i++)
+ {
+ this.Buttons[i].color = this.gray;
+ }
+ this.AddIndex(this.Buttons.RandomIdx<SpriteRenderer>());
+ yield return this.CoAnimateOldLeftSide();
+ yield break;
+ }
+
+ private IEnumerator CoAnimateOldLeftSide()
+ {
+ yield return new WaitForSeconds(1f);
+ this.SetLights(this.LeftLights, this.IndexCount);
+ int num2;
+ for (int i = 0; i < this.IndexCount; i = num2)
+ {
+ int num = (int)this[i];
+ yield return this.FlashButton(num, this.LeftSide[num], this.flashTime);
+ yield return new WaitForSeconds(0.1f);
+ num2 = i + 1;
+ }
+ this.MyNormTask.taskStep = 0;
+ for (int j = 0; j < this.Buttons.Length; j++)
+ {
+ this.Buttons[j].color = Color.white;
+ }
+ yield break;
+ }
+
+ private IEnumerator FlashButton(int id, SpriteRenderer butt, float flashTime)
+ {
+ if (id > -1 && Constants.ShouldPlaySfx())
+ {
+ SoundManager.Instance.PlaySound(this.ButtonPressSound, false, 1f).pitch = Mathf.Lerp(0.5f, 1.5f, (float)id / 9f);
+ }
+ Color c = butt.color;
+ butt.color = this.blue;
+ yield return new WaitForSeconds(flashTime);
+ butt.color = c;
+ yield break;
+ }
+
+ private void SetLights(SpriteRenderer[] lights, int num)
+ {
+ for (int i = 0; i < lights.Length; i++)
+ {
+ if (i < num)
+ {
+ lights[i].color = this.green;
+ }
+ else
+ {
+ lights[i].color = this.gray;
+ }
+ }
+ }
+
+ private void SetAllColor(Color color)
+ {
+ for (int i = 0; i < this.Buttons.Length; i++)
+ {
+ this.Buttons[i].color = color;
+ }
+ for (int j = 0; j < this.RightLights.Length; j++)
+ {
+ this.RightLights[j].color = color;
+ }
+ }
+}