calculating attack and defense

This is a discussion on calculating attack and defense within the C++ Programming forums, part of the General Programming Boards category; im stuck whats a good formula for calculating attack and defense? grr im stumped i dont need anyn code i ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    196

    calculating attack and defense

    im stuck whats a good formula for calculating attack and defense?
    grr im stumped i dont need anyn code i just need a good formula?

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,803
    Need a little more to work with than just that. Presumably you have two (or more) entites/objects that have some sort of statistics related to these attributes to which you need to add a little bit of randomness to things in order to perform some calculation/check?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    196
    err im just using attack and defense variables nothing special
    im looking for something like attack + 10% / defense but obviously thats no good ..

  4. #4
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Of course, because that helps.

    For all we know it could be a fork attacking a pea.

  5. #5
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,740
    You're that stats guy from the recent thread about pointers. I know you have more code than you're suggesting: you already said you were making a text-based RPG. In that case using the stats as part of the calculation would be perfect.

    damage = (strength + speed) * luck
    or something.

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    196
    haha ya yur write lol
    but there are no speed or luck variables ill post my code

    Code:
    #include <cstdlib>
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    void create();
    
    void createdata(string race);
    
    void attack();
    
    
    int yn;
    struct stats{
    string huname;
    string elname;
    string maname;
    string dename;
    string race;
    int lvl;
    int hel;
    double att;
    double def;
    double mage;
    double arch;
    double agi;
    double mon;
    double exp;
    };
    stats player;
    stats opponent;
    int main()
    {
    string select;
    do
    {
        cout<<"welcome to my little game i like to call\n";
        cout<<"FABLE RIPOFF\n";
        cout<<"\n\n\n";
        cout<<"please choose an option,\n";
        cout<<"tutorial is recommended for beginners\n\n";
        cout<<"play game(type play)\n";
        cout<<"load(type load)\n";
        cout<<"tutporial(type tut)\n";
        cout<<"quit(type quit)\n";
        cin>>select;
        cout<<endl;
        if(select == "play" || select == "Play")
        {
                  system("cls");
                  create();
                  cin.get();
        }
        if(select == "tut" || select == "Tut")
        {
                  cout<<"under construction\n";
                  cin.get();
        }
        if(select == "quit" || select == "Quit")
        {
                  break;
        }
        cin.get();
    }while(select != "quit" || select != "Quit");
    }
    void create(){
    string race;
    string yn;
    cout<<"which race do you want to be?\n";
    cout<<"\n\n";
    cout<<"human(press h)\n";
    cout<<"elf(press e)\n";
    cout<<"mage(press m)\n";
    cout<<"demon(press d)\n";
    cout<<"please choose an option\n";
    cin>>race;
    if(race == "h" || race == "H" )
    {
    cout<<"humans are not a preferred race for battles mainly because of there\n";
    cout<<"stupidity,they are however the only race that shops will talk to\n";
    cout<<"but because of this they cant go into other lands shops other than\n";
    cout<<"philostone.at the moment no human has survived even a minimal attack\n";
    cout<<"from another monster,will you?\n";
    cout<<"are you sure you want to be human\n";
    cin>>yn;
    if(yn == "y" || yn == "Y")
    {
    createdata(race);
    }
    else
    {
        system("cls");
             create();
    };
    }
    else if(race == "e" ||race == "E")
    {
    cout<<"elves are an amazing race,known for there absoloute mastery in \n";
    cout<<"archery,choosing this race will assure you a spot in the archers\n";
    cout<<"guild,they are also the only race other than mages to be\n";
    cout<<"able to do magic,but dont let that fool you there no mages\n";
    cout<<"but there very small which means this is what they have to rely\n";
    cout<<"on just magic and archery but being small gives them amazing speed\n";
    cout<<"allowing them to flee from every battle they face\n";
    cout<<"are you sure you want to be an elf?\n";
    cin>>yn;
    if(yn == "y" || yn == "Y")
    {
    createdata(race);
    }
    else
    {
        system("cls");
             create();
    };
    }
    else if(race == "m" || race == "M")
    {
    cout<<"mages are the most powerfull magicians and also most likely\n";
    cout<<"to finish the game to the very end,and being able to join\n";
    cout<<"the magic guild gives them the arsenal of magic they need\n";
    cout<<"provided they have the money to buy the spells of coarse\n";
    cout<<"are you sure you want to be a mage?\n";
    cin>>yn;
    if(yn == "y" || yn == "Y")
    {
    createdata(race);
    }
    else
    {
        system("cls");
             create();
    };
    }
    else if(race == "d" || race == "D")
    {
    cout<<"demons dont care about archery or magicks they care about\n";
    cout<<"BRUTE strenth there dumb as a doorknob but stronger than \n";
    cout<<"anything else in the world\n";
    cout<<"nobody whose fought a demon in a brute strenth battle\n";
    cout<<"has lived to tell the tale\n";
    cout<<"are you sure you want to be a demon?\n";
    cin>>yn;
    if(yn == "y" || yn == "Y")
    {
    createdata(race);
    }
    else
    {
        system("cls");
             create();
    };
    };
    }
    void createdata(string race){
         if(race == "h" || race =="H")
         {
    string huname;
         cout<<"what is your humans name?\n";
         cin>>huname;
    system("cls");
         cout<<"hmm "<< huname <<" if your sure\n";
         cout<<"here are your stats\n";
         player.lvl = 1;
         player.hel = 100;
         player.att = 3;
         player.def = 2;
         player.agi = 3;
         player.mon = 0;
         player.exp = 0;
    cout<<"level "<<player.lvl<<endl;
    cout<<"health "<<player.hel<<endl;
    cout<<"attack "<<player.att<<endl;
    cout<<"defense "<<player.def<<endl;
    cout<<"agility "<<player.agi<<endl;
    cout<<"money "<<player.mon<<endl;
    cout<<"experience "<<player.exp<<endl;
    }
    else if(race == "e" || race == "E")
    {
    string elname;
    cout<<"what is your elves name?\n";
    cin>>elname;
    system("cls");
    cout<<"hmm "<< elname <<" if your sure\n";
    cout<<"here are your stats\n";
         player.lvl = 1;
         player.hel = 100;
         player.att = 2;
         player.def = 2;
         player.agi = 3;
         player.arch = 4;
         player.mage = 1;
         player.mon = 0;
         player.exp = 0;
    cout<<"level "<<player.lvl<<endl;
    cout<<"health "<<player.hel<<endl;
    cout<<"attack "<<player.att<<endl;
    cout<<"defense "<<player.def<<endl;
    cout<<"agility "<<player.agi<<endl;
    cout<<"archery "<<player.arch<<endl;
    cout<<"mage "<<player.mage<<endl;
    cout<<"money "<<player.mon<<endl;
    cout<<"experience "<<player.exp<<endl;
    }
    else if(race == "m" || race == "M")
    {
    string maname;
    cout<<"what is your mages name?\n";
    cin>>maname;
    system("cls")
    cout<<"hmm "<< maname <<" if your sure\n";
    cout<<"here are your stats\n";
         player.lvl = 1;
         player.hel = 100;
         player.att = 1;
         player.def = 1;
         player.agi = 2;
         player.mage = 5;
         player.mon = 0;
         player.exp = 0;
    cout<<"level "<<player.lvl<<endl;
    cout<<"health "<<player.hel<<endl;
    cout<<"attack "<<player.att<<endl;
    cout<<"defense "<<player.def<<endl;
    cout<<"agility "<<player.agi<<endl;
    cout<<"mage "<<player.mage<<endl;
    cout<<"money "<<player.mon<<endl;
    cout<<"experience "<<player.exp<<endl;
    }
    else if(race == "d" || race == "D")
    {
    string dename;
    cout<<"what is your demons name?\n";
    cin>>dename;
    system("cls")
    cout<<"hmm "<< dename <<" if your sure\n";
    cout<<"here are your stats\n";
         player.lvl = 1;
         player.hel = 100;
         player.att = 5;
         player.def = 5;
         player.agi = 2;
         player.mon = 0;
         player.exp = 0;
    cout<<"level "<<player.lvl<<endl;
    cout<<"health "<<player.hel<<endl;
    cout<<"attack "<<player.att<<endl;
    cout<<"defense "<<player.def<<endl;
    cout<<"agility "<<player.agi<<endl;
    cout<<"money "<<player.mon<<endl;
    cout<<"experience "<<player.exp<<endl;
    }
    attack()
    {
    //where my attack formual will be
    }
    };
    that there is about 260 lines of kik @$$ code sorry just had to say that

  7. #7
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    What are you wanting to calculate.

  8. #8
    Registered User
    Join Date
    Sep 2005
    Posts
    196
    ...the attack...

  9. #9
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Lilhawk, it has been bugging me for near the whole time you have been here. If you want help on something, and or need to reply. Please use whole words, and decent grammar.

    Now onto your code, you have a TON of redunant code in there. You can probably cut 60-70% of the code out of there and make it a ton more readable.

    EDIT: Also else does not get a ; at the end.

    Another thing:
    Code:
    #include <iostream>
    #include <string.h>
    #include <ctype.h>
    
    using std::cin;
    using std::cout;
    using std::string;
    using std::transform;
    
    int main(int argc, char *argv[])
    {
        string test = "G";
        transform (test.begin(),test.end(), test.begin(), tolower);
        if(test == "g") {
            cout<<"AMAZING";
        } else {
            cout<<"Nope";
        }
        cin.get();
    }
    Check that out. Transform() is from ctype.h.
    Last edited by Wraithan; 07-06-2006 at 01:55 PM.

  10. #10
    Registered User
    Join Date
    Sep 2005
    Posts
    196
    How?
    And about my grammer,im just used to using m.s.n.talk.Yah so how could i limit down my code?

    Oh and lol ive been here longer than you.XD

  11. #11
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Quote Originally Posted by lilhawk2892
    ...the attack...
    The attack of what?

  12. #12
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    He wants to make a function for calculating an attack.

  13. #13
    Registered User
    Join Date
    Sep 2005
    Posts
    196
    Hmm,it appears that maybe i should work on the rest of the code before going back to this so maybe i can give more imformation...
    does anyone agree?

    But wraithen know what im getting at,but tell me more about this "transform" function?

  14. #14
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,740
    lilhawk joined the forum and started posting very general threads about C++ and stuff. Around the tenth one he actually tells us he is making a game and wants to shorten his code.

    Of course, since general questions get general answers, and because he hasn't programmed for very long (most likely) he has not been able to take the advice of our members and apply it within the scope of his project.

  15. #15
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    You can work on more than one thing at a time. Some advice, if I may, think of what you can reuse and put those parts into a function. Then consider creating utility files for your functions, so that it isn't a wall of code crashing down upon us. It really does help with a lot of things. Oh yeah, comments are good things to use too... and not only for others.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Partners (D&D fan preferably)
    By C_ntua in forum Game Programming
    Replies: 44
    Last Post: 11-22-2008, 08:21 AM
  2. classes and functions
    By cpudaman in forum C++ Programming
    Replies: 20
    Last Post: 12-18-2007, 01:45 AM

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