Hello everyone. I've been wanting to develop a game for iPhone for a while, and after watching the iPhone SDK 3.0 I decided I would have a go. Having been a programmer for 6 years in the past, having even a published game in the market, I thought it would be possible.
However, I didn't mentioned that the programming experience that I had was mostly with Web programming, and the shipped game was developed by me in Flash ActionScript. You have already figured it out, right? It's being hard as hell to get even the most basic things running, since I've never seen C in my life. I only happen to know a little about Java, but this isn't helping.
I've seen all Getting Started videos, of course, and a lot of Objective-C tutorials... but I think it's hard to get the concept of everything like this, in one or two days.
Here's my problem (for now): here's a snippet of my custom class named Game ("Game.h" file):
and here's my startGame method in the "Game.m" file:
The first NSLog output is OK, it shows all 40 cards and its suits (that's what the getCardValue does), but the second NSLog output, when I try to access the Cards from inside the array, doesn't work. It doesn't even enter the "for", signaling that the tmpDeck array is probably empty.
If I added objects to the tmpDeck array (with the tmpDeck addObject method), why is there nothing inside?
The weird thing is, if I put a "for" loop to walk through the 40 items of the tmpDeck array, it shows (null) for everyone... but even if I try to go to the fiftieth item, that doesn't exists, it doesn't give me an error... it just shows (null). Is this the normal behavior of an array? I'm used to get an "index out of bounds" error in other programming languages.
I'm trying to keeping it to the basics, first writing the game logic and testing it through the NSLog, but I can't even do that! I'm very frustrated... I'm struggling to conform myself that programming for the iPhone is just for the real programmers, and not Flash-Web-programmers like me...
It would be great if someone could explain what am I doing wrong here...
Thank you very much.
However, I didn't mentioned that the programming experience that I had was mostly with Web programming, and the shipped game was developed by me in Flash ActionScript. You have already figured it out, right? It's being hard as hell to get even the most basic things running, since I've never seen C in my life. I only happen to know a little about Java, but this isn't helping.
I've seen all Getting Started videos, of course, and a lot of Objective-C tutorials... but I think it's hard to get the concept of everything like this, in one or two days.
Here's my problem (for now): here's a snippet of my custom class named Game ("Game.h" file):
Code:
@interface Game : NSObject {
int matchesPlayed;
NSMutableArray* players;
NSMutableArray* deck;
}
+ (Game*)startGame;
- (id)initGame;
- (NSMutableArray*)createDeck;
and here's my startGame method in the "Game.m" file:
Code:
- (NSMutableArray*)createDeck
{
NSMutableArray* tmpDeck;
Card* tmpCard = nil;
NSString* ranks = @"4567QJKA23";
NSString* suits = @"DSHC";
for (int count = 0; count < 40; count++) {
tmpCard = [Card createCardWithRank:[ranks substringWithRange:NSMakeRange(count % 10, 1)]
Suit:[suits substringWithRange:NSMakeRange(floor(count) / 10, 1)]];
NSLog(@"card %@", [tmpCard getCardValue]);
[tmpDeck addObject:tmpCard];
}
for (Card* obj in tmpDeck) {
NSLog(@"hello world");
}
return [tmpDeck autorelease];
}
The first NSLog output is OK, it shows all 40 cards and its suits (that's what the getCardValue does), but the second NSLog output, when I try to access the Cards from inside the array, doesn't work. It doesn't even enter the "for", signaling that the tmpDeck array is probably empty.
If I added objects to the tmpDeck array (with the tmpDeck addObject method), why is there nothing inside?
The weird thing is, if I put a "for" loop to walk through the 40 items of the tmpDeck array, it shows (null) for everyone... but even if I try to go to the fiftieth item, that doesn't exists, it doesn't give me an error... it just shows (null). Is this the normal behavior of an array? I'm used to get an "index out of bounds" error in other programming languages.
I'm trying to keeping it to the basics, first writing the game logic and testing it through the NSLog, but I can't even do that! I'm very frustrated... I'm struggling to conform myself that programming for the iPhone is just for the real programmers, and not Flash-Web-programmers like me...
It would be great if someone could explain what am I doing wrong here...
Thank you very much.