diff --git a/src/AirBomber/FormArrays.java b/src/AirBomber/FormArrays.java new file mode 100644 index 0000000..41bcbd9 --- /dev/null +++ b/src/AirBomber/FormArrays.java @@ -0,0 +1,13 @@ +package AirBomber; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import AirBomber.Generics.EntitiesGenericCollection; +import AirBomber.MovementStrategy.ObjectEntityRenderer; +import AirBomber.Rendering.BomberRendererBase; + +public class FormArrays extends JFrame +{ + +} diff --git a/src/AirBomber/Generics/ArraysGeneric.java b/src/AirBomber/Generics/ArraysGeneric.java new file mode 100644 index 0000000..7b28761 --- /dev/null +++ b/src/AirBomber/Generics/ArraysGeneric.java @@ -0,0 +1,68 @@ +package AirBomber.Generics; + +import AirBomber.Entities.*; +import AirBomber.Rendering.*; +import java.util.ArrayList; +import java.util.Random; + +public class ArraysGeneric +{ + private ArrayList _entities; + private ArrayList _renderers; + + private int _entitiesCount = 0; + private int _renderersCount = 0; + + private final int _entitiesMaxCount; + private final int _renderersMaxCount; + + private final int _pictureWidth; + private final int _pictureHeight; + + public ArraysGeneric(int EntitiesMaxCount, int RenderersMaxCount, int Width, int Height) + { + _entitiesMaxCount = EntitiesMaxCount; + _renderersMaxCount = RenderersMaxCount; + + _entities = new ArrayList(EntitiesMaxCount); + _renderers = new ArrayList(RenderersMaxCount); + + _pictureWidth = Width; + _pictureHeight = Height; + } + + /** Полиморфные методы */ + public boolean Add(T Entity) + { + if (Entity == null || _entitiesCount >= _entitiesMaxCount) + return false; + + _entities.add(_entitiesCount++, Entity); + return true; + } + + public boolean Add(U Renderer) + { + if (Renderer == null || _renderersCount >= _renderersMaxCount) + return false; + + _renderers.add(_renderersCount++, Renderer); + return true; + } + + public BomberRendererBase CreateObject() + { + if (_entitiesCount == 0 || _renderersCount == 0) + return null; + + Random Random = new Random(); + + int EntityIndex = Random.nextInt(_entitiesCount); + int RendererIndex = Random.nextInt(_renderersCount); + + T Entity = _entities.get(EntityIndex); + U Renderer = _renderers.get(RendererIndex); + + return new BomberRendererBase(Entity, Renderer, _pictureWidth, _pictureHeight); + } +} diff --git a/src/AirBomber/Rendering/BomberRendererBase.java b/src/AirBomber/Rendering/BomberRendererBase.java index 79c15dc..9f29088 100644 --- a/src/AirBomber/Rendering/BomberRendererBase.java +++ b/src/AirBomber/Rendering/BomberRendererBase.java @@ -99,6 +99,21 @@ public class BomberRendererBase EngineRenderer.SetAmount(Random.nextInt(1, 7)); } + public BomberRendererBase(BomberEntityBase Entity, IEngineRenderer EngineRenderer, int Width, int Height) + { + if (Width < _bomberWidth || Height < _bomberHeight) + return; + + _startPosX = 0; + _startPosY = 0; + + _pictureWidth = Width; + _pictureHeight = Height; + + this.EntityBomber = Entity; + this.EngineRenderer = EngineRenderer; + } + public BomberEntityBase GetEntityBomber() { return EntityBomber; } public void SetPosition(int x, int y)