Looping Text based battle

This is a discussion on Looping Text based battle within the C++ Programming forums, part of the General Programming Boards category; I've just started this and I can't seem to get my characters attack to loop. I've tried, but the loop ...

  1. #1
    Games!? pujuman's Avatar
    Join Date
    Dec 2004
    Location
    Idaho, U.S.A.
    Posts
    14

    Looping Text based battle

    I've just started this and I can't seem to get my characters attack to loop. I've tried, but the loop is confusing for me, and I was wondering if anyone could tell me or show me how to loop.

    What I'm trying to loop:
    Code:
    while (gob > 0){
        const int LOW = 6;
        const int HIGH = 9;
        time(&seconds);
        srand((unsigned int) seconds);
        attack = rand() % (HIGH - LOW + 1) + LOW;
        cout<<"***Slash***"<<endl;
        cout<<"The Goblin has "<<gob - attack<<" life left!"<<endl;
    }
    As you can see I already tried while to loop it.
    Btw, I am doing this in Visual Studio.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well for starters, you only ever call srand one time in your entire program. So put it outside the loop. Furtheromore, "gob" never changes its value inside your loop.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Games!? pujuman's Avatar
    Join Date
    Dec 2004
    Location
    Idaho, U.S.A.
    Posts
    14
    Alright, thanks, I took a class at Digipen 5 months ago and this was all basic stuff they taught, but I forgot it (I was waiting for the program). Sorry if this was a basic question, lol.

  4. #4
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,807
    Read This

    Then read this:
    • First:
      There is no need to declare those two const's in your loop make them global or you can put them at the top of your function.

    • Second:
      You only need to call srand one time in your program.

    • Third
      Your not actully changing the value of gob you are just printing it out change it to.

      Code:
      gob = gob - attack;
    Woop?

  5. #5
    Games!? pujuman's Avatar
    Join Date
    Dec 2004
    Location
    Idaho, U.S.A.
    Posts
    14
    yea, I saw that, everything you stated I fixed. Now I have another dilemma. I was wondering, how can I make it so the character (the player) receives damage? I'm already using the const int for the damage done to the Goblin, but I want the damage done to me random too. Any ideas or suggestions?

  6. #6
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,807
    Well you could make a variable based on the "strength" of a certain type of creature.
    Use that in a similar type of formula that you are using for goblin damage.
    Woop?

  7. #7
    Games!? pujuman's Avatar
    Join Date
    Dec 2004
    Location
    Idaho, U.S.A.
    Posts
    14
    alright, I'll try that. If I get a snag, I'll either look at the tutorials, or I'll come back here. Thanks for the help!

  8. #8
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,807
    Structs are really good for this kinda thing.
    You code make one to hold basic characteristics.
    Code:
    struct character
    {
      int strength;
      int health;
      int wisdom;
      //so on 
    };
    Then anywhere you needed a new creature you could just use that struct.
    Code:
    character player;
    character goblin;
    
    player.strength = 10;
    player.health = 10;
    player.wisdom = 0;//cause we know players aren't smart :)
    
    goblin.strength = 5;
    goblin.health = 7;
    goblin.wisdom = 2;
    Last edited by prog-bman; 12-18-2004 at 04:26 AM.
    Woop?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. text based game
    By PippinofTook in forum Game Programming
    Replies: 5
    Last Post: 08-24-2005, 06:56 PM
  2. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 03:49 PM
  3. making a text based game
    By MisterSako in forum C++ Programming
    Replies: 1
    Last Post: 12-05-2004, 12:20 PM
  4. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM
  5. Text Based Game
    By drdroid in forum C++ Programming
    Replies: 2
    Last Post: 02-18-2002, 05:21 PM

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