V
V
Vladimir Rodkin2014-10-27 15:47:33
JavaScript
Vladimir Rodkin, 2014-10-27 15:47:33

Which design pattern to choose?

There is a small map, ab27eea752c04f4fa7b70d4bbb110fc6.png
you can build buildings on it by clicking on free cells with the mouse.
When the map is initialized, a list of already built knowledge comes from the server:

"buildings": {
    "1": {
        "position": [2, 1],
        "type": "barrack"
    },
    "2": {
        "position": [2, 2],
        "type": "hospital"
    },
    "3": {
        "position": [0, 0],
        "type": "school",
        "size": 4
    },
}

Some buildings have a property sizeequal to 4- this means that the building occupies 4 cells.
Need:
  • build buildings that came at initialization
  • add and destroy buildings dynamically
  • have access to the buildingid

I chose the factory template ( Factory ), but I don't understand it very well - where to store the whole list of buildings? In the factory module? Or make the factory part of the Building module?
Or do I need a Composite ?
I have modules:
  • Map - responsible for rendering the map, and also gives out cells by coordinates
  • The building is the building itself. It has properties: coordinate, size, if it is different from 1, a link to the image of the building
  • Building Factory - creates buildings

I know that these are elementary things for gamedev, but I'm not very familiar with this yet.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Melnikov, 2014-10-27
@VovanR

bakhirev.biz/book

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question