Laba4 KozyrevSS GasolineTanker JAVA HARD
This commit is contained in:
parent
264bf6c6af
commit
59c78e5111
@ -5,6 +5,7 @@ import java.awt.event.ActionListener;
|
||||
|
||||
class CollectionFrame extends JComponent {
|
||||
private final CarsGenericCollection<DrawTanker, DrawingObjectTanker> _tanks;
|
||||
|
||||
protected final int Width;
|
||||
protected final int Height;
|
||||
public CollectionFrame(int width, int height)
|
||||
@ -123,6 +124,8 @@ class GarageFrame extends JFrame {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
Collection = new CollectionFrame(Width-200, Height);
|
||||
Collection.setLayout(null);
|
||||
Collection.setBounds(0, 0, Width-200, Height);
|
||||
|
@ -10,14 +10,12 @@ class DrawRandomTanker extends JComponent {
|
||||
|
||||
public DrawRandomTanker() {
|
||||
GeneratorTanker = new ComboGenericCollection<>(25, 1000, 600);
|
||||
GeneratorTanker.Add(GeneratorTanker.GenerateTanker());
|
||||
GeneratorTanker.Add(GeneratorTanker.GenerateTanker());
|
||||
GeneratorTanker.Add(GeneratorTanker.GenerateTanker());
|
||||
GeneratorTanker.Add(GeneratorTanker.GenerateTanker());
|
||||
GeneratorTanker.Add(GeneratorTanker.GenerateWheel());
|
||||
GeneratorTanker.Add(GeneratorTanker.GenerateWheel());
|
||||
GeneratorTanker.Add(GeneratorTanker.GenerateWheel());
|
||||
GeneratorTanker.Add(GeneratorTanker.GenerateWheel());
|
||||
GeneratorTanker.Add(GenerateTanker());
|
||||
GeneratorTanker.Add(GenerateWheel());
|
||||
GeneratorTanker.Add(GenerateTanker());
|
||||
GeneratorTanker.Add(GenerateWheel());
|
||||
GeneratorTanker.Add(GenerateTanker());
|
||||
GeneratorTanker.Add(GenerateWheel());
|
||||
}
|
||||
public void paintComponent(Graphics g)
|
||||
{
|
||||
@ -27,7 +25,40 @@ class DrawRandomTanker extends JComponent {
|
||||
_drawTanker.DrawTransport(g);
|
||||
super.repaint();
|
||||
}
|
||||
private boolean IntToBool(int n) {return n % 2 == 0;}
|
||||
public BaseTanker GenerateTanker()
|
||||
{
|
||||
Random random = new Random();
|
||||
int mode = random.nextInt(0, 100) % 2;
|
||||
if (mode == 0)
|
||||
{
|
||||
return new BaseTanker(random.nextInt(100, 200), random.nextInt(2000, 4000),
|
||||
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)));
|
||||
}
|
||||
else
|
||||
{
|
||||
return new GasolineTanker(random.nextInt(100, 200), random.nextInt(2000, 4000),
|
||||
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
|
||||
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
|
||||
IntToBool(random.nextInt(0, 100)),IntToBool(random.nextInt(0, 100)), IntToBool(random.nextInt(0, 100)));
|
||||
}
|
||||
}
|
||||
|
||||
public IWheelDraw GenerateWheel()
|
||||
{
|
||||
Random random = new Random();
|
||||
int mode = random.nextInt(0, 100) % 3;
|
||||
IWheelDraw Wheels = new DrawWheelSquare();
|
||||
switch (mode)
|
||||
{
|
||||
case 0 -> {Wheels = new DrawWheelCircle();}
|
||||
case 1 -> {Wheels = new DrawWheelClassic();}
|
||||
case 2 -> {Wheels = new DrawWheelSquare();}
|
||||
}
|
||||
int count = random.nextInt(0, 100);
|
||||
Wheels.setWheelCount(count);
|
||||
return Wheels;
|
||||
}
|
||||
protected void GenerateTanker_Click()
|
||||
{
|
||||
_drawTanker = GeneratorTanker.CreateDraw();
|
||||
|
@ -22,37 +22,7 @@ public class ComboGenericCollection <T extends BaseTanker, U extends IWheelDraw
|
||||
Height = height;
|
||||
}
|
||||
|
||||
public T GenerateTanker()
|
||||
{
|
||||
int mode = random.nextInt(0, 100) % 2;
|
||||
if (mode == 0)
|
||||
{
|
||||
return (T) new BaseTanker(random.nextInt(100, 200), random.nextInt(2000, 4000),
|
||||
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)));
|
||||
}
|
||||
else
|
||||
{
|
||||
return (T) new GasolineTanker(random.nextInt(100, 200), random.nextInt(2000, 4000),
|
||||
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
|
||||
new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)),
|
||||
IntToBool(random.nextInt(0, 100)),IntToBool(random.nextInt(0, 100)), IntToBool(random.nextInt(0, 100)));
|
||||
}
|
||||
}
|
||||
|
||||
public U GenerateWheel()
|
||||
{
|
||||
int mode = random.nextInt(0, 100) % 3;
|
||||
U Wheels = (U) new DrawWheelSquare();
|
||||
switch (mode)
|
||||
{
|
||||
case 0 -> {Wheels = (U) new DrawWheelCircle();}
|
||||
case 1 -> {Wheels = (U) new DrawWheelClassic();}
|
||||
case 2 -> {Wheels = (U) new DrawWheelSquare();}
|
||||
}
|
||||
int count = random.nextInt(0, 100);
|
||||
Wheels.setWheelCount(count);
|
||||
return Wheels;
|
||||
}
|
||||
|
||||
public boolean Add(T tanker)
|
||||
{
|
||||
@ -83,7 +53,7 @@ public class ComboGenericCollection <T extends BaseTanker, U extends IWheelDraw
|
||||
}
|
||||
|
||||
|
||||
private boolean IntToBool(int n) {return n % 2 == 0;}
|
||||
|
||||
|
||||
public DrawTanker CreateDraw()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user