C++ Workshop - Project 2

Started by
94 comments, last by Warlord_Shaun 16 years ago
.. realized I should've asked my question above, but oh well.

What's been killing my time project wise is this: I want to have multiple types of "stuff" (Swords vs. Shields vs. Potions, for instance). So I set up an Item class, then inherit into Weapon, Shield, Potion, etc. But as soon as I:

Item *myItem;
myItem = new ShinySword;

all my methods respond as an Item, not as a ShinySword.

I know I'm missing something obvious; can someone tell me what it is? ;)
Advertisement
You probably didn't make the methods virtual in Item and override them in your subclasses.
I haven't been following the workshop from the start but I have read through some of the threads and completed project 1. I wanted to try project 2 as well however I also felt like it was quite overwhelming. For me the difficult areas about this project were:

1. Developing an item class that could handle any item.

In a sense this doesn't need to be overly difficult if you just create vectors for each different item. i.e shield vector, weapon vector etc. However I wanted to find a more satisfactory solution and decided to explore some of the methods suggested such as the pimpl(private implementation/handle classe). I was hoping this would then allow me to just create a vector of items that could then be a weapon, shield of just a standard item. I have read that the pimpl is a common idiom used within c++ however I have never used it before and have found it to be quite difficult to grasp - for me it feels like it would only work if all the classes and derived classes had exactly the same interface which I don't think is always possible.

2. Developing the room/map engine.

Not sure about this - if you are reading from a text file how would the text file be organised?

Also if the player came into a room from the east side rather than the north side does the description change?

Quote:Original post by Darkstrike
This links to my question I asked before: how long should such a mini-project take a practicing programmer? Less than a day? A day? A couple of days? More than half of my time was used for debugging; is that normal? I ended up rewriting my code a lot, it has barely anything left in it from Project 1; is that normal, considering that we should develop code-reusage skills and design in a way that would allow us to minimize the amount of extra work to be done?


I would also like to know this - project 1 took me about 12 - 14 hours to complete and quite a lot of time was spent testing the game and then fixing some of the code, I knew this project would take a lot longer.

With code reuse, I always get the impression that when learning c++, code reuse is always something that gets mentioned alot leaving you thinking that when you develop classes they are somehow perfect and can be reused constantly - I don't think this is the case, however I would like to see someone who is extremely proficient at c++ develop project 1 and 2 to see how they have broken the project down.
How about them apples?
Quote:jwalsh:
It appears, however, that interest in the project and in the workshop has largely trailed off.


Well, with a project like this, I have been spending alot of my time learning about file streaming, tokenizing strings, and c++ containers, etc. Besides the fact that I have switched from dev-cpp to VC++ express 2 weeks ago. Besides the big boomer: I sold my laptop a week ago... with all that going on, i didnt spend to much time around the forum, but my interest hasnt trailed off.

Keep it up jwalsh!

Quote:popcorn
1. Developing an item class that could handle any item.

In a sense this doesn't need to be overly difficult if you just create vectors for each different item. i.e shield vector, weapon vector etc. However I wanted to find a more satisfactory solution and decided to explore some of the methods suggested such as the pimpl(private implementation/handle classe). I was hoping this would then allow me to just create a vector of items that could then be a weapon, shield of just a standard item. I have read that the pimpl is a common idiom used within c++ however I have never used it before and have found it to be quite difficult to grasp - for me it feels like it would only work if all the classes and derived classes had exactly the same interface which I don't think is always possible.


I would also like to know about this.
Quote:Original post by kingIZZZY
Quote:popcorn
1. Developing an item class that could handle any item.

In a sense this doesn't need to be overly difficult if you just create vectors for each different item. i.e shield vector, weapon vector etc. However I wanted to find a more satisfactory solution and decided to explore some of the methods suggested such as the pimpl(private implementation/handle classe). I was hoping this would then allow me to just create a vector of items that could then be a weapon, shield of just a standard item. I have read that the pimpl is a common idiom used within c++ however I have never used it before and have found it to be quite difficult to grasp - for me it feels like it would only work if all the classes and derived classes had exactly the same interface which I don't think is always possible.


I would also like to know about this.


I think the trick is to isolate what you can do with an item, then override from there. Here's my list ("Attack" is a class I'm using to hold all the information needed for combat):
1. String Item->Name() - give the description, along with any needed information (number of uses, etc.
2. int Item->Use(Character) - drink the potion, wave the wand, etc
3. void Item->PutOn(Character) - for any "while wearing this" abilities
4. void Item->TakeOff(Character) - reverse of PutOn
5. Attack Item->Swing(Character) - use the item in combat (generate hit roll, damage, etc)


THoughts?
might get this book. can anyone tell me if it takes you from beginner to advanced C++? If so, I'll get it and catch up on this
Quote:anyGould
I think the trick is to isolate what you can do with an item, then override from there. Here's my list ("Attack" is a class I'm using to hold all the information needed for combat):
1. String Item->Name() - give the description, along with any needed information (number of uses, etc.
2. int Item->Use(Character) - drink the potion, wave the wand, etc
3. void Item->PutOn(Character) - for any "while wearing this" abilities
4. void Item->TakeOff(Character) - reverse of PutOn
5. Attack Item->Swing(Character) - use the item in combat (generate hit roll, damage, etc)
Talking about percolating the task upward? not a good idea really... unless i didnt get what you mean. Leme explain what I meant a little better: I need my Room class to be able to contain as many different objects needed, as is decided during runtime.
Quote:Original post by kingIZZZY
Quote:anyGould
I think the trick is to isolate what you can do with an item, then override from there. Here's my list ("Attack" is a class I'm using to hold all the information needed for combat):
1. String Item->Name() - give the description, along with any needed information (number of uses, etc.
2. int Item->Use(Character) - drink the potion, wave the wand, etc
3. void Item->PutOn(Character) - for any "while wearing this" abilities
4. void Item->TakeOff(Character) - reverse of PutOn
5. Attack Item->Swing(Character) - use the item in combat (generate hit roll, damage, etc)
Talking about percolating the task upward? not a good idea really... unless i didnt get what you mean. Leme explain what I meant a little better: I need my Room class to be able to contain as many different objects needed, as is decided during runtime.


My current plan is to use Object (the class), and have everything inherit from that (with the five basic methods listed above). Then rooms can just hold "objects" without needing to know if they're Weapons or Potions or what-not.

Now, that said, I haven't gotten this to work yet (although I figured out the problem was due to me trying to build a CLR project by accident :), so we'll see.
I been thinking of having all my game objects convert to simple class when not in use by player or game enity; then changing it back to the correct class when object is in use.
cool

This topic is closed to new replies.

Advertisement