-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewController.cs
More file actions
223 lines (182 loc) · 6.15 KB
/
ViewController.cs
File metadata and controls
223 lines (182 loc) · 6.15 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
using System;
using System.Collections.Generic;
using TikTakToe.GameManage;
using UIKit;
namespace TikTakToe
{
public partial class ViewController : UIViewController
{
private IGameObjectManager gameObjectManager = null;
private List<UIButton> _uIButtons = new List<UIButton>();
protected ViewController(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
gameObjectManager = new GameObjectManager();
gameObjectManager.WinAction += (bool obj) =>
{
BeginInvokeOnMainThread(() =>
{
if (obj)
{
FinishGame();
lblStatus.Text = "Yes";
}
else
lblStatus.Text = "Try More";
});
};
btnReset.TouchUpInside += (object sender, EventArgs e) =>
{
ResetUI();
};
_uIButtons.Add(btn1);
_uIButtons.Add(btn2);
_uIButtons.Add(btn3);
_uIButtons.Add(btn4);
_uIButtons.Add(btn5);
_uIButtons.Add(btn6);
_uIButtons.Add(btn7);
_uIButtons.Add(btn8);
_uIButtons.Add(btn9);
InitiliazeGameUI(true);
btn1.TouchUpInside += (sender, e) =>
{
ExecuteButtonProcess(btn1, 0);
};
btn2.TouchUpInside += (sender, e) =>
{
ManageAddingGameObject(1, btn2);
btn2.Enabled = false;
};
btn3.TouchUpInside += (sender, e) =>
{
ManageAddingGameObject(2, btn3);
btn3.Enabled = false;
};
btn4.TouchUpInside += (sender, e) =>
{
ManageAddingGameObject(3, btn4);
btn4.Enabled = false;
};
btn5.TouchUpInside += (sender, e) =>
{
ManageAddingGameObject(4, btn5);
btn5.Enabled = false;
};
btn6.TouchUpInside += (sender, e) =>
{
ManageAddingGameObject(5, btn6);
btn6.Enabled = false;
};
btn7.TouchUpInside += (sender, e) =>
{
ManageAddingGameObject(6, btn7);
btn7.Enabled = false;
};
btn8.TouchUpInside += (sender, e) =>
{
ManageAddingGameObject(7, btn8);
btn8.Enabled = false;
};
btn9.TouchUpInside += (sender, e) =>
{
ManageAddingGameObject(8, btn9);
btn9.Enabled = false;
};
meSelector.ValueChanged += (sender, e) =>
{
//InitiliazeGameUI(true);
};
// Perform any additional setup after loading the view, typically from a nib.
}
private void ExecuteButtonProcess(UIButton btn, short position)
{
ManageAddingGameObject(position, btn);
btn.Enabled = false;
}
private void SetWinningUI(List<int> buttonsIds)
{
foreach (var item in buttonsIds)
{
switch (item)
{
case 0:
btn1.BackgroundColor = UIColor.Red;
break;
case 1:
btn2.BackgroundColor = UIColor.Red;
break;
case 2:
btn3.BackgroundColor = UIColor.Red;
break;
case 3:
btn4.BackgroundColor = UIColor.Red;
break;
case 4:
btn5.BackgroundColor = UIColor.Red;
break;
case 5:
btn6.BackgroundColor = UIColor.Red;
break;
case 6:
btn7.BackgroundColor = UIColor.Red;
break;
case 7:
btn8.BackgroundColor = UIColor.Red;
break;
case 8:
btn9.BackgroundColor = UIColor.Red;
break;
}
}
}
private void FinishGame()
{
foreach (var item in _uIButtons)
{
item.Enabled = false;
}
}
private void InitiliazeGameUI(bool buttonsEnable)
{
foreach (var item in _uIButtons)
{
item.Enabled = buttonsEnable;
item.SetTitle("", UIControlState.Normal);
item.BackgroundColor = UIColor.Gray;
}
lblStatus.Text = string.Empty;
}
private void ResetUI()
{
meSelector.Enabled = true;
meSelector.ControlStyle = UISegmentedControlStyle.Bezeled;
InitiliazeGameUI(true);
gameObjectManager.Initiliaze();
}
private void ManageAddingGameObject(short coordinateNo, UIButton button)
{
GameObject gameObject = null;
if (meSelector.SelectedSegment == 0)
gameObject = new XGameObject(coordinateNo);
else
gameObject = new OGameObject(coordinateNo);
gameObjectManager.AddGameObjectInGame(gameObject);
SetGraphics(gameObject, button);
gameObjectManager.CalculateGameCondition();
}
private void SetGraphics(GameObject gameObject, UIButton button)
{
button.SetTitle(gameObject.AssetText, UIControlState.Normal);
}
public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
// Release any cached data, images, etc that aren't in use.
}
}
}