Lab1
This commit is contained in:
parent
8256207a51
commit
0ccdd9e2d6
@ -1,16 +0,0 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class CanvasAccordionBus extends JComponent {
|
||||
public DrawningAccordionBus _drawningAccordionBus;
|
||||
public CanvasAccordionBus(){}
|
||||
public void paintComponent(Graphics g) {
|
||||
if (_drawningAccordionBus == null) {
|
||||
return;
|
||||
}
|
||||
super.paintComponents(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
_drawningAccordionBus.DrawTransport(g2d);
|
||||
super.repaint();
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
public enum CountEntrances {
|
||||
Three,
|
||||
Four,
|
||||
Five
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
public enum DirectionType {
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawingEntrances {
|
||||
private CountEntrances countEntrances;
|
||||
|
||||
Random rand = new Random();
|
||||
int randomNum = rand.nextInt(5);
|
||||
|
||||
public CountEntrances getCount() {
|
||||
return countEntrances;
|
||||
}
|
||||
public void setCountEntrances() {
|
||||
switch (randomNum) {
|
||||
case 3:
|
||||
countEntrances = CountEntrances.Three;
|
||||
break;
|
||||
case 4:
|
||||
countEntrances = CountEntrances.Four;
|
||||
break;
|
||||
case 5:
|
||||
countEntrances = CountEntrances.Five;
|
||||
break;
|
||||
default:
|
||||
countEntrances = CountEntrances.Five;
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void DrawEntrances(Graphics2D g, int _StartPosX, int _StartPosY) {
|
||||
if (countEntrances == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_StartPosX + 74, _StartPosY + 18, 5, 20);
|
||||
g.drawRect(_StartPosX + 84, _StartPosY + 18, 5, 20);
|
||||
|
||||
if (countEntrances == CountEntrances.Three) {
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_StartPosX + 94, _StartPosY + 18, 5, 20);
|
||||
}
|
||||
|
||||
if (countEntrances == CountEntrances.Four) {
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_StartPosX + 94, _StartPosY + 18, 5, 20);
|
||||
g.drawRect(_StartPosX + 104, _StartPosY + 18, 5, 20);
|
||||
}
|
||||
|
||||
if (countEntrances == CountEntrances.Five) {
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_StartPosX + 94, _StartPosY + 18, 5, 20);
|
||||
g.drawRect(_StartPosX + 104, _StartPosY + 18, 5, 20);
|
||||
g.drawRect(_StartPosX + 112, _StartPosY + 18, 5, 20);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,138 +0,0 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawningAccordionBus extends JPanel {
|
||||
public EntityAccordionBus entityAccordionBus;
|
||||
public DrawingEntrances drawingEntrances = null;
|
||||
|
||||
private Integer picture_width;
|
||||
private Integer picture_height;
|
||||
|
||||
private Integer _StartPosX;
|
||||
private Integer _StartPosY;
|
||||
|
||||
private int drawingBusWidth = 60;
|
||||
private int drawingBusHeight = 40;
|
||||
|
||||
public void Init(int speed, double weight, Color bodycolor, Color additionalcolor, boolean compartment, boolean entrance, boolean windows) {
|
||||
entityAccordionBus = new EntityAccordionBus();
|
||||
entityAccordionBus.Init(speed, weight, bodycolor, additionalcolor, compartment, entrance, windows);
|
||||
picture_width = null;
|
||||
picture_height = null;
|
||||
_StartPosX = null;
|
||||
_StartPosY = null;
|
||||
drawingEntrances = new DrawingEntrances();
|
||||
Random rand = new Random();
|
||||
drawingEntrances.setCountEntrances();
|
||||
}
|
||||
|
||||
public boolean SetPictureSize(int width, int height) {
|
||||
if (width < drawingBusWidth || height < drawingBusHeight) return false;
|
||||
picture_width = width;
|
||||
picture_height = height;
|
||||
if (_StartPosX != null || _StartPosY != null) {
|
||||
if (_StartPosX + drawingBusWidth > picture_width) {
|
||||
_StartPosX = _StartPosX - (_StartPosX + drawingBusWidth - picture_width);
|
||||
}
|
||||
else if (_StartPosX < 0) _StartPosX = 0;
|
||||
if (_StartPosY + drawingBusHeight > picture_height) {
|
||||
_StartPosY = _StartPosY - (_StartPosY + drawingBusHeight - picture_height);
|
||||
}
|
||||
else if (_StartPosY < 0) _StartPosY = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y) {
|
||||
if (!(picture_width != null && picture_height != null)) return;
|
||||
if (x + drawingBusWidth > picture_width) {
|
||||
_StartPosX = x - (x + drawingBusWidth - picture_width);
|
||||
}
|
||||
else if (x < 0) _StartPosX = 0;
|
||||
else _StartPosX = x;
|
||||
if (y + drawingBusHeight > picture_height) {
|
||||
_StartPosY = y - (y + drawingBusHeight - picture_height);
|
||||
}
|
||||
else if (y < 0) _StartPosY = 0;
|
||||
else _StartPosY = y;
|
||||
}
|
||||
|
||||
public boolean MoveTransport(DirectionType direction) {
|
||||
if (entityAccordionBus == null || _StartPosX == null || _StartPosY == null) return false;
|
||||
switch (direction) {
|
||||
case Left:
|
||||
if (_StartPosX - entityAccordionBus.Step > 0) {
|
||||
_StartPosX -= (int) entityAccordionBus.Step;
|
||||
}
|
||||
return true;
|
||||
case Up:
|
||||
if (_StartPosY - entityAccordionBus.Step > 0) {
|
||||
_StartPosY -= (int) entityAccordionBus.Step;
|
||||
}
|
||||
return true;
|
||||
case Right:
|
||||
if (_StartPosX + drawingBusWidth + (int) entityAccordionBus.Step < picture_width - entityAccordionBus.Step) {
|
||||
_StartPosX += (int) entityAccordionBus.Step;
|
||||
}
|
||||
return true;
|
||||
case Down:
|
||||
if (_StartPosY + drawingBusHeight + (int) entityAccordionBus.Step < picture_height - entityAccordionBus.Step) {
|
||||
_StartPosY += (int) entityAccordionBus.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawTransport(Graphics2D g) {
|
||||
if (entityAccordionBus == null || _StartPosX == null || _StartPosY == null) return;
|
||||
|
||||
//вагончик
|
||||
g.setColor(entityAccordionBus.getBodyColor());
|
||||
g.fillRect(_StartPosX + 10, _StartPosY + 10, 50, 30);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_StartPosX + 10, _StartPosY + 10, 50, 30);
|
||||
|
||||
//двери
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_StartPosX + 26, _StartPosY + 18,10, 20);
|
||||
|
||||
//окна
|
||||
g.setColor(Color.BLUE);
|
||||
g.fillOval(_StartPosX + 15, _StartPosY + 15, 5, 10);
|
||||
g.fillOval(_StartPosX + 40, _StartPosY + 15, 5, 10);
|
||||
g.fillOval(_StartPosX + 50, _StartPosY + 15, 5, 10);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawOval(_StartPosX + 15, _StartPosY + 15, 5, 10);
|
||||
g.drawOval(_StartPosX + 40, _StartPosY + 15, 5, 10);
|
||||
g.drawOval(_StartPosX + 50, _StartPosY + 15, 5, 10);
|
||||
|
||||
//колеса
|
||||
g.setColor(Color.BLACK);
|
||||
g.fillOval(_StartPosX + 15, _StartPosY + 35, 10, 10);
|
||||
g.fillOval(_StartPosX + 45, _StartPosY + 35, 10, 10);
|
||||
g.drawOval(_StartPosX + 15, _StartPosY + 35, 10, 10);
|
||||
g.drawOval(_StartPosX + 45, _StartPosY + 35, 10, 10);
|
||||
|
||||
if(entityAccordionBus.withCompartment()) {
|
||||
drawingBusWidth = 130;
|
||||
g.setColor(entityAccordionBus.getAdditionalColor());
|
||||
g.fillRect(_StartPosX + 70, _StartPosY + 10, 50, 30);
|
||||
g.fillRect(_StartPosX + 60, _StartPosY + 15, 10, 20);
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(_StartPosX + 70, _StartPosY + 10, 50, 30);
|
||||
g.drawRect(_StartPosX + 60, _StartPosY + 15, 10, 20);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.fillOval(_StartPosX + 75, _StartPosY + 35, 10, 10);
|
||||
g.fillOval(_StartPosX + 105, _StartPosY + 35, 10, 10);
|
||||
g.drawOval(_StartPosX + 75, _StartPosY + 35, 10, 10);
|
||||
g.drawOval(_StartPosX + 105, _StartPosY + 35, 10, 10);
|
||||
|
||||
drawingEntrances.DrawEntrances(g, _StartPosX, _StartPosY);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class EntityAccordionBus {
|
||||
|
||||
private int Speed;
|
||||
|
||||
private double Weight;
|
||||
|
||||
private Color BodyColor;
|
||||
public Color getBodyColor() {
|
||||
return BodyColor;
|
||||
}
|
||||
|
||||
private Color AdditionalColor;
|
||||
public Color getAdditionalColor() {
|
||||
return AdditionalColor;
|
||||
}
|
||||
|
||||
public double Step;
|
||||
|
||||
private boolean Compartment;
|
||||
public boolean withCompartment() {
|
||||
return Compartment;
|
||||
}
|
||||
|
||||
private boolean Entrance;
|
||||
public boolean withEntrance() {
|
||||
return Entrance;
|
||||
}
|
||||
|
||||
private boolean Windows;
|
||||
public boolean withWindows() {
|
||||
return Windows;
|
||||
}
|
||||
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor,
|
||||
boolean compartment, boolean entrance, boolean windows) {
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
Compartment = compartment; // отсек
|
||||
Entrance = entrance; // крылья
|
||||
Windows = windows;
|
||||
Step = Speed * 100 / weight;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user