-
tripping all over myself
Im trying to write a simple txt adv game. I trying to figure how to simulate die rolls to do combat. how do I reset kbhit() to roll every time this, function runs wild!and does not wait for a new random number is there any @$%# hope for this function
///it is called 4 times per round of combat
int die_roll(int power,char who)
int roll;
if(who=='h') //if hero is rolling
{cout<<"engage or somethin";
while(!kbhit())rand();
roll=rand();
roll=roll % power//hero max attack or defense
return roll;}
else//enemy
{cout<<"enemy action";
//same as above
}
-
Pygmy Monkey
Aaghh please use [c o d e] [/ c o d e] tags???
-
This is ErionD again.
For rand functions you do
int a = rand() % 7; // this does 0-6
or maybe
int a = (rand()% 7)+1; //does 1-7
or maybe you can do it like this i dunno
int a = rand();
a = a%blabla;
but my versions are simpler
-
Don't forget srand() to seed the rand function
-
Pygmy Monkey
Oh yeah thats right, include time.h and use
srand(time(NULL));
before the randomizing. Once is enough.
Its to make the random numbers different each time you start the prog
Popular pages
Recent additions