lab3 some minor fixes
This commit is contained in:
parent
96a9477a8f
commit
42e878848f
@ -32,8 +32,8 @@ public class HardFrame extends JFrame {
|
||||
int size = rand.nextInt(1, 10);
|
||||
generic = new HardGeneric<>(size, size, pictureBoxWidth, pictureBoxHeight);
|
||||
for(int i = 0; i < size; i++){
|
||||
generic.insertShip(makeRandomShip());
|
||||
generic.insertBlock(makeRandomBlock());
|
||||
generic.insertShip(generic.makeRandomShip());
|
||||
generic.insertBlock(generic.makeRandomBlock());
|
||||
}
|
||||
buttonMakeObject.addActionListener(e -> {
|
||||
DrawingShip drawingShip = generic.makeObject();
|
||||
@ -47,29 +47,5 @@ public class HardFrame extends JFrame {
|
||||
pack();
|
||||
setVisible(true);
|
||||
}
|
||||
public EntityShip makeRandomShip(){
|
||||
Random random = new Random();
|
||||
EntityShip ship;
|
||||
switch (random.nextInt(2)){
|
||||
case 0 -> ship = new EntityShip(random.nextInt(100, 300), random.nextDouble(1000,3000),
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)));
|
||||
default -> ship = new EntityBattleship(random.nextInt(100, 300), random.nextDouble(1000,3000),
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
||||
random.nextBoolean(), random.nextBoolean());
|
||||
}
|
||||
return ship;
|
||||
}
|
||||
public IDrawBlocks makeRandomBlock(){
|
||||
Random random = new Random();
|
||||
IDrawBlocks block;
|
||||
switch (random.nextInt(3)){
|
||||
case 1 -> block = new DrawingRoundBlocks();
|
||||
case 2 -> block = new DrawingCrossBlocks();
|
||||
default -> block = new DrawingBlocks();
|
||||
}
|
||||
block.setNumber((random.nextInt(3) + 1) * 2);
|
||||
return block;
|
||||
}
|
||||
void draw(){pictureBox.repaint();}
|
||||
}
|
@ -1,11 +1,10 @@
|
||||
package generics;
|
||||
|
||||
import drawing_objects.DrawingBattleship;
|
||||
import drawing_objects.DrawingShip;
|
||||
import drawing_objects.IDrawBlocks;
|
||||
import drawing_objects.*;
|
||||
import entities.EntityBattleship;
|
||||
import entities.EntityShip;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class HardGeneric<T extends EntityShip, U extends IDrawBlocks>{
|
||||
@ -52,4 +51,28 @@ public class HardGeneric<T extends EntityShip, U extends IDrawBlocks>{
|
||||
((EntityBattleship) entity).getTurret(), ((EntityBattleship) entity).getRocketLauncher(), pictureBoxWidth, pictureBoxHeight, block.getType(), block.getNumber());
|
||||
return new DrawingShip(entity.getSpeed(), entity.getWeight(), entity.getBodyColor(), pictureBoxWidth, pictureBoxHeight, block.getType(), block.getNumber());
|
||||
}
|
||||
public EntityShip makeRandomShip(){
|
||||
Random random = new Random();
|
||||
EntityShip ship;
|
||||
switch (random.nextInt(2)){
|
||||
case 0 -> ship = new EntityShip(random.nextInt(100, 300), random.nextDouble(1000,3000),
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)));
|
||||
default -> ship = new EntityBattleship(random.nextInt(100, 300), random.nextDouble(1000,3000),
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
||||
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
|
||||
random.nextBoolean(), random.nextBoolean());
|
||||
}
|
||||
return ship;
|
||||
}
|
||||
public IDrawBlocks makeRandomBlock(){
|
||||
Random random = new Random();
|
||||
IDrawBlocks block;
|
||||
switch (random.nextInt(3)){
|
||||
case 1 -> block = new DrawingRoundBlocks();
|
||||
case 2 -> block = new DrawingCrossBlocks();
|
||||
default -> block = new DrawingBlocks();
|
||||
}
|
||||
block.setNumber((random.nextInt(3) + 1) * 2);
|
||||
return block;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user