-
Notifications
You must be signed in to change notification settings - Fork 0
/
Piano_Question.cs
125 lines (110 loc) · 3.58 KB
/
Piano_Question.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Piano_Question : MonoBehaviour {
public int x;
public int y;
public int result;
public int compare;
private Text leftbutton;
private Text rightbutton;
private Piano_Button resetleft;
private Piano_Button resetright;
private float Difficulty;
private Piano_Score score;
public Animator anim;
public bool IsPressed;
private int Negative;
void Awake()
{
leftbutton = GameObject.Find("LeftButton").GetComponentInChildren<Text>();
resetleft = GameObject.Find("LeftButton").GetComponent<Piano_Button>();
rightbutton = GameObject.Find("RightButton").GetComponentInChildren<Text>();
resetright = GameObject.Find("RightButton").GetComponent<Piano_Button>();
score = GameObject.Find("Score").GetComponent<Piano_Score>();
anim = gameObject.GetComponent<Animator>();
}
public void NewQuestion()
{
Difficulty = score.score + 1;
Negative = Random.Range(1, 3);
if (Negative == 1)
NewQuestionPositive();
else if (Negative == 2)
NewQuestionNegative();
anim.SetFloat("Speed", (float)(0.65 + Difficulty / 20));
}
private void NewQuestionPositive()
{
x = Random.Range(1+ (int)Difficulty, 5 + (int)Difficulty);
y = Random.Range(1, 5 + (int)Difficulty);
result = x + y;
int position = Random.Range(1, 4);
switch (position)
{
case 1:
gameObject.GetComponent<Text>().text = "? + " + y + " = " + result;
ButtonPossition(x);
compare = x;
break;
case 2:
gameObject.GetComponent<Text>().text = x + " + ? = " + result;
ButtonPossition(y);
compare = y;
break;
case 3:
gameObject.GetComponent<Text>().text = x + " + " + y + " = ?";
ButtonPossition(result);
compare = result;
break;
}
}
private void NewQuestionNegative()
{
x = Random.Range(1 + (int)Difficulty, 8 + (int)Difficulty);
y = x - Random.Range(1, x - 1);
result = x - y;
int position = Random.Range(1, 4);
switch (position)
{
case 1:
gameObject.GetComponent<Text>().text = "? - " + y + " = " + result;
ButtonPossition(x);
compare = x;
break;
case 2:
gameObject.GetComponent<Text>().text = x + " - ? = " + result;
ButtonPossition(y);
compare = y;
break;
case 3:
gameObject.GetComponent<Text>().text = x + " - " + y + " = ?";
ButtonPossition(result);
compare = result;
break;
}
}
public void ResetButtons()
{
resetleft.anim.SetInteger("IsCorrect", 0);
resetright.anim.SetInteger("IsCorrect", 0);
if (!IsPressed)
score.UpdateScore(false);
else
IsPressed = false;
}
void ButtonPossition(int content)
{
int unknown = Random.Range(1, 3);
if (unknown == 1)
{
leftbutton.text = "" + content;
rightbutton.text = "" + (content + Random.Range(1, 7));
}
else if (unknown == 2)
{
rightbutton.text = "" + content;
leftbutton.text = "" + (content + Random.Range(1, 7));
}
}
}