Minesweeper

Member
Posts: 144
Joined: 2009.11
Post: #1
There are many implementations of Minesweeper like it, but this one is mine.

I got really bored and made a Minesweeper clone. Only I can't draw for beans, so they turned into OS 8-ish bombs. The complete source is available on Github, with a pre-chewed binary available as well.

Right now clicking on stuff works. You can actually play a full game of minesweeper. However, the high-scores do not work. I'm planning on implementing that with Core Data. Not because Core Data is the best tool for the job (NSCoder probably is), but because I've never used it before and this is a situation where I could use it and not totally mess something up.

For those unfamiliar with the mechanics of Minesweeper, the goal is to flag all mines without putting a flag where a Mine is not. You flag a mine by right-clicking on a tile. You can discover how many mines are adjacent to any tile by left-clicking on it.

Thoughts and suggestions are appreciated!

Everyone's favourite forum lurker!
https://github.com/NSError
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Bug: turn up a square that's not a mine, right-click it to mark it as a mine (should probably be disallowed!), right click it again to get ?, right click it again to return it face down, then left-click it. About 50% of the time, you get the number you originally turned up, as "expected". The other half of the time, it's transmuted into a bomb and you explode!
Quote this message in a reply
Moderator
Posts: 3,573
Joined: 2003.06
Post: #3
I would suggest that you could just as well use NSUserDefaults to save all your high scores and stuff, unless you really have your heart set on CoreData. NSUserDefaults is silly easy to use.

Out of curiosity, is this the first game you've released?
Quote this message in a reply
Member
Posts: 144
Joined: 2009.11
Post: #4
OneSadCookie Wrote:Bug: turn up a square that's not a mine, right-click it to mark it as a mine (should probably be disallowed!), right click it again to get ?, right click it again to return it face down, then left-click it. About 50% of the time, you get the number you originally turned up, as "expected". The other half of the time, it's transmuted into a bomb and you explode!

Well, if I disallowed marking any tile as flagged, then you could simply right click 64 times and win the game.

If you're using the older build, then that might be the transmutation bug. I re-worked a lot of the internals so it's much more stable now. Including fixing a bug where I was using memory I hadn't allocated! Specifically the minefield, so no wonder if didn't work.

AnotherJake Wrote:I would suggest that you could just as well use NSUserDefaults to save all your high scores and stuff, unless you really have your heart set on CoreData. NSUserDefaults is silly easy to use.

Out of curiosity, is this the first game you've released?

Well, I already know how to use NSUserDefaults. So using this to get to know Core Data seems more productive to me.

Yeah, this is the first game I've released.

Everyone's favourite forum lurker!
https://github.com/NSError
Quote this message in a reply
Moderator
Posts: 3,573
Joined: 2003.06
Post: #5
(Jul 14, 2010 04:18 PM)cmiller Wrote:  Well, I already know how to use NSUserDefaults. So using this to get to know Core Data seems more productive to me.
Ah I see, yes that makes sense.

cmiller Wrote:Yeah, this is the first game I've released.
Congratulations! It took me years to get the first one out there. This is how the disease starts. Smile
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
I just downloaded the build you linked here... so no, not an older one.

The win condition should be "every square is flagged or face-up, and there are the same number of flags as mines".

There's no reason to allow flagging an already-face-up tile...
Quote this message in a reply
Member
Posts: 144
Joined: 2009.11
Post: #7
Well I found and fixed both of your bugs. I'm unsure on changing the victory condition, however. By requiring that every tile be either clicked or flagged, you prevent people from saving time by flagging things they think are mines without clicking on the places they think aren't mines. I think the requirement that there be flags on all the mines and no flags on any place which doesn't have a mine is a good win condition. It prevents people from flagging all 64 tiles to win the game.

I haven't uploaded a new build though; I think I might do that when I get the high-scores working.

Everyone's favourite forum lurker!
https://github.com/NSError
Quote this message in a reply
Member
Posts: 144
Joined: 2009.11
Post: #8
Sorry for the double-post, but...

A super-ultra special thanks to forum member McSpider, who put his artistic talents towards shiny new art to replace my feeble attempt at "placeholder art."

It looks loverly!

[Image: mwDvd.png] [Image: n8BkU.png]

As well as a shiny new app-icon!

[Image: DyKmr.png]

I'm also working on the high-scores screen, which isn't done yet... I have a window with a table, but now need to populate the table with data.

When I get that working I plan on releasing a new build.

Following that, my next project is to work on a system for storing the art in a kind of archive file (TAR, ZIP, or something like that). Right now it's all just kind of hanging out on the filesystem which is Bad Form. Granted, it's not too many files, but this kind of resource system is the kind of code that can be re-used later.

Everyone's favourite forum lurker!
https://github.com/NSError
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #9
(Jul 18, 2010 02:31 AM)cmiller Wrote:  Following that, my next project is to work on a system for storing the art in a kind of archive file (TAR, ZIP, or something like that). Right now it's all just kind of hanging out on the filesystem which is Bad Form.

How's that again?
Quote this message in a reply
Member
Posts: 144
Joined: 2009.11
Post: #10
(Jul 18, 2010 05:39 AM)ThemsAllTook Wrote:  
(Jul 18, 2010 02:31 AM)cmiller Wrote:  Following that, my next project is to work on a system for storing the art in a kind of archive file (TAR, ZIP, or something like that). Right now it's all just kind of hanging out on the filesystem which is Bad Form.

How's that again?

Too many small files wastes drive sectors, which are comparatively larger on modern hard drives. It also fills up the master file table, causing the whole filesystem's performance to degrade. My theory is that it's not my job to fill up the user's drive with rubbish. I should take my itty bitty resources and package them up to conserve space and resources. That way the user can clog his or her own filesystem up.

These fears may or may not be well-founded on HFS+, but I prefer to keep that kind of thinking up. It's absolutely the case for NTFS, and if I ever get hit on the head by a large object at sufficient speed, it's possible that I'll try Windows programming. In which situation packaging resources into an archive is an absolute must-have. Some Linux file systems also suffer from MFT overload. ext2, ext3, and XFS that I've experienced. And we can't expect users to go off and make their own ReiserFS partitions, now can we? Rasp

Additionally it helps indexing services ignore the resources.

But yeah, that's my thinking in a nutshell. It shouldn't be hard to integrate. Simply keep folders of all the rubbish in the project directory, then add a build script to ZIP/TAR it up, then have Xcode stick that into the resources of the application bundle. The tricky part (for me, because I've never done it before) is getting content out of the archive. Considering that I haven't even decided upon a format, it's fair to say I'm still in the formative process of imagining the solution. Smile

Everyone's favourite forum lurker!
https://github.com/NSError
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #11
Nice, usually the "don't use individual files" argument is made without any logic to back it up. Good that you put some thought into it, I hadn't thought of those things!
Quote this message in a reply
Member
Posts: 144
Joined: 2009.11
Post: #12
Well for something as small as Minesweeper, it isn't at all worthwhile. But I plan to transplant the resource system into other projects. Something smaller like Minesweeper is a wonderful sandbox to work on various systems for use in larger projects. For instance, my entire use of plists for indexing the various images is total overkill. I could easily hard-code all that rot. But I plan on using a similar system in other projects, so I might as well develop the idea now.

Everyone's favourite forum lurker!
https://github.com/NSError
Quote this message in a reply
Post Reply