-
Notifications
You must be signed in to change notification settings - Fork 0
/
67-mayin-tarlasi-mekanikleri.htm
320 lines (232 loc) · 9.47 KB
/
67-mayin-tarlasi-mekanikleri.htm
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
<!DOCTYPE html>
<html>
<head>
<title>Mayın Tarlası Mekanikleri</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<!-- LIBRARY FILES -->
<link rel="stylesheet" type="text/css" href="basic/basic.min.css">
<script src="basic/basic.min.js" type="text/javascript" charset="utf-8"></script>
<style>
body {
overflow: hidden;
}
</style>
<script>
// DEĞİŞKENLER
var GAME_PAGE_WIDTH = 600
var selectedLevelIndex = 1
var levelList = [
{
name: "Easy",
width: 10,
height: 10,
mines: 15,
boxSize: 40,
fontSize: 28
},
{
name: "Medium",
width: 15,
height: 15,
mines: 30,
boxSize: 30,
fontSize: 21
},
{
name: "Hard",
width: 20,
height: 20,
mines: 40,
boxSize: 20,
fontSize: 15
}
]
var level = levelList[selectedLevelIndex]
// Taşıyıcı ekran
var a1
var upperBoxList = {}
var boxList = {}
var bombList = {}
// ÖZEL FONKSİYONLAR
// İlk çalışan fonksiyon.
var start = function() {
page.color = "white"
page.fit(GAME_PAGE_WIDTH, GAME_PAGE_WIDTH)
// BOX: Oyun oynama ekranı
a1 = createBox(0, 0, GAME_PAGE_WIDTH, page.height)
that.center("left")
// BOX: Küçük kutuların taşındığı kutu. Parametreler: Yatay kare sayısı, Dikey kare sayısı.
a1.b1 = createTheField(level.width, level.height)
a1.add(that)
that.color = "white"
that.border = 1
that.center()
// Bombaları yerleştir. Parametreler: Oluşturulacak bomba sayısı.
placeTheBombs(level.mines)
// Bomba sayılarını işaretle. Parametreler: Yatay kare sayısı, dikey kare sayısı.
markDangerZones(level.width, level.height)
// Ekran boyutu değiştiğinde, yeniden ortala.
page.onResize(function() {
page.fit(GAME_PAGE_WIDTH, GAME_PAGE_WIDTH)
a1.width = GAME_PAGE_WIDTH
a1.height = page.height
a1.center("left")
a1.b1.center()
})
}
// DİĞER FONKSİYONLAR
// Oyun ekranının içinde küçük kutuları oluşturur.
var createTheField = function(leftCount, topCount) {
upperBoxList = {}
boxList = {}
var BOX_WIDTH = level.boxSize
var BOX_HEIGHT = level.boxSize
var boxField = createBox(0, 0)
for (var i = 0; i < topCount; i++) {
for (var j = 0; j < leftCount; j++) {
var upperBoxName = "imgx" + j + "y" + i
var boxName = "boxx" + j + "y" + i
boxField[boxName] = createBox(0, 0, BOX_WIDTH, BOX_HEIGHT)
boxField.add(that)
that.left = j * BOX_WIDTH
that.top = i * BOX_HEIGHT
that.round = 1
boxList[boxName] = that
boxField[upperBoxName] = createImage(0, 0, BOX_WIDTH, BOX_HEIGHT)
boxField.add(that)
var imageFilePath = "images/67/box.svg"
that.load(imageFilePath)
that.left = j * BOX_WIDTH
that.top = i * BOX_HEIGHT
that.x = j
that.y = i
that.color = "white"
that.onClick(function(self) {
self.visible = 0
openNextWhiteBoxes(self.x, self.y)
})
upperBoxList[upperBoxName] = that
}
}
boxField.width = (leftCount * BOX_WIDTH) + 2
boxField.height = (topCount * BOX_HEIGHT) + 2
makeBasicObject(boxField)
return boxField
}
// Bombaları yerleştirir.
var placeTheBombs = function(count) {
bombList = {}
for (var i = 0; i < count; i++) {
var boxName = "boxx" + Math.floor(Math.random() * level.width) + "y" + Math.floor(Math.random() * level.height)
// Her bir kareye sadece bir bomba yerleştirilebilir.
if (!bombList[boxName]) {
var obj = boxList[boxName]
obj.color = "whitesmoke"
obj.dangerColor = "whitesmoke"
obj.border = 1
obj.round = 3
// IMAGE: Bomba resmi
obj.imgBomb = createImage(0, 0, obj.width, obj.height)
obj.add(that)
var imageFilePath = "images/67/bomb.png"
that.load(imageFilePath)
that.space = 10
bombList[boxName] = that
} else {
i--
}
}
}
// Bomba sayılarını işaretle.
var markDangerZones = function(leftCount, topCount) {
var coorPatern = [
[0, -1],
[1, -1],
[1, 0],
[1, 1],
[0, 1],
[-1, 1],
[-1, 0],
[-1, -1]
]
for (var i = 0; i < topCount; i++) {
for (var j = 0; j < leftCount; j++) {
var boxName = "boxx" + j + "y" + i
var boxObject = boxList[boxName]
var bombCount = 0
if (bombList[boxName]) {
// boxObject.color = "white"
} else {
for (var k = 0; k < 8; k++) {
var x = j + coorPatern[k][0]
var y = i + coorPatern[k][1]
var nextBoxName = "boxx" + x + "y" + y
if (boxList[nextBoxName]) {
if (bombList[nextBoxName]) {
bombCount++
}
}
}
if (bombCount != 0) {
boxObject.lblNumber = createLabel(0, 0, level.boxSize)
boxObject.add(that)
that.text = bombCount
that.fontSize = level.fontSize
that.textAlign = "center"
that.textColor = "black"
}
boxObject.color = "white"
switch (bombCount) {
case 0:
boxObject.color = "white"
break
case 1:
boxObject.color = "#FFEB3A"
break
case 2:
boxObject.color = "#FAA236"
break
case 3:
boxObject.color = "#FE5D49"
break
default:
boxObject.color = "#D0021B"
break
}
}
}
}
}
// Tıklanan kutunun arka planı beyaz ise, beyaz olan tüm komşularını da aç.
var openNextWhiteBoxes = function(boxX, boxY) {
var coorPatern = [
[0, -1],
[1, 0],
[0, 1],
[-1, 0]
]
var boxName = "boxx" + boxX + "y" + boxY
var upperBoxName = "imgx" + boxX + "y" + boxY
if (boxList[boxName].color == "white") {
for (var k = 0; k < 4; k++) {
var x = boxX + coorPatern[k][0]
var y = boxY + coorPatern[k][1]
var nextBoxName = "boxx" + x + "y" + y
if (boxList[nextBoxName]) {
var nextUpperBoxName = "imgx" + x + "y" + y
var nextUpperBoxObject = upperBoxList[nextUpperBoxName]
if (nextUpperBoxObject.visible == 1) {
nextUpperBoxObject.visible = 0
openNextWhiteBoxes(nextUpperBoxObject.x, nextUpperBoxObject.y)
}
}
}
}
}
</script>
</head>
<body>
<!-- HTML content -->
</body>
</html>