I am making a tiny game app in my free time, and I have just recently hit a wall.
The idea is that there is a fixed grid of Box
es available and that many Jewel
s as well.
Both boxes and jewels can come in different colors. As with color space, the three basic type of boxes are Red, Yellow and Blue. The other ones available are, of course, Orange, Purple, Green, with a special White box.
I also have the Jewels, which correspond to the same colors as boxes.
Now, the logic is as following:
- Primary color boxes will give reward only if they contain a gem whose color is the same as the box color or is made from the box color
- For example, red box will give bonus if there is a red, orange or purple jewel inside it because of the following
- Red is made of Red
- Orange is made of Red and Yellow
- Purple is made of Red and Blue
- White is made of Red, Blue and Yellow
- Red box won't give any bonus for Green jewel, because Green is Blue and Yellow and there is no Red in there
- For example, red box will give bonus if there is a red, orange or purple jewel inside it because of the following
- Secondary color boxes cannot accept any of the primary color jewels because secondary color boxes are made of at least two colors, while primary gems are made of 1 color only.
- Given that, secondary color boxes can only accept the corresponding color jewel, plus the white one.
- And as an exception to the rules above, white box is like a bonus box, which can accept all jewels
I'm puzzled with how to make the domain model for this so it doesn't contain (or contains as least as possible) if
s and instanceof
s.
Also, if I would like to extend the types of boxes and jewels one day, I'd like it to be done in any of the following two ways by adding new classes without having to change old ones.