Advertisement

C++ Workshop - Project 2

Started by September 27, 2006 04:56 PM
94 comments, last by Warlord_Shaun 16 years, 9 months ago
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.
Advertisement
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.
Advertisement
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
1. jwalsh: Please just post the remaining days of the workshop, or at least just post the next project, I'd really like to know what it is...

2. Regarding the polymorphism problem discussed at the beginning of this project-2, it seems that RTTI was the only solution (weather using dynamic_cast or pimpl). But Jesse liberty said (i think day 12, or 14) that RTTI might be a sign of poor design and that one should consider using multiple inheritance instead. well, how would multiple inheritance help in this case? and if RTTI is a bad idea, what do they really do in real big programs out there?

Also, on day 12 in the book "you can't get there from here":
Quote:
Although you can transform the Mammal pointer into a Dog pointer, there are usually far better and safer ways to call the WagTail() method. C++ frowns on explicit casts because they are error-prone. This subject will be addressed in depth when multiple inheritance is covered, and again when templates are covered on Day 20, "Exceptions and Error Handling."


where in multiple-inheritance and day-20 does the book deal with this?
Just wanted to say that I am going back to this project (had to stop because of other game committments). If you decide to stop the workshop, I really hope you post the next project JWalsh. This has been a huge help to me and alot of others.

This topic is closed to new replies.

Advertisement