Object Oriented Card Game
but, there's still some little kinks.
The instance method -init... should only be ever called once per alloc'd instance (this is up to you and your code). (This is also why most Cocoa programming tutorials suggest you nest the alloc/inits.) So therefore, you shouldn't ever have to check the instance members against nil, just set them. When you alloc an object it's instance members are all nil/NULL.
I'm assuming you're referencing the instance variables being set in -(Rank *)initWithName: Symbol: method. I think I got the getter/setter technique confused with the alloc/init technique. Here's the method now.
-(Rank *)initWithName:(NSString *)aName Symbol:(NSString *)aSymbol
self = [super init];
if (self != nil)
name = [aName retain];
symbol = [aSymbol retain];
kelvin Wrote:also, in your dealloc method...
[super dealloc]; should always be the last line of your subclass' dealloc method. Calling it first like you do can release important stuff and cause serious problems. Do your subclass member clean up, then pass to the superclass to do the final clean up.
My bad. Here's the new -dealloc method.
I dunno, but doesn't this seem a little overkill? I'm interested, because you've managed to make it act pretty "english" (i.e. no cryptic arrays of cards, etc). But I would have never thought to do it this way... Neat, though. Keep it up.
Honestly, I wouldn't have thought about creating complete classes to represent primative aspects of a playing card. Originally, I thought about using a C enumeration or possibly a C struct. After I stumbled across the programming challenge, I really enjoyed the author's explanation of the problem and the typical pit-falls made by novice programmers. If you get a chance, read the article that I included in my first post. It really helped me understand some of the decisions to 'overkill' the problem.
After running a few tests, I'm finding that all my nice static class objects aren't being initialized properly. I ran the gdb and realized that the +initialize method is NOT sending messages to the -initWithName: Symbol: method at all. This leads me to believe that +initialize methods cannot send messages to instance methods of the same class. I've googled for more information on this, but so far, nothing definitive has been said about using custom instance methods inside the +initialize method. Anyone have a clue as to what might be going on?
in your +initialize classmethod.
Quote:ACE = [[Rank alloc] initWithName:@"Ace" Symbol:@"A"];to...
ACE = [[self alloc] initWithName:@"Ace" Symbol:@"A"];
15.4" MacBook Pro revA
and get rid of those allocWithZone, etc. overrides. If you're returning nil from allocWithZone, you're not gonna be able to allocate anything in the first place.
15.4" MacBook Pro revA
Don't override the basic release, retain, autorelease mechanism unless you have a really good reason. Instead, just ensure that you retain it once when its created and nobody releases it.
Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Possibly Related Threads...
|Game engines with object programming||JonnyThunder||3||9,323||
Aug 16, 2010 10:42 AM
Last Post: SethWillits
|Coding A Card Game||Jerm #1||3||6,161||
Apr 11, 2010 03:05 PM
Last Post: TimMcD