Thread: damage dealt algorithm

  1. #16
    Registered User
    Join Date
    Feb 2003
    Posts
    62
    Cerin,

    I can't help much with your programme, but when reading one of my programming books the other day, I found something which of course is something most people probally do but I think its one of the best programming tips I ever heard.

    That is to do one function at a time make sure that function works correctly first then move on to the next that way you dont write out a whole programme and get lost because you got 12 functions all with errors.

    It's made my life easier and I can promise it will make it easier for you too

  2. #17
    Registered User
    Join Date
    Dec 2004
    Location
    UK
    Posts
    109
    Code:
    fight=rand()%5
    returns a nubmer from 0 to 4 (as per definition of the modulo operation)
    if you want it to return a nubmer from 1 to 5 just add 1

    Code:
    fight = rand() % 5 + 1

  3. #18
    Registered User
    Join Date
    Dec 2004
    Posts
    465
    The only thing I am working with is the combat system. Thanks for the tip sigfriedmcwild
    My computer is awesome.

  4. #19
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Cerin, first of all you'd better learn to indent your code properly. Ouch! I can barely tell what's part of which if and whatnot!

    That aside, I can't figure out what you mean:
    This works fine if I take out the cout at the end, but while its in it has an error. Should I put a for loop in the while loop so when the monsters hp goes down it stays down?
    What error? In what? Huuuh?

    Anyway, you have a problem, because you're not storing the result of finalcom in mHp1. That means the monster's HP will never change unless you hit it with enough damage to kill with 1 hit.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  5. #20
    Registered User
    Join Date
    Dec 2004
    Posts
    465
    Awsome it worked thanks for the help I know I had that error I just hadn't got around to fixing it yet, but I just did. The other error I was talking was the cout at the end of that case statement when the monster did actually die. Instead of displaying he is dead windows would tell me the program mud.exe had an error, but it seemed to have fixed itself so no worries.



    Edit: But alas another problem has arisen. I need make the mhp1 variable go back to its original value so that next time you got to fight it won't he already dead. I tried putting this in in a few places, but it won't work.
    Code:
    	case 'f':
    	cout<<"You encounter one dumb sunava..........\n";
    	while(finalcom>0){              //fight
    	fight=rand()%6;
    	cin>>combat;
    	if(combat=='a'){                //attack
    	     fcom=(((strength*3)+agility)/fight);
    	     finalcom=mhp1-fcom;                   //calculations
    	     mhp1=finalcom;
    	}
    	if(finalcom>0){
    	     cout<<finalcom<<"\n";
    	}
    	}
    	cout<<"\nHe is dead\n";

    Where to put it?
    Last edited by cerin; 03-22-2005 at 11:27 PM.
    My computer is awesome.

  6. #21
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    After he is dead, of course.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  7. #22
    Registered User
    Join Date
    Dec 2004
    Posts
    465
    Except that won't work since I have this menu. So I change just a few variables depending on what they pick.
    Code:
    	case 'f':
    	cout<<"1-man\n";
    	cout<<"2-goblin\n";
    	cin>>monster;
    	if(monster=1){
    	mhp1=20;          <---------------------can't get Vb code to work
    	cout<<"You encounter a man.\n";
    	}
    	while(finalcom>0){              //fight
    	fight=rand()%6;
    	cin>>combat;
    	if(combat=='a'){                //attack
    	fcom=(((strength*3)+agility)/fight);
    	finalcom=mhp1-fcom;
    	mhp1=finalcom;
    	}
    	if(finalcom>0){
    	cout<<finalcom<<"\n";
    	}
    	}
    	cout<<"\nHe is dead\n";                     //death
    Last edited by cerin; 03-26-2005 at 10:43 PM.
    My computer is awesome.

  8. #23
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    Dear:
    [x] Clueless Newbie
    [ ] Troller
    [ ] "Me too"-er
    [ ] Spammer
    [ ] Racist
    [ ] Expert on everything (EOE)
    [ ] Flamerthrower
    [ ] News Groupie


    You Are Being Flamed Because:

    [x] You obviously don't know anything about the topic at hand
    [ ] You are trying to make money on a non-commercial newsgroup
    [ ] You posted a picture (binary) of something YOU think is really cool in an unmoderated TEXT ONLY news group
    [ ] You started a long, stupid thread
    [ ] You continued spreading a long stupid thread
    [ ] You started a thread that has been discussed here continuously for the last year and a half
    [ ] Your post is absurdly off topic for where you posted it
    [ ] You didn't pay attention to the originating post header and posted a followup to crossposted robot-generated spam
    [ ] You posted a "test" in a discussion group rather than in alt.test
    [ ] You posted a "YOU ALL SUCK" message
    [x] You posted low-IQ flamebait
    [ ] You posted a blatently obvious troll
    [ ] You followed up to a blatently obvious troll
    [ ] You said "X rules, Y sucks" and gave no support for your lame statement
    [ ] You said "me too" to something and added NOTHING to the discussion
    [ ] You make no sense
    [ ] You posted the same text multiple times
    [ ] You made a post yet failed to say anything
    [ ] You posted a phone-sex ad
    [ ] You posted a stupid pyramid money making scheme
    [ ] You claimed a pyramid-scheme/chain letter for money was legal
    [ ] Your margin settings (or lack of) make your post unreadable
    [ ] You posted SCREAMING in RANDOM CAPS (OR IN ALL CAPS) for NO APPARENT REASON
    [ ] You posted a 2 line reply with PAGES of unecessary quoted text
    [ ] You didn't quote AT ALL.
    [x] You didn't do anything specific, but appear to be so generally worthless that you are being flamed anyway


    To Repent, You Must:

    [x] Refrain from posting until you have a vague idea what you're doing
    [x] Read the FAQ before posting something else.
    [ ] READ every post in this group for two weeks so you can have some idea about what is discussed here
    [ ] Read every newsgroup you posted to for a week
    [x] Give up your AOL account
    [x] Give up your webTV account
    [ ] Bust up your modem with a hammer and eat it
    [ ] Jump into a bathtub while holding your monitor (monitor must be plugged in)
    [ ] Actually post something relevant
    [ ] Post to alt.test
    [ ] Print your home phone number and address in your ads
    [ ] Be the guest of honor in alt.flame for a month
    [x] Nothing, we'll let you go this time


    In Closing, I'd Like to Say:

    [x] Get a clue
    [ ] Get a life
    [ ] Go away
    [ ] Grow up
    [ ] Never post again
    [ ] You need to seek psychiatric help
    [x] Like a neutered dog, you just don't get it
    [ ] Take your gibberish somewhere else
    [x] Go back to school and actaully learn something
    [ ] Learn how to post or get off the usenet
    [x] Don't take offense at this, I just like to use this form
    [ ] All of the above

  9. #24
    Registered User
    Join Date
    Mar 2005
    Posts
    16
    read the random number tutorial right here on cprogramming.com :P
    http://www.cprogramming.com/tutorial/random.html

    this is what you need to do: var = rand() % (HIGH - LOW + 1) + LOW;
    var is the variable to store, obviously, and HIGH and LOW are constants that you can #define such as, in your case i guess 1 and 5.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Implement of a Fast Time Series Evaluation Algorithm
    By BiGreat in forum C Programming
    Replies: 7
    Last Post: 12-04-2007, 02:30 AM
  2. In a game Engine...
    By Shamino in forum Game Programming
    Replies: 28
    Last Post: 02-19-2006, 11:30 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM