0
\$\begingroup\$

I'm working on a tower defense game as a class project and i got it to a kinda working level(creep spawns, towers can shoot etc), but i have a problem with my classes.

Currently the towers shoot but there's no bullets, i'm using an ArrayList to store bullets.

Where should the ArrayList be, on the Game class(manages all the logic) or on the tower class?

\$\endgroup\$
1
\$\begingroup\$

I think you shouldn't put bullets into a tower class. If you store bullets in the tower class you'll not be able to destroy tower when some bullets in way to the target. For example, if you have rocket launcher with slow rockets, it would be hard to sell it, because in any moment of game some rocket will be on the way. So, ArrayList (or special class called like BulletsManager) is better. If you need to handle relationship between bullet and tower just save pointer to a tower in bullet's instance.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

The tower class should probably inherit a bigger class that manages bullets, weapons and the sort. That being said, it's a fairly simple game, so from the limited information you've provided, I'd say put it in the tower class so you can do Tower.Shoot() -- neat and logical.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ I have something like: Sprite -> Towers,enemies,bullets My Game class has an arraylist of enemies and towers, should every tower have an arraylist of his bullets then? \$\endgroup\$ – troyz Feb 14 '15 at 13:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.