Design patterns principles - XOQDY/tanks-game GitHub Wiki

Design Patterns

State .state/

We created a State Pattern to utilize in Player Class to reflect the tank's current direction.

Strategy .strategy/

We use Strategy to give the AI tank the next command. We can provide a functionality to choose difficulty mode by implementing strategy in a future edition.

Command .command/

We want to utilize a Command Pattern to turn the tank's head such that the tank's next move will be in the same direction as the head.

Observer Window.java model/World.java

Make the World and Window Classes interact using the Observer Pattern so that when the world is refreshed to the next frame, the window will know and repaint.

Object Pool model/BulletPool model/Bullet

Rather than allocating and discarding bullets on demand, use Object Pool to establish a Bullet Pool to employ a pool of initialized bullets that are stored ready to use. We chose Object Pool since we know we'll use bullet for a short amount of time, and we don't want to have to construct new Bullet every time we require one.

Design principles

Information Expert .model/

We Assign responsibility to the class that has the information needed to fulfill it.

Creator model/World model/BulletPool

We Assign class World the responsibility to create object tank

Polymorphism .model/

When related alternatives or behaviors vary by type (class), assign responsibility for the behavior using polymorphic operations to the types for which the behavior varies. In each object tank we have base class which is WObject.