-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIView.cs
132 lines (110 loc) · 3.46 KB
/
UIView.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
126
127
128
129
130
131
132
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.SceneManagement;
public class UIView : RubiksView {
public GUISkin timeGUISkin;
Canvas startCanvas;
Text timerText;
float gameTime;
string viewTime;
string viewTimer;
bool showMsg;
bool restart = false;
bool quit = false;
private void Awake()
{
startCanvas = GameObject.FindWithTag("StartCanvas").GetComponent<Canvas>();
timerText = GameObject.FindWithTag("TimeText").GetComponent<Text>();
}
private void Update()
{
if (app.model.gameState == GameState.Start)
{
startCanvas.enabled = true;
}
else
{
startCanvas.enabled = false;
}
if (restart)
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
if(quit)
{
Application.Quit();
}
gameTime = app.model.timer;
int minutes = Mathf.FloorToInt(gameTime / 60F);
int seconds = Mathf.FloorToInt(gameTime - minutes * 60);
timerText.text = string.Format("{0:0}:{1:00}", minutes, seconds);
}
private void OnGUI()
{
GUI.skin.textArea.alignment = TextAnchor.MiddleCenter;
GUI.color = Color.white;
GUI.skin.textArea.fontSize = 42;
GUI.backgroundColor = Color.white;
GUIStyle endGameStyle = new GUIStyle();
endGameStyle.fontSize = 72;
endGameStyle.alignment = TextAnchor.MiddleCenter;
gameTime = app.model.timer - Time.time;
int minutes = Mathf.FloorToInt(gameTime / 60F);
int seconds = Mathf.FloorToInt(gameTime - minutes * 60);
viewTime = string.Format("{0:0}:{1:00}", minutes, seconds);
if (app.model.gameState == GameState.Play)
{
GUI.TextArea(new Rect(50, 50, 300, 50), "Time: " + viewTime);
}
if (app.model.gameState == GameState.Win)
{
GUI.Box(new Rect(870, 440, 300, 100), "You Win!", endGameStyle);
GUI.TextArea(new Rect(870, 440, 300, 100), "You Lose..", endGameStyle);
restart = GUI.Button(new Rect(870, 550, 100, 35), "Restart");
}
if (app.model.gameState == GameState.Loose)
{
GUI.TextArea(new Rect(870, 440, 300, 100), "You Lose..", endGameStyle);
restart = GUI.Button(new Rect(870, 550, 100, 35),"Restart");
}
if(showMsg)
{
GUI.Box(new Rect(870, 440, 300, 100), "Start!", endGameStyle);
StartCoroutine(ShowMsg());
}
}
IEnumerator ShowMsg()
{
yield return new WaitForSeconds(1);
showMsg = false;
}
public void UpTime()
{
app.model.timer += 15;
}
public void DownTime()
{
if (app.model.timer > 0)
{
app.model.timer -= 15;
}
}
public void StartGame()
{
app.model.gameState = GameState.Shuffle;
showMsg = true;
}
public void QuitGame()
{
if (app.model.gameState == GameState.Play || app.model.gameState == GameState.Shuffle)
{
app.model.gameState = GameState.Start;
}
else if (app.model.gameState == GameState.Start)
{
Application.Quit();
}
showMsg = true;
}
}