Drowning in code When working on WeaponManager

So as you can see above I have been working on the WeaponManager for this past week.

I have drew my thought the first day thinking I have nailed it it looked something like this:

thinking I NAILED it!

Then after a good nights sleep I realized I was SO wrong in how I thought and how I began to code, removing everything and starting from scratch was inevitable.  SO I started working on paper again and the pattern you see above was spread to 4 A4 pieces of paper and scribbled on and off again over and over.

Then after 1 hour of thinking and scribbling I started to program. Yes now I surely would make it.

Yet again fate was not with me, as off today I noticed that my code would not work. Not at all.
Worth to mention that:
(I have had issues with the program called GitHub (https://github.com/) making waiting time before I could work longer )

After learning how to use a library called YAML (https://code.google.com/p/yaml-cpp/) I used it to my advantage and now I know how use it for beginners.

Now I have rambled about my problems so maybe you should know what I have been looking into.

I have a Player, WeaponManager and BulletManager class and have to make WeaponManager work with Player and BulletManager making a ”conversation” between them and making sure that information such as Weapon: Damage, spread, delay, recoil, ammo and such would come in use when you pressed shoot.

But after several trials I ended up making this:

void WeaponManager::equipWeapon(int value){

if (value == 1){

bullet_speed = 50;
Congigure(weapon_name = ”rifle_lowcab”);

}
if (value == 2){

bullet_speed = 100;
Congigure(weapon_name = ”rifle_highcab”);
}

weapon->setWeight(weight);
weapon->setAutoFire(auto_fire);
weapon->setDamage(damage);
weapon->setAutoShootDelay(shoot_delay);
weapon->setMaxSpread(max_spread);
weapon->setMinSpread(min_spread);
weapon->setMagazineSize(magazine_size);

}

I bet some of you can see the error right away but I sure as hell did not. This is still new to me and I after asking our Lead Programmer I got to know what was wrong with the code.

I should store it in a std::map

and faster than you can say: Brain Freeze! I lost it all, I went home that day thinking dark thoughts about how programming should always work how I wanted it so that I could get on with my life.

Now you are with me today. I have worked to make my former code work better before I gave up and now have to learn about std::map if you ever ask my lead programmer what it is he will say (Like a vector but tailor-made for this!) and I am still baffled how it works.

So my goal for the moment is to make this work the way I like it with std::map.
As a tip he told me look at the code in animation and use that. Look at it and see guess if I get it:

void Config::configure(AnimationManager *animationManager)
{
if (root_node[“animations”])
{
for (YAML::iterator it = root_node[“animations”].begin(); it != root_node[“animations”].end(); ++it)
{
Animation* animation = new Animation();
animation->identifier = it->first.as();

animation->m_texture =
SpriteManager::loadImage(it ->second[“image”].as());

animation->frame_duration = it->second[“frame_duration”].as();
int frame_width = it->second[“frame_size”][0].as();
int frame_height = it->second[“frame_size”][1].as();

animation->m_frames.clear();
for (unsigned int i = 0; i second[“frames”].size(); i++)
{
int x = it->second[“frames”][i][0].as();
int y = it->second[“frames”][i][1].as();
sf::IntRect rect;
rect.left = x;
rect.width = frame_width;
rect.top = y;
rect.height = frame_height;
animation->m_frames.push_back(rect);
}
animationManager->addAnimation(animation);
}
}
}

Still in bafflement but I will make it work before tomorrow morning! even If I have to stay awake all night!

Alpha presentation is tomorrow and I will blog a short response on how I made it with the code and how it went when I get the time but it will be before next Thursday.