Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 30, 2009, 04:47 AM   #1
iphonedevelop18
macrumors member
 
Join Date: Feb 2009
A few Questions...

First of all I am making a tic tac toe game.

1. how can a set an int to a random number, ie.
Code:
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!
iphonedevelop18 is offline   0 Reply With Quote
Old Mar 30, 2009, 06:54 AM   #2
mccannmarc
macrumors 6502
 
Join Date: Aug 2008
Location: Manchester, UK
Send a message via MSN to mccannmarc
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:-

Code:
difficulty = 5;
srandom(time(NULL));
choice = (random() % difficulty) + 1;
if (choice != 2){
}
__________________
DudeWare site:- http://www.dude-ware.co.uk DudeWare forum:- http://www.forum.dude-ware.co.uk
mccannmarc is offline   0 Reply With Quote
Old Mar 30, 2009, 07:32 AM   #3
jnic
macrumors 6502a
 
Join Date: Oct 2008
Location: Cambridge
2. NSTimer
jnic is offline   0 Reply With Quote
Old Mar 30, 2009, 01:09 PM   #4
iphonedevelop18
Thread Starter
macrumors member
 
Join Date: Feb 2009
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?

Last edited by iphonedevelop18; Mar 30, 2009 at 02:03 PM.
iphonedevelop18 is offline   0 Reply With Quote
Old Mar 31, 2009, 02:38 AM   #5
CocoaPuffs
macrumors 68010
 
Join Date: Aug 2008
Quote:
Originally Posted by jnic View Post

Code:
- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay
CocoaPuffs is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
A few questions?? Maybe not a few :-) Pinkstiletto66 iPhone 2 Dec 12, 2010 10:27 PM
Do you edit video ?? A few questions., ... and a few answers already from PC users! igmolinav Digital Video 20 Sep 12, 2010 07:24 PM
I have a few "light leaks" and have a few questions Millah iPhone Tips, Help and Troubleshooting 1 Sep 28, 2008 01:28 PM
Few Questions about a few things davidcb13 Mac Peripherals 4 Aug 22, 2005 06:21 PM
Buying PowerBook In A Few Hours, Had A Few Questions Though??? jumpman25 Buying Tips, Advice and Discussion (archive) 44 May 31, 2004 10:49 PM


All times are GMT -5. The time now is 12:36 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC