Rant

Pages: 1234
The reason I said accuracy was part of weapon was because I was thinking guns and snipers :) I don't know how we will distinguish between the two though. Maybe one accuracy on weapon and one for the "warrior".
not sure what you meant with defining == operator
bool operator==(Armor& lhs, Armor& rhs) and then do std::cout << (Armor() == false)
Try to guess what will happens without experimenting first.
What would be the point of adding an equal operator for comparing armors? The standard one works doesn't it?
Last edited on
Is it? Does not work for me, but if it is for you, try line i asked you.
I just want to show that too many constructors is rarely good and could lead to unexpected results. What do you think would happens when you run that line?
It will convert false to Armor I would guess, so it creates a temporary object. because of my Armor(bool). The funny thing is that that is probably what you would want it to do if you do that line. I see no reason to use it though.

EDIT: What does it actually do? I haven't tried it :P
Last edited on
I have tried, it returns 1, exactly what I would expect. (and want if I were ever to use it) I used this code for the equals operator :)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
bool operator==(bool x)
	{
		if(noDefenseLeft() == true)
		{
			return (x == false);
		}
		else
			return (x == true);
	}

	friend bool operator==(bool x, Armor a)
	{
		return (a == x);
	}
It would call constructor which will ask you to enter armor parameters manually.

Imagine following construct
1
2
if(warrior->armor == NULL)
    //... 

It will compile without warnings, but will not do what you want.

And that way your warrior class always require iostream and gets input from cin, which isn't good if you ever move into dose graphic library.

My suggestion: leave only parametrized constuctor (which takes most arguments in your case), delete default constructor and create armor factory class:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
enum class ArmorType {HEAVE, NONE, LIGHT};
class ArmorFactory
{
    Armor* craftArmor(ArmorType armor)
    {
        switch(armor)
        {
        case ArmorType::HEAVY: return new //...
        case ArmorTyoe::LIGHT: return //...
        default: //Clever handling of default case
        case ArmorType::NONE: return new Armor(0, 0, /*...*/);
        }
    }

    Armor* craftArmor()
    {
        return craftArmor(NONE)
    }

    Armor* craftArmorFromUserInput();
    {
        std::cout << Enter defense: ";
        srd::cin >> //...
    }
}; 
That way you will not overburden Armor class with unneeded code and will allow you to control how your class would be created.
Everything you say makes sense but I don't think there ever is a situation you would use it for something else and if you do you would make an operator function for it anyway. The user will never have access to that anyway because it is hidden under the armor class :) I see your point though, my design was terrible. That is one of the problems I have. Were did you learn about designing programs, do you have any recomendations? I wont have time to read any more books atm but it would be nice to know. Are you interested in helping out with this small fun project? Daleth made a github project for it :)

EDIT:
if you want you can finish the armor factory class and add it to our project :)
Last edited on
http://en.wikipedia.org/wiki/Factory_method_pattern
http://sourcemaking.com/design_patterns/factory_method

Basically a design for controlling the instantiation of objects, right? Or delegating the customization of a general class to its derived classes? I'm currently in the process of learning the factory method, so I can't say for sure.

Edit:
In response to Filiprei, there is no chat system on github. We could either make a thread in the lounge like the ChessPlusPlus group or host an IRC.
Last edited on
I fixed my problem. As I said the code used in main isn't needed, nor is the Sim class'. It was merely used to test my code. I have the code running.

I didn't take too much time in organization as this was a test so.... :P

Yea and I got grounded so I lost my fixed code for a week. I'll work from the code I uploaded and compile with mingw.
I can add you to our repository on GitHub, FredBill. So long as you have an internet connection, you'll have access to the current updates to the project files.
I'll do that, thanks.
FFMPEG and AutoDiff. Both projects have shit documentation for using them in your own development.
RPGmaker. Although its pretty good, it started to produce script kiddies quickly.

(Because of the availability of Ruby to give more control of the editor.)
That was very random ^
Is there some reason such a high percentage of your posts include the term "script kiddies?" It's almost like you're trying to come out of the script kiddie closet.
Fredbill, do you have an account on github? have you joined our project? If so please add the weapon class :)
Last edited on
@cire lol.

@Filiprei no.
Topic archived. No new replies allowed.
Pages: 1234