Image

Imagechocojoshy wrote in Imagecpp

A Design Question

I'm doing some work on my game, and I'm at a bit of a block.

I have a class that represents the visuals of my battle (specifies which elements are contained and the functions that they can do). I noticed that for each of my elements, they all have pretty much the same functionality (initalization, show, hide, destroy, and then a few specifically for the element). I'm planning on adding the pictures for players and monsters, and I realized it's time to refactor this class so instead of having:



Class BattleVisual:

public:
showMenu1() //Class RingMenu
showMenu2() //Class GridMenu. A subclass of window
showPlayerStats() //Class Window
showTurnCircle() //Class BITMAP*, basically a picture.

hideMenu1()
hideMenu2()
...

same thing for initialization, etc


private:
RingMenu menu1;
GridMenu menu2;
WINDOW playerStats;
BITMAP *turnCircle;


This class, BattleVisual, is only used for class Battle (Although it's not a private/inner class, I can't think of any way this would be reused elsewhere). My BattleVisual class is about 800 lines long (including the header file), and would probably grow by another few hundred after adding the players and monsters.

However, I would like to create a class called BattleVisualElement, where my BattleVisual class would present each element with an object of that type. Is this worth it? I would probably still have to create functions in BattleVisual for Battle to call (though I could probably use an enumeration or index).

I.e.:
In Battle class: battleVisualObj.show(0); //Show element of 0 of battleVisualsElements

BattleVisual::show(int pos)
{
visualElements[pos]->show();
}


Also, how would I handle the fact that I have different types of VisualElements (like I said, GridMenu, Window, RingMenu, BITMAP)? I was thinking of having a bunch of subclasses of visualElements?


Thanks everyone for reading this, I feel that the hardest part of programming is not the actual coding, but figuring out how to design (architect) the code in such a good way that you feel comfortable with. I know reading on Pattern (I plan on buying the classic book on Design Patterns) would help, but with a full courseload I have minimal time to do research :(