Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Nitrex88

macrumors newbie
Original poster
Dec 30, 2007
11
0
Hi, awhile back I asked for basic programming ideas to challenge myself in objective-C, a language that i am not very advanced in. One idea that was suggested was Conways game of Life found here...

http://en.wikipedia.org/wiki/Conway's_Game_of_Life

I was very interested in this challenge and have sat down many times over the last few weeks trying to make such a program in xcode 3, using objective-C. So far I have been unsuccessful and need some help.
1.) What is best to use as a "cell". I was thinking a square button or picture view.
2.) What method should i use to detect the neighboring cells

If anyone has any suggestions it would greatly appreciated. Also i cant seem to find this program for mac except on java, which i am not that good at, so if anyone knows where to find this program already made with non-java source code, u could point me to that. Thanks in advance.
 

sord

macrumors 6502
Jun 16, 2004
352
0
Hi, awhile back I asked for basic programming ideas to challenge myself in objective-C, a language that i am not very advanced in. One idea that was suggested was Conways game of Life found here...

http://en.wikipedia.org/wiki/Conway's_Game_of_Life

I was very interested in this challenge and have sat down many times over the last few weeks trying to make such a program in xcode 3, using objective-C. So far I have been unsuccessful and need some help.
1.) What is best to use as a "cell". I was thinking a square button or picture view.
2.) What method should i use to detect the neighboring cells

If anyone has any suggestions it would greatly appreciated. Also i cant seem to find this program for mac except on java, which i am not that good at, so if anyone knows where to find this program already made with non-java source code, u could point me to that. Thanks in advance.
You may want to instead consider using OpenGL. Using a lot of buttons or a lot of picture viewers is (sorry for the harshness) a HORRIBLE idea.

Sample code to the rescue! (I got bored last year in one of my classes and just so happened to make exactly what you want, though no guarantee on quality - haven't looked at the code for a year).

Builds just fine in XCode 3
http://home.earthlink.net/~valiantsoul/life.zip

Hope this helps! When its not running you can click to add blocks.

EDIT: You may want to extend it so the blocks can go offscreen instead of just ending.
 

Catfish_Man

macrumors 68030
Sep 13, 2001
2,579
2
Portland, OR
You may want to instead consider using OpenGL. Using a lot of buttons or a lot of picture viewers is (sorry for the harshness) a HORRIBLE idea.

Sample code to the rescue! (I got bored last year in one of my classes and just so happened to make exactly what you want, though no guarantee on quality - haven't looked at the code for a year).

Builds just fine in XCode 3
http://home.earthlink.net/~valiantsoul/life.zip

Hope this helps! When its not running you can click to add blocks.

EDIT: You may want to extend it so the blocks can go offscreen instead of just ending.


While that might be the "correct" way to do it (I'm not sure I agree!), it's not such a great way to learn Cocoa. Were I him, I would either do it using NSMatrix, or, preferably take the opportunity to learn more about custom drawing and event handling in NSViews. Not terribly difficult, but useful any time you need a custom Cocoa widget.
 

Doctor Q

Administrator
Staff member
Sep 19, 2002
40,078
8,343
Los Angeles
I find it's more fun, when coding the Game of Life, to have the squares wraparound horizontally and vertically on the grid, even though you display it on a plane. For example, a cell in the leftmost column is considered a neighbor of the cell in the same row in the rightmost column, and the same kind of wraparound top to bottom.

That way, moving patterns like a glider don't break up at the boundaries, and can wrap around as if they were on an infinite grid.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.