Thread: calculating attack and defense

  1. #16
    Registered User
    Join Date
    Sep 2005
    Posts
    196
    oh no ive been coding just about everyday just not in c++...
    ive been using

    www.gamemaker.nl
    but i hate using that because i switch projects to easily...and ill never be able to make a professional game.

  2. #17
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    You are not ready for doing attacks yet, I would say get it to the point at which you can walk around, probably using cardinal directions (NEWS). Till then you don't even need a combat engine. Also find a way to read the text you need for class selection from a external file. Also, you want to make your game modular, otherwise it will overwhelm you. Take some time with a notebook and write down all the general things your are going to need, such as weapon, dialog, classes, races, spells, monsters, npcs, AI, maps, and other stuff like that. Too many people rush into the game making (like I did with my first attempt) and end up with spagetti code that is something horrendous

  3. #18
    Registered User
    Join Date
    Sep 2005
    Posts
    196
    you know your right...i did rush into this..maybe if i spent a little more time planning and a little less time doing my game wont look so half assed thank you..if a mod looks at this thread please lock it

  4. #19
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Quote Originally Posted by Wraithan
    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.
    Uhhh... no.

    Code:
    #include <string.h>  // Should be <string>
    #include <ctype.h>  // Should be <cctype>
    To use std::transform, you need to include the <algorithm> header. <cctype> is needed for std::tolower.

    Quote Originally Posted by lilhawk2892
    But wraithen know what im getting at,but tell me more about this "transform" function?
    The std::transform function operates across a range of elements in a container (array/vector/ect...) calling a user supplied function on those elements and then saving the results to another (or the same/original) location. Thus, if you wanted to make a user input string all lowercase, you can either loop over all the values in the array and change them to lower case yourself or make a single line statement of code that will do the same thing.
    "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

  5. #20
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    http://www.msoe.edu/eecs/cese/resources/stl/string.htm

    This page has all sorts of string manipulation, just search transform on this page to find out more about it.

  6. #21
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Code:
    #include <cstdlib>
    #include <iostream>
    #include <string>
    #include <cctype>
    #include <algorithm> 
    
    using namespace std;
    
    void create();
    void createdata(string race);
    
    int yn;
    
    struct stats{
    	string name;
    	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<<"tutorial(type tut)\n";
    	    cout<<"quit(type quit)\n";
    	    cin>>select;
    		transform (select.begin(),select.end(), select.begin(), tolower);
    	    cout<<endl;
    	    if(select == "play") {
    			system("cls");
    			create();
    			cin.get();
    		} else if(select == "tut") {
    			cout<<"under construction\n";
    			cin.get();
    	    } else if(select == "quit") {
    			return 0;
    	    }
    	    cin.get();
    	} while(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;
    	transform (race.begin(),race.end(), race.begin(), tolower);
    	
    	if(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";
    	
    	} else if(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";
    		
    	} else if(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";
    		
    	} else if(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;
    	transform (yn.begin(),yn.end(), yn.begin(), tolower);
    	
    	if(yn == "y") {
    		createdata(race);
    	} else {
    	    system("cls");
    		create();
    	}
    }
    
    void createdata(string race){
    	string name;
    	cout<<"What is your character's name?\n";
    	cin>>name;
    	system("cls");
    	
    	if(race == "h") {
    		player.lvl = 1;
    		player.hel = 100;
    		player.att = 3;
    		player.def = 2;
    		player.agi = 3;
    		player.arch = 0;
    		player.mage = 0;
    		player.mon = 0;
    		player.exp = 0;
    	} else if(race == "e") {
    		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;
    	} else if(race == "m") {
    		player.lvl = 1;
    		player.hel = 100;
    		player.att = 1;
    		player.def = 1;
    		player.agi = 2;
    		player.arch = 0;
    		player.mage = 5;
    		player.mon = 0;
    		player.exp = 0;
    	} else if(race == "d") {
    		player.lvl = 1;
    		player.hel = 100;
    		player.att = 5;
    		player.def = 5;
    		player.agi = 2;
    		player.arch = 0;
    		player.mage = 0;
    		player.mon = 0;
    		player.exp = 0;
    	}
    	cout<<"Here are your stats\n";
    	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<<"magic "<<player.mage<<endl;
    	cout<<"money "<<player.mon<<endl;
    	cout<<"experience "<<player.exp<<endl;
    }
    Here is with some of the changes I was talking to you about on MSN.

  7. #22
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    You could limit your actual code usage by using proper object oriented programming..

    But that requires a lot of thought and design.
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

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, 09:21 AM
  2. classes and functions
    By cpudaman in forum C++ Programming
    Replies: 20
    Last Post: 12-18-2007, 02:45 AM