Mar 7 2008

GeekGameBoard — Getting closer to iPhone-ready

To encourage development, I’ve started an open source project based on the GeekGameBoard game-development sample code that Apple published last December (which, by a strange coincidence, I wrote.) I hope to have it ready for iPhone game development soon. It runs on iPhones, too!

You can browse or download the source code over at bitbucket.org. It’s BSD-licensed, and your contributions are of course welcome.

The changes since Apple’s original sample-code release are:

  • It no longer requires garbage collection. I love GC, but it’s not supported on the iPhone, where I am definitely planning to use GGB.
  • I fixed some memory leaks of CoreGraphics objects.
  • I fixed an assertion-failure when kinging a checker.

What Is GeekGameBoard?

GeekGameBoard is a small Objective-C framework for implementing the user interface of a board or card game. Many games can be implemented in less than 150 lines of code.

It also demonstrates generally-useful Core Animation techniques like:

  • Hit testing
  • Dragging CALayers with the mouse
  • Loading images from files and setting them as layer contents
  • 3D “card-flip” animations

Framework classes include Bit, Piece, PlayingCard, HexGrid and more. It comes with sample games from Klondike solitaire to Checkers and even Tic-Tac-Toe. It’s all ready for you to add AI, network play, new game definitions…

GeekGameBoard runs on Mac OS X 10.5 or later. iPhone support is coming soon.

Klondike

Hexchequer

Pssst! Game Pieces!

Icon websites like IconFactory, InterfaceLift and DeviantArt are great places to get artwork for game pieces. (My personal favorite game pieces are Ginko’s Icons, shown on the right.) Just be aware that most icons, even if freeware, require you to get the copyright holder’s permission for anything other than personal use.


24 Responses to “GeekGameBoard — Getting closer to iPhone-ready”

  • Chris Ryland Says:

    Jens—How did you end up writing GGB for Apple? I thought you were working on the PubSub stuff near the end of your tenure. Just curious.

    Looking forward to the iPhone version!

    Also, how can you make this an OSS project, if it’s an Apple dev example? Is their license that lenient?

  • Jens Alfke Says:

    I wrote GGB in my spare time (especially over Thanksgiving) and submitted it to ADC as sample code.

    Yes, the license really is that lenient. More so than BSD, even. All it says is that, if you distribute an unmodified version of the source code, you have to retain their copyright notice. And my new version has been modified, of course.

  • Joe Heck Says:

    Jens — I’m a little new to Mercurial - is there a way to use “hg pull” with your site to get the latest and greatest as you update it?

  • http://weebull.myopenid.com/ Says:

    You should be able to ‘hg clone http://mooseyard.com/hg/hgwebdir.cgi/GeekGameBoard/’ and then just ‘hg pull’ )to get the changesets) and ‘hg update’ (to update your working directory to the latest tip) when you want new versions.

  • Floroskop Says:

    Hello!
    I think this try.

  • Kevin Doughty Says:

    I am implementing chess for the GGB. I’ve got the basics down, but I might need to email you with some questions if you don’t mind.

  • Jens Alfke Says:

    Kevin — Cool. Feel free to ask (email jens at this domain.)

  • Chert Pellett Says:

    Doesn’t compile for the iPhone, two errors, something stupid like ‘gcc’ exited with status blah or something, - I’m new to Mac development, so I’m expecting an error message like ‘X error on line Y of file Z’ or something, but instead it takes me to the first line of the code in the file.

    It does say died on line 0…

    Looks like it is trying to run something related to the iPhone simulator…

    {standard input}:156:symbol: “_kPieceStyle1” can’t be undefined in a subtraction expression

    (Ok, well, I cut and pasted it and it changed it totally to something different than it was… go figure….)

    Any ideas?

    I downloaded the SDK for the iPhone about a week ago..

  • Chert Pellett Says:

    Ok, Found the ‘treat warnings as errors’ and turned that off (shouldn’t have to, but that got it to compile), but it said “_log” and “_warn” not defined… What do I need to link with to pick those up?

    -Chert

  • Neil T Says:

    I get the following error using the downloaded source.

    /Maui-Dev/GeekGameBoard/GeekGameBoard-db8640a38faf/Source/QuartzUtils.m: In function ‘CreateCGImageFromFile’:
    /Maui-Dev/GeekGameBoard/GeekGameBoard-db8640a38faf/Source/QuartzUtils.m:81: warning: implicit declaration of function ‘Warn’

    /Maui-Dev/GeekGameBoard/GeekGameBoard-db8640a38faf/Source/CheckersGame.m: In function ‘-[CheckersGame checkForWinner]’:
    /Maui-Dev/GeekGameBoard/GeekGameBoard-db8640a38faf/Source/CheckersGame.m:221: warning: implicit declaration of function ‘Log’

    Where are these defined?

  • ger Says:

    Great idea!!!
    Is any tutorial available? i found it a little difficult.

    Thanks

  • Jens Alfke Says:

    ger — Sorry, there’s no documentation other than the API docs in the headers. But the included games serve as sample code.

  • ger Says:

    Hi
    I download the last code from your repo, i found a couple of errors:
    -GoGame: Doesn´t work because it can´t find the image.
    -TicTacTocGame: only shows the board

    Thanks

  • Bryan Hughes Says:

    You ROCK!!!!

    Thank you for posting this code - it is really clean and excellent learning material.

  • Ian Dawson Says:

    How do yo run Klondike on the iPhone using GeekGameBoard ? When I run it I get the checkers game opening, I cannot switch to Klondike or the other games.

  • Lips Says:

    Hi,
    I just compiled the GGB for iPhone simulator and it only does the checkers game. Which part tells it what game to play? Sorry, just trying to start learning Obj-C!
    Thanks!

  • Lips Says:

    Actually, I just figured out how to change the game that it compiles for in iPhoneAppDelegate, but it crashes during launch with Klondike and after the board appears on Go.

  • Floyd Says:

    Hi, i’m kinda new to the whole iPhone programming, and I tried to make a separate Checkers game. It’s probably quite easy with this source code, but a little help would be extremely appreciated! Thanks in advance.

    Floyd

  • David Says:

    I was able to get klondike to launch on the iPhone by adding the following to the end of KlondikeGame.m

    - (NSString*) stateString {return @”“;}
    - (void) setStateString: (NSString*)s { }
    - (BOOL) applyMoveString: (NSString*)move {return NO;}

    and changing line 64 in iPhoneAppDelegate.m to:

    [self startGameNamed: @”KlondikeGame”];

  • Lips Says:

    Hi David,

    Are you saying to put those three lines at the very end of KlondikeGame.m? Before the end statement or after? I tried it both ways and get a fatal error either way.

    Regards,
    Steve

    • jens Says:

      Those are method definitions, so they go before the @end.

      If you’re copying and pasting, make sure you’ve converted any curly quotes back into regular double-quote characters.