I made a game!!

Started by
1 comment, last by Roboguy 18 years, 7 months ago
I proudly present my first complete game: Minesweeper! linky How to play: find all the mines on the board. Left-click opens the cell under the pointer, right-click toggles the flag on the cell, and double clicking opens up all cells surrounding a numbered visible cell. A corrosponing number of flags must be placed for it to try. NOTE: I have only tested it on Maxthon 1.3.3 and IE 6.0 SP2. It may not work on any other browser. The game is made completely in HTML/&#106avascript with some PHP for setting the size of the board and to place the cells. Currently it's set at Expert (though that may change at any time). I'm planning on adding a way of using html GET statements to select board size at load/link time. I started the project on Wedensday evening and coded and drank wine until I had to leave for the party. I continued on Thursday, and got it finished that day except for the image counters and the visual style. I took the Friday off and continued today. Total time spent on the project was probably about 15 hours. I think I may have been sober for about 3 of those [smile]. The hardest thing to code was the flood-fill algorithm used when the player clicks on a cell with no neighboring mines. I would have used a recursive algortihm, but unfortunately &#106avascript doesn't protect it's variables. After trying to do it by storing the temporary values in an array, I gave up and made a non-recursive 4-way flood fill algorithm with edge detection to find those annoying corners that would otherwise go undetected. It works, but it's pretty slow. On my computer it takes a couple of seconds to flood fill a 30x16 board with 1 mine. In normal games such as 30x16 it's fast enough not to be noticable though. Sometimes it doesn't catch the clicks, and especially the right-clicks, but apart from that it looks and acts exactly like the Minesweeper included with Windows XP. So much in fact that I probably will have to change the graphics to avoid being sued by Microsoft for stealing thier pixels [smile]. The left+right click combo for opening all surrounding fields wasn't possible AFAIK, so I did it with a double click instead. Unlike MS Minesweeper, the number of undiscovered mines isn't visible in the counter until the player clicks. I tried to fix it, but even OnLoad tries to call the function before the ID of the DIV is set. I can fix it by "hard coding" it, but I haven't done that yet. It shouldn't take more than a few minutes, so by the time you read this I may already have fixed it. Lessons learned: &#106avascript is very badly suited for recursive algorithms that include for-loops. Events in HMTL/&#106avascript is not 100% accurate. It sometimes doesn't recognize all clicks. Coding while drunk isn't any harder then when sober. For me it's actually easier as I don't spend unnecessary time trying to get everything 100% perfect.
Advertisement
It doesn't work in Firefox...I refuse to use IE. Sorry!
Doesn't seem to work on Opera either (it seems to display about right, but clicking on it doesn't do anything).

This topic is closed to new replies.

Advertisement