fix polimorph class
This commit is contained in:
parent
55025611d1
commit
d526660dc2
@ -1,42 +1,45 @@
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class PolimorphClass <M extends ArmoredVehicleEntity, R extends IDrawingRoller> {
|
||||
Object[] machines;
|
||||
Object[] rollers;
|
||||
ArrayList<M> machines;
|
||||
ArrayList<R> rollers;
|
||||
|
||||
int machineCount = 0;
|
||||
int rollersCount = 0;
|
||||
int _machineCount = 0;
|
||||
int _rollersCount = 0;
|
||||
|
||||
public PolimorphClass(int machineCount, int rollersCount) {
|
||||
machines = new Object[machineCount];
|
||||
rollers = new Object[rollersCount];
|
||||
_machineCount = machineCount;
|
||||
_rollersCount = rollersCount;
|
||||
machines = new ArrayList<M>(_machineCount);
|
||||
rollers = new ArrayList<R>(_rollersCount);
|
||||
}
|
||||
|
||||
public int AddEntity(M machine)
|
||||
{
|
||||
if(machineCount < machines.length){
|
||||
machines[machineCount] = machine;
|
||||
return machineCount++;
|
||||
if(_machineCount < machines.size()){
|
||||
machines.add(machine);
|
||||
return _machineCount++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int AddRollers(R rolls)
|
||||
{
|
||||
if(rollersCount < rollers.length){
|
||||
rollers[rollersCount]=rolls;
|
||||
return rollersCount++;
|
||||
if(_rollersCount < rollers.size()){
|
||||
rollers.add(rolls);
|
||||
return _rollersCount++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public DrawingArmoredVehicle CreateMachine() {
|
||||
int iMachine = new Random().nextInt(machineCount);
|
||||
int iRoller = new Random().nextInt(rollersCount);
|
||||
M selectedMachine = (M)machines[iMachine];
|
||||
R selectedRoller = (R)rollers[iRoller];
|
||||
int iMachine = new Random().nextInt(0, _machineCount);
|
||||
int iRoller = new Random().nextInt(0, _rollersCount);
|
||||
M selectedMachine = machines.get(iMachine);
|
||||
R selectedRoller = rollers.get(iRoller);
|
||||
if (selectedMachine instanceof TankEntity) {
|
||||
return new DrawingTank(selectedMachine, selectedRoller);
|
||||
}
|
||||
|
@ -207,6 +207,7 @@ public class PolimorphForm extends JFrame{
|
||||
|
||||
polymorphMachine.AddRollers(roll);
|
||||
polymorphMachine.AddEntity(machine);
|
||||
|
||||
_ArmoredVehicle = polymorphMachine.CreateMachine();
|
||||
_ArmoredVehicle.Count = c;
|
||||
SetData();
|
||||
|
Loading…
Reference in New Issue
Block a user