tripping all over myself

This is a discussion on tripping all over myself within the C++ Programming forums, part of the General Programming Boards category; Im trying to write a simple txt adv game. I trying to figure how to simulate die rolls to do ...

  1. #1
    Unregistered
    Guest

    Angry 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
    }

  2. #2
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    Aaghh please use [c o d e] [/ c o d e] tags???

  3. #3
    Unregistered
    Guest
    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

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    559
    Don't forget srand() to seed the rand function

  5. #5
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    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 subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21