Lab3 Java HARD Петрушин Егор ПИбд-22 #3
@ -18,6 +18,7 @@ public class DrawningSPAU {
|
||||
private int rollVar;
|
||||
private int carWidth = 135;
|
||||
private int carHeight = 75;
|
||||
private IDrawable Rollers;
|
||||
|
||||
protected void setEntitySPAU(EntitySPAU entitySPAU) {
|
||||
this.EntitySPAU = entitySPAU;
|
||||
@ -62,6 +63,24 @@ public class DrawningSPAU {
|
||||
}
|
||||
EntitySPAU = new EntitySPAU(speed, weight, bodyColor);
|
||||
}
|
||||
public DrawningSPAU(EntitySPAU sPAU,IDrawable roll, int width, int height)
|
||||
{ if (this.carHeight >= height)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (this.carWidth >= width)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
startPosX = 0;
|
||||
startPosY = 0;
|
||||
pictureWidth = width;
|
||||
pictureHeight = height;
|
||||
|
||||
EntitySPAU = sPAU;
|
||||
Rollers = roll;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
@ -113,7 +132,7 @@ public class DrawningSPAU {
|
||||
Path2D.Double path = new Path2D.Double();
|
||||
|
||||
//гусеницы
|
||||
IDrawable Rollers = new DrawningRollers(g2d, startPosX, startPosY, bodyColor, _numbeRollers);
|
||||
Rollers = new DrawningRollers(g2d, startPosX, startPosY, bodyColor, _numbeRollers);
|
||||
switch (rollVar) {
|
||||
case 2:
|
||||
Rollers = new DrawningClamps(g2d, startPosX, startPosY, bodyColor, _numbeRollers);
|
||||
|
60
SelfPropelledArtilleryUnit/Generics/RandomParts.java
Normal file
60
SelfPropelledArtilleryUnit/Generics/RandomParts.java
Normal file
@ -0,0 +1,60 @@
|
||||
package SelfPropelledArtilleryUnit.Generics;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import SelfPropelledArtilleryUnit.DrawningObjects.DrawningSPAU;
|
||||
import SelfPropelledArtilleryUnit.DrawningObjects.IDrawable;
|
||||
import SelfPropelledArtilleryUnit.Entities.EntitySPAU;
|
||||
|
||||
public class RandomParts<T extends EntitySPAU, I extends IDrawable> {
|
||||
private ArrayList<T> entities;
|
||||
private ArrayList<I> interfaceDops;
|
||||
private int CntOfEnt;
|
||||
private int MaxCntOfEnt;
|
||||
private int CntOfDops;
|
||||
private int MaxCntOfDops;
|
||||
private int WidthOfPanel;
|
||||
private int HeightOfPanel;
|
||||
|
||||
public RandomParts(int maxCountOfBuses, int maxCountOfDoors, int width, int height) {
|
||||
MaxCntOfEnt = maxCountOfBuses;
|
||||
MaxCntOfDops = maxCountOfDoors;
|
||||
entities = new ArrayList<T>(MaxCntOfEnt);
|
||||
interfaceDops = new ArrayList<I>(MaxCntOfDops);
|
||||
CntOfEnt = 0;
|
||||
CntOfDops = 0;
|
||||
WidthOfPanel = width;
|
||||
HeightOfPanel = height;
|
||||
}
|
||||
|
||||
//Полиморфные методы добавления в массив
|
||||
public boolean Add(T bus) {
|
||||
if (bus == null || CntOfEnt >= MaxCntOfEnt) {
|
||||
return false;
|
||||
}
|
||||
entities.add(CntOfEnt++, bus);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean Add(I door) {
|
||||
if (door == null || CntOfDops >= MaxCntOfDops) {
|
||||
return false;
|
||||
}
|
||||
interfaceDops.add(CntOfDops++, door);
|
||||
return true;
|
||||
}
|
||||
|
||||
public DrawningSPAU CreateObject() {
|
||||
if (CntOfEnt == 0 || CntOfDops == 0) {
|
||||
return null;
|
||||
}
|
||||
Random rand = new Random();
|
||||
int indexOfEntity = rand.nextInt(0, CntOfEnt);
|
||||
int indexOfDop = rand.nextInt(0, CntOfDops);
|
||||
T ent = entities.get(indexOfEntity);
|
||||
I dop = interfaceDops.get(indexOfDop);
|
||||
return new DrawningSPAU(ent, dop, WidthOfPanel, HeightOfPanel);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user