-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnity_APP
More file actions
165 lines (146 loc) · 4.36 KB
/
Copy pathUnity_APP
File metadata and controls
165 lines (146 loc) · 4.36 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class LevelManager : MonoBehaviour {
public Canvas myCanvas;
public Text grades_Text, finalMean_Text;
public GameObject first_UI, second_UI, gradeGenerator, gradeGenerated, container;
public RectTransform generatorRect;
public Button[] grades_Buttons = new Button[13];
private int[] grades = new int[21];
private int nGrades, finalMean;
private float currentSum, roundedMean, rawMean, tfloat;
private float wantedMean;
private int[] gradesVector = new int[21];
private void Start()
{
first_UI.SetActive(true);
second_UI.SetActive(false);
nGrades = 0;
}
public void ButtonPressed(int index)
{
nGrades++;
grades[nGrades] = index;
UpdateGrades();
}
public void DeleteLast()
{
if (nGrades == 0 || nGrades == 20) return;
grades[nGrades] = 0;
nGrades--;
UpdateGrades();
}
public void UpdateGrades()
{
int i, j;
currentSum = 0;
grades_Text.text = "";
for (i = 1; i <= nGrades; i++)
{
grades_Text.text += grades[i];
currentSum += grades[i];
if (i != nGrades) grades_Text.text += ", ";
}
}
public void UpgradeGrades()
{
if (wantedMean < 10)
{
wantedMean++;
finalMean_Text.text = "" + (finalMean).ToString("0.00") + " > " + (wantedMean).ToString("0.00");
}
//GenerateGrades();
CalculateGradesNeeded();
}
public void DowngradeGrades()
{
if (wantedMean > 1)
{
wantedMean--;
finalMean_Text.text = "" + (finalMean).ToString("0.00") + " > " + (wantedMean).ToString("0.00");
}
//GenerateGrades();
CalculateGradesNeeded();
}
public void CalculateGradesNeeded()
{
int i, j;
Destroy(container);
Instantiate(container, generatorRect.position, generatorRect.rotation);
container.transform.SetParent(gradeGenerator.transform.parent);
for (i = 0; i < 21; i++) gradesVector[i] = 0;
for (i = 1; i <= 5; i++)
{
BackTrack(1, i);
}
}
public void BackTrack(int x, int a)
{
int i, j, SS = 0;
for (i = (int)wantedMean; i <= 10; i++)
{
gradesVector[x] = i;
if (Candidate(x))
{
if (x == a)
{
GenerateGrades(x);
}
else if (x < a)
{
BackTrack(x + 1, a);
}
}
}
}
bool Candidate(int x)
{
int i, j, S = 0;
for (i = 1; i < x; i++)
{
if (gradesVector[x] < gradesVector[i]) return false;
S += gradesVector[i];
}
S += gradesVector[x];
return S == ((2 * wantedMean) - finalMean) * x;
}
void GenerateGrades(int x)
{
generatorRect = gradeGenerator.GetComponent<RectTransform>();
GameObject tGen;
Debug.Log(generatorRect.anchoredPosition.y);
tGen = Instantiate(gradeGenerated, generatorRect.position, generatorRect.rotation);
tGen.GetComponent<Text>().text = "";
for (int i = 1; i <= x; i++)
{
tGen.GetComponent<Text>().text += "" + gradesVector[i] + " ";
}
tGen.transform.SetParent(container.transform, false);
tGen.GetComponent<RectTransform>().anchoredPosition = generatorRect.anchoredPosition;
generatorRect.anchoredPosition += new Vector2(0, -38f);
}
public void CalculateMean()
{
first_UI.SetActive(false);
second_UI.SetActive(true);
rawMean = currentSum / nGrades;
roundedMean = Mathf.RoundToInt(rawMean);
tfloat = rawMean * 100;
finalMean = (int)(tfloat);
finalMean_Text.text = "" + (rawMean).ToString("0.00");
if (finalMean % 100 != 50) {
finalMean = (int)roundedMean;
} else {
finalMean = (finalMean / 100) + 1;
}
finalMean_Text.text += "(" + (finalMean).ToString("0.00") + ")";
wantedMean = finalMean;
}
public void ResetEverything()
{
SceneManager.LoadScene(0);
}
}