vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | Author: Jacob Bowers (Thronk on Mal'Ganis server) |
||
3 | |||
4 | ]] |
||
5 | |||
6 | |||
7 | MinesweeperOptions = {}; |
||
8 | local CS_BLANK = 0; |
||
9 | local CS_QUESTION = 1; |
||
10 | local CS_FLAGGED = 2; |
||
11 | local CS_CLEARED = 3; |
||
12 | local CS_MINE = 4; |
||
13 | local NUM_SQUARES = 81; |
||
14 | local NUM_MINES = 10; |
||
15 | local GameLost = 0; |
||
16 | local NumUncovered = 0; |
||
17 | |||
18 | local CellState = {state = 0, bMined = 0, num = 0}; |
||
19 | |||
20 | function Minesweeper_OnLoad() |
||
21 | |||
22 | this:RegisterEvent("VARIABLES_LOADED"); |
||
23 | |||
24 | SlashCmdList["MINESWEEPER"] = Minesweeper_SlashHandler; |
||
25 | SLASH_MINESWEEPER1 = "/minesweeper"; |
||
26 | |||
27 | MS_CreateMatrix(); |
||
28 | |||
29 | end |
||
30 | |||
31 | |||
32 | function Minesweeper_OnEvent(event) |
||
33 | |||
34 | if( event == "VARIABLES_LOADED") then |
||
35 | |||
36 | end |
||
37 | end |
||
38 | |||
39 | |||
40 | function MS_Test1() |
||
41 | PlaySoundFile("Sound\\Doodad\\G_Mortar.wav"); |
||
42 | end |
||
43 | |||
44 | |||
45 | function MS_CreateMatrix() |
||
46 | local sent = 0; |
||
47 | local cnt = 0; |
||
48 | local val = 0; |
||
49 | |||
50 | GameLost = 0; |
||
51 | NumUncovered = 0; |
||
52 | |||
53 | for i=1,NUM_SQUARES do |
||
54 | CellState[i] = {state = 0, bMined = 0, num = 0}; |
||
55 | |||
56 | getglobal("MSButton"..i.."TextureOverlay"):SetTexture(""); |
||
57 | |||
58 | if(random() > 0.5) then |
||
59 | getglobal("MSButton"..i.."Texture"):SetTexture("Interface\\AddOns\\Minesweeper\\ButtonPlainv3"); |
||
60 | else |
||
61 | getglobal("MSButton"..i.."Texture"):SetTexture("Interface\\AddOns\\Minesweeper\\ButtonPlainv3_2"); |
||
62 | end |
||
63 | getglobal("MSButton"..i):SetText(""); |
||
64 | end |
||
65 | |||
66 | while (sent == 0) do |
||
67 | |||
68 | val = floor(random()*NUM_SQUARES); |
||
69 | |||
70 | if ( val == 0 ) then |
||
71 | val = 1; |
||
72 | end |
||
73 | |||
74 | if ( CellState[val].bMined == 0 ) then |
||
75 | CellState[val].bMined = 1; |
||
76 | MS_UpdateCellNumbers(val); |
||
77 | cnt = cnt + 1; |
||
78 | end |
||
79 | |||
80 | if ( cnt >= NUM_MINES ) then |
||
81 | sent = 1; |
||
82 | end |
||
83 | end |
||
84 | |||
85 | |||
86 | end |
||
87 | |||
88 | |||
89 | function MS_UpdateCellNumbers(cellnum) |
||
90 | |||
91 | if ( MS_CheckIsInLeftmostColumn(cellnum) == nil) then |
||
92 | if ( cellnum - 10 > 0 ) then |
||
93 | CellState[cellnum-10].num = CellState[cellnum-10].num + 1; |
||
94 | end |
||
95 | end |
||
96 | |||
97 | |||
98 | if ( cellnum - 9 > 0 ) then |
||
99 | CellState[cellnum-9].num = CellState[cellnum-9].num + 1; |
||
100 | end |
||
101 | |||
102 | if ( MS_CheckIsInRightmostColumn(cellnum) == nil) then |
||
103 | if ( cellnum - 8 > 0 ) then |
||
104 | CellState[cellnum-8].num = CellState[cellnum-8].num + 1; |
||
105 | end |
||
106 | end |
||
107 | |||
108 | |||
109 | |||
110 | |||
111 | if ( MS_CheckIsInLeftmostColumn(cellnum) == nil) then |
||
112 | if ( cellnum - 1 > 0 ) then |
||
113 | CellState[cellnum-1].num = CellState[cellnum-1].num + 1; |
||
114 | end |
||
115 | end |
||
116 | |||
117 | if ( MS_CheckIsInRightmostColumn(cellnum) == nil) then |
||
118 | if ( cellnum + 1 <= NUM_SQUARES ) then |
||
119 | CellState[cellnum+1].num = CellState[cellnum+1].num + 1; |
||
120 | end |
||
121 | end |
||
122 | |||
123 | |||
124 | |||
125 | if ( MS_CheckIsInRightmostColumn(cellnum) == nil ) then |
||
126 | if ( cellnum + 10 <= NUM_SQUARES ) then |
||
127 | CellState[cellnum+10].num = CellState[cellnum+10].num + 1; |
||
128 | end |
||
129 | end |
||
130 | if ( cellnum + 9 <= NUM_SQUARES ) then |
||
131 | CellState[cellnum+9].num = CellState[cellnum+9].num + 1; |
||
132 | end |
||
133 | if ( MS_CheckIsInLeftmostColumn(cellnum) == nil) then |
||
134 | if ( cellnum + 8 <= NUM_SQUARES ) then |
||
135 | CellState[cellnum+8].num = CellState[cellnum+8].num + 1; |
||
136 | end |
||
137 | end |
||
138 | end |
||
139 | |||
140 | |||
141 | function MS_CheckIsInLeftmostColumn(cellnum) |
||
142 | if( cellnum == 1 or cellnum == 10 or cellnum == 19 or cellnum == 28 or cellnum == 37 or cellnum == 46 or cellnum == 55 or cellnum == 64 or cellnum == 73 ) then |
||
143 | return 1; |
||
144 | else |
||
145 | return nil; |
||
146 | end |
||
147 | end |
||
148 | |||
149 | function MS_CheckIsInRightmostColumn(cellnum) |
||
150 | if( cellnum == 9 or cellnum == 18 or cellnum == 27 or cellnum == 36 or cellnum == 45 or cellnum == 54 or cellnum == 63 or cellnum == 72 or cellnum == 81 ) then |
||
151 | return 1; |
||
152 | else |
||
153 | return nil; |
||
154 | end |
||
155 | end |
||
156 | |||
157 | function MS_CheckIsInBottommostRow(cellnum) |
||
158 | if( cellnum >= 72 ) then |
||
159 | return 1; |
||
160 | else |
||
161 | return nil; |
||
162 | end |
||
163 | end |
||
164 | |||
165 | function MS_CheckIsInTopmostRow(cellnum) |
||
166 | if( cellnum <= 9 ) then |
||
167 | return 1; |
||
168 | else |
||
169 | return nil; |
||
170 | end |
||
171 | end |
||
172 | |||
173 | function MS_UncoverMatrix() |
||
174 | local i; |
||
175 | |||
176 | GameLost = 1; |
||
177 | |||
178 | for i=1,NUM_SQUARES do |
||
179 | if ( CellState[i].bMined == 0 ) then |
||
180 | getglobal("MSButton"..i.."Texture"):SetTexture("Interface\\AddOns\\Minesweeper\\ButtonClearv2"); |
||
181 | else |
||
182 | if ( CellState[i].state ~= CS_MINE ) then |
||
183 | getglobal("MSButton"..i.."Texture"):SetTexture("Interface\\AddOns\\Minesweeper\\ButtonClearMinev2"); |
||
184 | else |
||
185 | getglobal("MSButton"..i.."Texture"):SetTexture("Interface\\AddOns\\Minesweeper\\ButtonMineHitv2"); |
||
186 | end |
||
187 | end |
||
188 | end |
||
189 | |||
190 | for i=1,NUM_SQUARES do |
||
191 | if ( CellState[i].num > 0 and CellState[i].bMined == 0) then |
||
192 | --getglobal("MSButton"..i):SetText(CellState[i].num); |
||
193 | MS_SetNumColor(i); |
||
194 | else |
||
195 | getglobal("MSButton"..i):SetText(""); |
||
196 | end |
||
197 | end |
||
198 | end |
||
199 | |||
200 | |||
201 | function MS_RecursiveClear(cellnum) |
||
202 | |||
203 | if (cellnum < 1 or cellnum > 81 ) then |
||
204 | return; |
||
205 | end |
||
206 | |||
207 | if ( CellState[cellnum].num == 0 and CellState[cellnum].state ~= CS_CLEARED and CellState[cellnum].bMined ~= 1) then |
||
208 | getglobal("MSButton"..cellnum.."Texture"):SetTexture("Interface\\AddOns\\Minesweeper\\ButtonClearv2"); |
||
209 | CellState[cellnum].state = CS_CLEARED; |
||
210 | NumUncovered = NumUncovered + 1; |
||
211 | getglobal("MSButton"..cellnum.."TextureOverlay"):SetTexture(""); |
||
212 | else |
||
213 | return; |
||
214 | end |
||
215 | |||
216 | if ( MS_CheckIsInLeftmostColumn(cellnum) == nil) then |
||
217 | if ( cellnum - 10 > 0 ) then |
||
218 | if ( CellState[cellnum-10].num == 0 ) then |
||
219 | MS_RecursiveClear(cellnum-10); |
||
220 | elseif ( CellState[cellnum-10].num ~= 0 ) then |
||
221 | getglobal("MSButton"..(cellnum-10).."Texture"):SetTexture("Interface\\AddOns\\Minesweeper\\ButtonClearv2"); |
||
222 | CellState[cellnum-10].state = CS_CLEARED; |
||
223 | MS_SetNumColor(cellnum-10); |
||
224 | --NumUncovered = NumUncovered + 1; |
||
225 | getglobal("MSButton"..(cellnum-10).."TextureOverlay"):SetTexture(""); |
||
226 | end |
||
227 | end |
||
228 | end |
||
229 | |||
230 | |||
231 | if ( cellnum - 9 > 0 ) then |
||
232 | if ( CellState[cellnum-9].num == 0 ) then |
||
233 | MS_RecursiveClear(cellnum-9); |
||
234 | elseif ( CellState[cellnum-9].num ~= 0 ) then |
||
235 | getglobal("MSButton"..(cellnum-9).."Texture"):SetTexture("Interface\\AddOns\\Minesweeper\\ButtonClearv2"); |
||
236 | CellState[cellnum-9].state = CS_CLEARED; |
||
237 | MS_SetNumColor(cellnum-9); |
||
238 | --NumUncovered = NumUncovered + 1; |
||
239 | getglobal("MSButton"..(cellnum-9).."TextureOverlay"):SetTexture(""); |
||
240 | end |
||
241 | end |
||
242 | |||
243 | if ( MS_CheckIsInRightmostColumn(cellnum) == nil) then |
||
244 | if ( cellnum - 8 > 0 ) then |
||
245 | if ( CellState[cellnum-8].num == 0 ) then |
||
246 | MS_RecursiveClear(cellnum-8); |
||
247 | elseif ( CellState[cellnum-8].num ~= 0 ) then |
||
248 | getglobal("MSButton"..(cellnum-8).."Texture"):SetTexture("Interface\\AddOns\\Minesweeper\\ButtonClearv2"); |
||
249 | CellState[cellnum-8].state = CS_CLEARED; |
||
250 | MS_SetNumColor(cellnum-8); |
||
251 | --NumUncovered = NumUncovered + 1; |
||
252 | getglobal("MSButton"..(cellnum-8).."TextureOverlay"):SetTexture(""); |
||
253 | end |
||
254 | end |
||
255 | end |
||
256 | |||
257 | |||
258 | |||
259 | |||
260 | if ( MS_CheckIsInLeftmostColumn(cellnum) == nil) then |
||
261 | if ( cellnum - 1 > 0 ) then |
||
262 | if ( CellState[cellnum-1].num == 0 ) then |
||
263 | MS_RecursiveClear(cellnum-1); |
||
264 | elseif ( CellState[cellnum-1].num ~= 0 ) then |
||
265 | getglobal("MSButton"..(cellnum-1).."Texture"):SetTexture("Interface\\AddOns\\Minesweeper\\ButtonClearv2"); |
||
266 | CellState[cellnum-1].state = CS_CLEARED; |
||
267 | MS_SetNumColor(cellnum-1); |
||
268 | --NumUncovered = NumUncovered + 1; |
||
269 | getglobal("MSButton"..(cellnum-1).."TextureOverlay"):SetTexture(""); |
||
270 | end |
||
271 | end |
||
272 | end |
||
273 | |||
274 | if ( MS_CheckIsInRightmostColumn(cellnum) == nil) then |
||
275 | if ( cellnum + 1 <= NUM_SQUARES ) then |
||
276 | if ( CellState[cellnum+1].num == 0 ) then |
||
277 | MS_RecursiveClear(cellnum+1); |
||
278 | elseif ( CellState[cellnum+1].num ~= 0 ) then |
||
279 | getglobal("MSButton"..(cellnum+1).."Texture"):SetTexture("Interface\\AddOns\\Minesweeper\\ButtonClearv2"); |
||
280 | CellState[cellnum+1].state = CS_CLEARED; |
||
281 | MS_SetNumColor(cellnum+1); |
||
282 | --NumUncovered = NumUncovered + 1; |
||
283 | getglobal("MSButton"..(cellnum+1).."TextureOverlay"):SetTexture(""); |
||
284 | end |
||
285 | end |
||
286 | end |
||
287 | |||
288 | |||
289 | |||
290 | if ( MS_CheckIsInRightmostColumn(cellnum) == nil ) then |
||
291 | if ( cellnum + 10 <= NUM_SQUARES ) then |
||
292 | if ( CellState[cellnum+10].num == 0 ) then |
||
293 | MS_RecursiveClear(cellnum+10); |
||
294 | elseif ( CellState[cellnum+10].num ~= 0 ) then |
||
295 | getglobal("MSButton"..(cellnum+10).."Texture"):SetTexture("Interface\\AddOns\\Minesweeper\\ButtonClearv2"); |
||
296 | CellState[cellnum+10].state = CS_CLEARED; |
||
297 | MS_SetNumColor(cellnum+10); |
||
298 | --NumUncovered = NumUncovered + 1; |
||
299 | getglobal("MSButton"..(cellnum+10).."TextureOverlay"):SetTexture(""); |
||
300 | end |
||
301 | end |
||
302 | end |
||
303 | if ( cellnum + 9 <= NUM_SQUARES ) then |
||
304 | if ( CellState[cellnum+9].num == 0 ) then |
||
305 | MS_RecursiveClear(cellnum+9); |
||
306 | elseif ( CellState[cellnum+9].num ~= 0 ) then |
||
307 | getglobal("MSButton"..(cellnum+9).."Texture"):SetTexture("Interface\\AddOns\\Minesweeper\\ButtonClearv2"); |
||
308 | CellState[cellnum+9].state = CS_CLEARED; |
||
309 | MS_SetNumColor(cellnum+9); |
||
310 | --NumUncovered = NumUncovered + 1; |
||
311 | getglobal("MSButton"..(cellnum+9).."TextureOverlay"):SetTexture(""); |
||
312 | end |
||
313 | end |
||
314 | if ( MS_CheckIsInLeftmostColumn(cellnum) == nil) then |
||
315 | if ( cellnum + 8 <= NUM_SQUARES ) then |
||
316 | if ( CellState[cellnum+8].num == 0 ) then |
||
317 | MS_RecursiveClear(cellnum+8); |
||
318 | elseif ( CellState[cellnum+8].num ~= 0 ) then |
||
319 | getglobal("MSButton"..(cellnum+8).."Texture"):SetTexture("Interface\\AddOns\\Minesweeper\\ButtonClearv2"); |
||
320 | CellState[cellnum+8].state = CS_CLEARED; |
||
321 | MS_SetNumColor(cellnum+8); |
||
322 | --NumUncovered = NumUncovered + 1; |
||
323 | getglobal("MSButton"..(cellnum+8).."TextureOverlay"):SetTexture(""); |
||
324 | end |
||
325 | end |
||
326 | end |
||
327 | end |
||
328 | |||
329 | |||
330 | function MS_SetNumColor(id) |
||
331 | |||
332 | getglobal("MSButton"..id):SetText(CellState[id].num); |
||
333 | |||
334 | if ( CellState[id].num == 1 ) then |
||
335 | getglobal("MSButton"..id):SetTextColor(0, 0, 1); |
||
336 | elseif ( CellState[id].num == 2 ) then |
||
337 | getglobal("MSButton"..id):SetTextColor(0, 1, 0); |
||
338 | else |
||
339 | getglobal("MSButton"..id):SetTextColor(1, 0, 0); |
||
340 | end |
||
341 | |||
342 | end |
||
343 | |||
344 | |||
345 | function MS_OnClick(id) |
||
346 | |||
347 | if ( GameLost == 1) then |
||
348 | return; |
||
349 | end |
||
350 | |||
351 | if ( IsAltKeyDown() ) then |
||
352 | DEFAULT_CHAT_FRAME:AddMessage(id); |
||
353 | return; |
||
354 | end |
||
355 | |||
356 | if ( IsControlKeyDown() and CellState[id].state ~= CS_CLEARED and CellState[id].state ~= CS_MINE ) then |
||
357 | if ( CellState[id].state ~= CS_FLAGGED ) then |
||
358 | getglobal("MSButton"..id.."TextureOverlay"):SetTexture("Interface\\AddOns\\Minesweeper\\Flag"); |
||
359 | CellState[id].state = CS_FLAGGED; |
||
360 | else |
||
361 | getglobal("MSButton"..id.."TextureOverlay"):SetTexture(""); |
||
362 | CellState[id].state = MS_BLANK; |
||
363 | end |
||
364 | return; |
||
365 | end |
||
366 | |||
367 | if ( IsShiftKeyDown() and CellState[id].state ~= CS_CLEARED and CellState[id].state ~= CS_MINE ) then |
||
368 | if( CellState[id].state ~= CS_QUESTION ) then |
||
369 | getglobal("MSButton"..id.."TextureOverlay"):SetTexture("Interface\\AddOns\\Minesweeper\\Question"); |
||
370 | CellState[id].state = CS_QUESTION; |
||
371 | else |
||
372 | getglobal("MSButton"..id.."TextureOverlay"):SetTexture(""); |
||
373 | CellState[id].state = MS_BLANK; |
||
374 | end |
||
375 | return; |
||
376 | end |
||
377 | |||
378 | if (CellState[id].state ~= CS_CLEARED and CellState[id].state ~= CS_QUESTION and CellState[id].state ~= CS_FLAGGED) then |
||
379 | if( CellState[id].bMined ~= 1 ) then |
||
380 | getglobal("MSButton"..id.."Texture"):SetTexture("Interface\\AddOns\\Minesweeper\\ButtonClearv2"); |
||
381 | --CellState[id].state = CS_CLEARED; |
||
382 | if ( CellState[id].num > 0) then |
||
383 | MS_SetNumColor(id); |
||
384 | CellState[id].state = CS_CLEARED; |
||
385 | NumUncovered = NumUncovered + 1; |
||
386 | |||
387 | tmpval = random(); |
||
388 | |||
389 | if(tmpval < 0.25) then |
||
390 | PlaySoundFile("Sound\\Spells\\TradeSkills\\MiningHitA.wav"); |
||
391 | elseif(tmpval >= 0.25 and tmpval < 0.5) then |
||
392 | PlaySoundFile("Sound\\Spells\\TradeSkills\\MiningHitA.wav"); |
||
393 | elseif(tmpval >= 0.5 and tmpval < 0.75) then |
||
394 | PlaySoundFile("Sound\\Spells\\TradeSkills\\MiningHitA.wav"); |
||
395 | elseif(tmpval >= 0.75) then |
||
396 | PlaySoundFile("Sound\\Spells\\TradeSkills\\MiningHitA.wav"); |
||
397 | end |
||
398 | else |
||
399 | getglobal("MSButton"..id):SetText(""); |
||
400 | MS_RecursiveClear(id); |
||
401 | PlaySoundFile("Sound\\interface\\OrcExploration.wav"); |
||
402 | end |
||
403 | |||
404 | getglobal("MSButton"..id.."TextureOverlay"):SetTexture(""); |
||
405 | |||
406 | else |
||
407 | getglobal("MSButton"..id.."Texture"):SetTexture("Interface\\AddOns\\Minesweeper\\ButtonClearMinev2"); |
||
408 | CellState[id].state = CS_MINE; |
||
409 | MS_UncoverMatrix(); |
||
410 | --PlaySoundFile("Sound\\Spells\\DynamiteExplode.wav"); |
||
411 | |||
412 | if(random() < 0.5) then |
||
413 | PlaySoundFile("Sound\\Creature\\GoblinMaleZanyNPC\\GoblinMaleZanyNPCPissed03.wav"); |
||
414 | else |
||
415 | PlaySoundFile("Sound\\Creature\\GoblinMaleZanyNPC\\GoblinMaleZanyNPCPissed04.wav"); |
||
416 | end |
||
417 | |||
418 | DEFAULT_CHAT_FRAME:AddMessage("YOU LOSE AT GOBLIN MINESWEEPER! TRY AGAIN!"); |
||
419 | end |
||
420 | end |
||
421 | |||
422 | Minesweeper_CheckWin(); |
||
423 | end |
||
424 | |||
425 | |||
426 | function Minesweeper_ShowMines() |
||
427 | for i=1,NUM_SQUARES do |
||
428 | |||
429 | if ( CellState[i].bMined == 1 ) then |
||
430 | getglobal("MSButton"..i.."Texture"):SetTexture("Interface\\AddOns\\Minesweeper\\ButtonClearMinev2"); |
||
431 | end |
||
432 | end |
||
433 | |||
434 | end |
||
435 | |||
436 | |||
437 | function Minesweeper_CheckWin() |
||
438 | local NumCleared = 0; |
||
439 | |||
440 | for i=1,NUM_SQUARES do |
||
441 | |||
442 | if ( CellState[i].state == CS_CLEARED ) then |
||
443 | NumCleared = NumCleared + 1; |
||
444 | end |
||
445 | end |
||
446 | |||
447 | if(NumCleared == NUM_SQUARES - NUM_MINES) then |
||
448 | GameLost = 1; |
||
449 | --PlaySoundFile("Sound\\interface\\LevelUp.wav"); |
||
450 | DEFAULT_CHAT_FRAME:AddMessage("YOU WIN GOBLIN MINESWEEPER!"); |
||
451 | |||
452 | if(random() < 0.5) then |
||
453 | PlaySoundFile("Sound\\Creature\\GoblinMaleZanyNPC\\GoblinMaleZanyNPCFarewell02.wav"); |
||
454 | else |
||
455 | PlaySoundFile("Sound\\Creature\\GoblinMaleZanyNPC\\GoblinMaleZanyNPCFarewell04.wav"); |
||
456 | end |
||
457 | else |
||
458 | --DEFAULT_CHAT_FRAME:AddMessage("DEBUG: "..NumCleared); |
||
459 | end |
||
460 | end |
||
461 | |||
462 | |||
463 | function Minesweeper_SlashHandler(cmd) |
||
464 | |||
465 | local args = {}; |
||
466 | local counter = 0; |
||
467 | local i, w; |
||
468 | local status; |
||
469 | local TmpStr = {}; |
||
470 | TmpStr = ""; |
||
471 | |||
472 | cmd = string.lower(cmd); |
||
473 | for w in string.gfind(cmd, "%w+") do |
||
474 | counter = counter + 1; |
||
475 | args[counter] = w; |
||
476 | end |
||
477 | |||
478 | if (args[1] == nil) then |
||
479 | MinesweeperFrame:Show(); |
||
480 | end |
||
481 | end |
||
482 | |||
483 |