Inheritance / game interface design

I am developing the game, but I can not plunge into the structure of inheritance. I usually have a good understanding of this, but it has too many overlaps, and I cannot solve all this.

I'm trying to simulate sailing ships - I think Age of Sail. Presumably, therefore, everything expands the class of the vessel.

There are several types of ship types: rowing (galleys, canoes), square installation, front and rear towers with different behavior. Each of them is further subdivided into several other types. I cannot decide if it should be a series of interfaces or extensions of a ship. We also note that there may be some kind of crosshairs (a vessel can be either rowing or square rigged), which makes me think about interfaces?

Ships also have different forms of behavior: merchant ships, military, privateers, and pirates. I really can't decide if it should be an interface or an extension of another class. However, in this case there is no crossover type.

Finally, there are several behaviors that individual ships may have. Merchants can be in convoys (defend themselves) or be independent (run away). Men of war almost always attack, if not much outsmarted ... but they can work in fleets, squadrons, or independently. Teamen and pirates attack only weaker - usually independently, but sometimes in pairs. I assume this should be an interface too?

My big problem is that every ship style (frigate, battleship, etc.) can fulfill almost any of these roles, so I cannot build a simple inheritance structure. The frigate cannot expand military service, as some of them are private individuals. Sloop cannot spread square falsification because some of them are front and aft. etcetc.

Any thoughts would be appreciated, I lost a little end. Thanks

+5
source share
6 answers

Ok, here are some ideas:

  • The courts have one or more means of propulsion (oars, sails, etc.) that you can simulate by composition (for example, have a list of propulsion techniques).
  • ( - . http://en.wikipedia.org/wiki/Strategy_pattern - )
  • , , - - , , ( , )

. , .. , .

, , , / , .

, :

http://cowboyprogramming.com/2007/01/05/evolve-your-heirachy/

+2

"" . . . , .

.

" , . , - , ". , , . "" .

:

enter image description here

" :..." . , "Movable" . "" "Movable" . "Movable" - , , , . , , . ArrayList. ( , ). , .

: " :...", , , , . " ". .

para ", , ...", . ArrayList, .

, , .

+5

, Bhusan, :

"", , . , - , ". , , . " " ".

, , , , , , . . http://en.wikipedia.org/wiki/Composite_pattern, , " , , ".

, : " ()", , -, ? , , , , protoype

+2

strategy.
(, , , , ), , , , . (Man-o-war - )
AI , , , .

+1

, , , Composition .

: . (... , , X)

A Pirate - ( )...

+1

Vessel. , Vessel , . ( , - , .) Propulsion, , . . Behavior, . , . , . ( , ). , , , , .

This allows you to switch features on the fly if you want, although you probably don't. However, you can go from sail to sweeps or switch bold linear behavior while maintaining the behavior of a merchant to realize a captain who is losing his nerves. In any case, he is there if you need it.

+1
source

All Articles