PDA

View Full Version : A few Questions...




iphonedevelop18
Mar 30, 2009, 04:47 AM
First of all I am making a tic tac toe game.

1. how can a set an int to a random number, ie.

difficulty = 5;
choice = (random() % difficulty) + 1;
if (choice != 2){
}

it will stay the same throughout as i tried to set difficulty to 100 and it would stay the same.

2. How can I delay the reaction of the computer.

Thanks!



mccannmarc
Mar 30, 2009, 06:54 AM
I will answer your first question but I don't quite get what you mean by the second one

The reason your random number will be the same is because you are not seeding the random number off of anything. if you put the following line before your code for generating the random number you will find it will start working. Try this:-


difficulty = 5;
srandom(time(NULL));
choice = (random() % difficulty) + 1;
if (choice != 2){
}

jnic
Mar 30, 2009, 07:32 AM
2. NSTimer (http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html)

iphonedevelop18
Mar 30, 2009, 01:09 PM
mccannmarc

Yea I already seeded it in the app delegate under didfinish launching or whatever. So I don't think I have to seed it again do I?

CocoaPuffs
Mar 31, 2009, 02:38 AM
2. NSTimer (http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html)


- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay