Thread: Random Damage

  1. #1
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331

    Random Damage

    I have a monster in my game and i am curious as to how i can make his damage given and take completely random. Heres what i have now:

    //edit: Also how would i make a timer, that when it hits 0 from a number like 100, would end the game.

    PHP Code:
    if (user_x == && user_x == 7)
        {
            
    std::cout <<"You see a wolf.\n";
            
    std::cout <<"Fight (F)\nRun (R)\n\n";

            if (
    key == 'F' || key == 'f')
            {
                
    std::cout <<"You damage the wolf for 10 health points.\n";
                
    std::cout <<"It is dead. You gain 5 experience points.\n\n";

                
    xp += 5;
            }

            if (
    key == 'R' || key == 'r')
            {
                
    std::cout <<"You run from the wolf.\n";
                
    std::cout <<"You gain nothing.\n\n";
            }
        } 

  2. #2
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    1) rand()...RTFAQ for more info

    2) you can't use a timer with consoles, because consoles don't allow multi-threading, which you would need in order to have a timer for a console program.

  3. #3
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    thnx tech, i'll just use a != statement for the ending of program, with a decrement variable.

    Thnx for the info bro.

  4. #4
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Originally posted by TechWins
    2) you can't use a timer with consoles, because consoles don't allow multi-threading, which you would need in order to have a timer for a console program.
    Yes, they do!

    At least in Windows, which is the only OS I've been programing for. I think it is possible in Linux too, though.

    In windows, use CreateThread()
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  5. #5
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    its ok i used a variable with a not statement.

    Thnx tho!

  6. #6
    Shadow12345
    Guest
    for my timer I use 3 int variables (this was in console in windows)
    int BeginTime, EndTime, TotalTime;
    BeginTime = GetTickCount();
    //event
    //
    EndTime = GetTickCount();
    TotalTime = EndTime - BeginTime;
    cout << "Your event lasted " << TotalTime << " MS" << endl;
    //note it may not be milliseconds because I am stupid

    Interested note:
    after 47 days GetTickCount() wraps around and starts at zero! (GetTickCount counts the number of ms the operatign system has been on)

    EDIT:
    You need windows.h in order for GetTickCoun() to work...or maybe its time.h, dammit I don't remember...also ride or die you never have the user input the string do you?

  7. #7
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Well, when I asked this question a very long time ago I'm pretty sure I was informed that you can't multi-thread in consoles. As well as that there wasn't any way to create a timer. Either I was misinformed or I misunderstood. Glad that I know otherwise now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lesson #3 - Math
    By oval in forum C# Programming
    Replies: 2
    Last Post: 04-27-2006, 08:16 AM
  2. In a game Engine...
    By Shamino in forum Game Programming
    Replies: 28
    Last Post: 02-19-2006, 11:30 AM
  3. Another brain block... Random Numbers
    By DanFraser in forum C# Programming
    Replies: 2
    Last Post: 01-23-2005, 05:51 PM
  4. Changing random #'s
    By napkin in forum C++ Programming
    Replies: 6
    Last Post: 05-02-2002, 12:30 PM
  5. Best way to generate a random double?
    By The V. in forum C Programming
    Replies: 3
    Last Post: 10-16-2001, 04:11 PM