Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 09-14-2009, 11:32 PM   #10 (permalink)
garysanchez_29
Registered Member
 
Join Date: Sep 2009
Posts: 1
garysanchez_29 is on a distinguished road
Default

Quote:
Originally Posted by will.ray View Post
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..
garysanchez_29 is offline   Reply With Quote
 

» Advertisements
» Online Users: 809
25 members and 784 guests
ADY, azertyle, BinHex, djohnson, D_V, givensur, gmarro, HarrysLad, jNoxx, jujuforce, mattyaitken, mkjarred, mtl_tech_guy, ncc1701e, Pincode, pipposanta, reficul, Renrob, Rikco, Rudy, sacha1996, shigaugi, srhasan, Sunzanne, tassaga
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,276
Threads: 93,953
Posts: 402,301
Top Poster: BrianSlick (7,971)
Welcome to our newest member, Sunzanne
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:29 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.