Quote:
Originally Posted by will.ray
here is my card and deck class... it is working in simulator... I am c# programmer... is there anything that might blow up a real iphone or get rejected by app store???
thanks... code follows..
Code:
//
// card.m
//
//
// Created by Admin on 2/10/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "card.h"
@implementation card
-(void) setRank: (int) n {
rank = n;
}
-(int)rank{
return rank;
}
-(void) setSuit: (NSString *) s {
suit = s;
}
-(NSString *)suit{
return suit;
}
@end
--------
//
// deck.m
//
//
// Created by Admin on 2/10/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "deck.h"
@implementation deck
-(id) init {
self = [super init];
maincardlist = [[NSMutableArray alloc] init];
cardlist = [[NSMutableArray alloc] init];
shuffledlist = [[NSMutableArray alloc] init];
return self;
}
-(void) setupDeck{
int i;
for(i=1; i < 14; i++)
{
card *c;
c = [[card alloc]init];
[c setRank:i];
[c setSuit:(NSString *)"d"];
[cardlist addObject:c];
}
for(i=1; i < 14; i++)
{
card *c;
c = [[card alloc]init];
[c setRank:i];
[c setSuit:(NSString *)"h"];
[cardlist addObject:c];
}
for(i=1; i < 14; i++)
{
card *c;
c = [[card alloc]init];
[c setRank:i];
[c setSuit:(NSString *)"c"];
[cardlist addObject:c];
}
for(i=1; i < 14; i++)
{
card *c;
c = [[card alloc]init];
[c setRank:i];
[c setSuit:(NSString *)"s"];
[cardlist addObject:c];
}
int numcardsleft = 52;
card *c;
int x;
for(x=0;x<52;x++)
{
c = [cardlist objectAtIndex:x];
[maincardlist addObject:c];
}
while(numcardsleft>1)
{
x = random() % (numcardsleft);
c = [cardlist objectAtIndex:x];
[shuffledlist addObject:c];
[cardlist removeObjectAtIndex:x];
numcardsleft--;
}
c = [cardlist lastObject];
[cardlist removeLastObject];
[shuffledlist addObject:c];
c = [shuffledlist lastObject];
[shuffledlist removeLastObject];
[self setCurrentCard:c];
}
-(void) shuffleDeck{
[cardlist release];
cardlist = [[NSMutableArray alloc] init];
int numcardsleft = 52;
card *c;
int x;
for(x=0;x<52;x++)
{
c = [maincardlist objectAtIndex:x];
[cardlist addObject:c];
}
[shuffledlist release];
shuffledlist = [[NSMutableArray alloc] init];
while(numcardsleft>1)
{
x = random() % (numcardsleft);
c = [cardlist objectAtIndex:x];
[shuffledlist addObject:c];
[cardlist removeObjectAtIndex:x];
numcardsleft--;
}
c = [cardlist lastObject];
[cardlist removeLastObject];
[shuffledlist addObject:c];
c = [shuffledlist lastObject];
[shuffledlist removeLastObject];
[self setCurrentCard:c];
}
-(void)gotoNextCard{
[self setCurrentCard:[shuffledlist lastObject]];
[shuffledlist removeLastObject];
}
-(void) setCurrentCard: (card *) c {
currentCard = c;
}
-(card *)currentCard{
return currentCard;
}
@end
|
Hi will.ray, i am developing a card game, i try to follow your code but im stuck on the part where i need to display the image of the card on the players cards hand image.
What i did is create a class "cards" set the rank, suit, and card image.
My question is how can i display the image of the card on that class to a UIimage that represent the players cards hand.
Here is my code..
//
// PusoyDosViewController.m
// PusoyDos
//
// Created by Gary Sanchez on 9/11/09.
// Copyright __MyCompanyName__ 2009. All rights reserved.
//
#import "PusoyDosViewController.h"
#import "cards.h"
@implementation PusoyDosViewController
@synthesize pCard0, pCard1, pCard2, pCard3,
pCard4, pCard5, pCard6, pCard7,
pCard8, pCard9, pCard10, pCard11,
pCard12;
@synthesize legelPlays, lastPlayed;
//method to load players card
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableArray *imageArray = [[NSMutableArray alloc] initWithObjects:
[UIImage imageNamed:@"d1.png"],
[UIImage imageNamed:@"d2.png"],
[UIImage imageNamed:@"d3.png"],
[UIImage imageNamed:@"d4.png"],
[UIImage imageNamed:@"d5.png"],
[UIImage imageNamed:@"d6.png"],
[UIImage imageNamed:@"d7.png"],
[UIImage imageNamed:@"d8.png"],
[UIImage imageNamed:@"d9.png"],
[UIImage imageNamed:@"d10.png"],
[UIImage imageNamed:@"d11.png"],
[UIImage imageNamed:@"d12.png"],
[UIImage imageNamed:@"d13.png"],
nil];
mainCardsList = [[NSMutableArray alloc] init];
int i;
for(i = 0; i < 13; i++) {
cards *c;
c = [[cards alloc] init];
[c setRank:i];
[c setSuit:@"d"];
[c setcardsPic:[imageArray objectAtIndex:i]];
[mainCardsList addObject:c];
}
pCard0.image = [mainCardsList objectAtIndex:1];
the image display a black color.
Thanks..