Hello all,
I am a beginner in programming, so having lots of trouble getting started with and assignment. Any help would be greatly appreciated. This is the assignment.
There will be a file called "Weapons.txt" which contains 3 pieces of information about weapons.
There will be the following data:
string name; // contains the name of the weapon
int hands; // contains how many hands required to use the weapon
int attackpower; //contains the attack power the weapon has per hit.
**this next variable is not in the file and will be generated by constructor**
double attackspeed; //this requires a bit of explaining:
//lets say the attack power of the weapon is 10. IF the weapon has an attackspeed
//of 2, that means he does 2 attacks per second, so his damage per second is 20.
//if his attackspeed was .5, he attacks once every 2 seconds so his damage per second is 5 (average).
The attackspeed will be generated randomly in the constructor from 0.1 to 2.5
This means the class Weapon will have 4 variables (name, hands, attackpower, attackspeed);
There will also be a class called Hero with only three variables:
int str; // the strength of the hero
string lefthand; //name of weapon on left hand
string righthand; //name of weapon on right hand
This str will also be generated randomly by the constructor using rand()%10+1;
The hero has the obvious... two hands! You should determine the best weapon combination
for the hero for him to deal the highest damage per second (dps).
**There is a restriction though... You can only equipt weapons you are strong enough to equipt.
This means that if your str is 5, the combined attackpower of your weapons equipt should be 5 or less.
This really makes things tougher.
To begin, you need to infile all the weapons into the array of size 10 correctly.
Once all the weapons are set up, you should use bubble sort to sort the weapons by your choice of
either attackspeed, attackpower, or maybe even dps; (use a function named sortWeapons)
Display all the weapons information.
*At this point you should have found the weapon(s) to equipt*
Display the Hero's information (his attack strength and the name of the weapon on each hand).
IF the hero is using a two handed weapon, then the same name of the weapon is on both the left and right hand.
IF he is using two one handed weapons, then there should be two different names.
Display these names along with the combined attack damage per second.
**be aware that the two handed weapons are stronger than one handed, but you can
equit two one handed weapons.
***You cannot equipt two of the same weapon
** The classes should have all set and get functions, constructor, variables should be private **
**The main should have an array of 10 weapons and a hero. it should have functions as you find needed.
class Weapon
{
std::string name;
int hands = 0,attackPower = 0;
double attackSpeed = 0.0;
/*Constructor*/
public:
Weapon(std::string &inName,int &inHands,int &inAttackPower,double &inAttackSpeed):name(inName),hands(inHands),attackPower(inAttackPower),attackSpeed(inAttackSpeed){};
std::string getName()
{
return name;
}
void setName(std::string setName)
{
name = setName;
}
/*The rest of Get and Sets here*/
};
That should give you a good start here, try writing some code until you absolutely get stuck, google problems and if you cant get anything then post here again.
You have blank constructors and no get or sets for the Hero and Weapon class. How are you going to change variables such as hands or attack power? For every weapon those should be different.
Another thing, you dont instantiate your Hero or Weapon objects in the main function
I came up with a little more code, but on my sort Im getting an error that I cant get rid of. Do you see anything wrong with it. Thanks for all your help.
It usually helps to post the error message. It may seem like gobbledygook to you, but someone on here might understand it better, and it will save them a lot of time looking through your code. :)