Hello everybody.
I am struggling with an OOP architecture problem i have for a game i am coding. Sorry in advance for my poor English.
The aim of the game is to shoot monsters with a canon.
The objects of my game are :
- A battleship which fires to monsters
- An island (a simple square on the screen) which contains one or more ground monsters (like crabs)
- A sea which contains one or more islands and one or more sea Monster (like octopus).
A monster can move through different patterns : it can be still (no move) or move horizontally or move vertically or move randomly in each directions. It cannot cross the island borders.
My first idea was to use an interface OOP class for the move pattern. So i can assign for each monster a specific move pattern.
Here is my implementation in OOP :
class Monster {
// other attributes
PVector pos ; // position
PGraphics aliveForm ;
MoveType movetype ; // move pattern
// lots of stuff
}
class Crab extends Monster {
// lot of stuff
createAliveForm() {
// construct a crab image and put it in aliveform;
}
class Octopus extends Monster{
// lot of stuff
createAliveForm() {
// construct a octopus image and put it in aliveform;
}
Interface MoveType {
void move() ;
}
class StillMove implements MoveType {
void move(){
// do nothing}
}
Class HozizontalMove implements MoveType{
Void move() {
// i can’t figure how to code here}
}
Class Island {
PVector pos ;// position of left corner of the island
Int w, h ; //width and height of the island
ArrayList<Crab> crabs = new ArrayList<Crab>(); // list of crab monster
}
I can’t figure how to manage the coding of the Monster movement. In interface ModeType, it does not access to position attribute of Crab or Octopus Class. So it cannot modify the position according to the type of move. Do i have to pass object Crab and Island in parameter to the move method of interface ? It seems strange to me…
I feel a little lost and fear to be in the wrong way with this implementation.
I would appreciate some hints of OOP skilled coder.
Thanks