Сданная сложная лаб 1

This commit is contained in:
Данила Мочалов 2022-09-27 16:26:05 +04:00
parent 0a29f09918
commit ac9d6db704
2 changed files with 16 additions and 20 deletions

View File

@ -12,14 +12,15 @@ class DrawningLocomotive {
/// Высота окна отрисовки /// Высота окна отрисовки
private Integer _pictureHeight = null; private Integer _pictureHeight = null;
/// Ширина отрисовки локомотива /// Ширина отрисовки локомотива
private final int _locomotiveWidth = 110; private final int _locomotiveWidth = 120;
/// Высота отрисовки локомотива /// Высота отрисовки локомотива
private final int _locomotiveHeight = 50; private final int _locomotiveHeight = 50;
/// Инициализация свойств /// Инициализация свойств
public void Init(int speed, float weight, Color bodyColor, int wheelsNum, EntityLocomotive entity) public void Init(int speed, float weight, Color bodyColor, int wheelsNum, EntityLocomotive entity)
{ {
Locomotive = entity; Locomotive = entity;
extraWheelsDraw = new ExtraWheelsDraw(wheelsNum, bodyColor); extraWheelsDraw = new ExtraWheelsDraw();
extraWheelsDraw.Init(wheelsNum, bodyColor);
Locomotive.Init(speed, weight, bodyColor); Locomotive.Init(speed, weight, bodyColor);
} }
/// Установка позиции локомотива /// Установка позиции локомотива
@ -90,7 +91,7 @@ class DrawningLocomotive {
} }
//тело //тело
g.setColor(Color.BLACK); g.setColor(Color.BLACK);
g.drawRect((int)_startPosX , (int)_startPosY, _locomotiveWidth - 10, _locomotiveHeight - 10); g.drawRect((int)_startPosX , (int)_startPosY, _locomotiveWidth - 20, _locomotiveHeight - 10);
//окна //окна
g.setColor(Locomotive.getBodyColor()); g.setColor(Locomotive.getBodyColor());
g.fillRect((int)_startPosX + 10, (int)_startPosY + 10, 10, 10); g.fillRect((int)_startPosX + 10, (int)_startPosY + 10, 10, 10);

View File

@ -1,28 +1,24 @@
import java.awt.*; import java.awt.*;
public class ExtraWheelsDraw { public class ExtraWheelsDraw {
private WheelsCount wheelsCount; private WheelsCount wheelsCount = WheelsCount.Two;
private int wheelsNum;
public void setWheelsNum(int num) { public void setWheelsNum(int num) {
wheelsNum = num; switch (num) {
switch (wheelsNum) {
case 0: { case 0: {
wheelsCount = WheelsCount.Two;
break;
}
case 1: {
wheelsCount = WheelsCount.Three; wheelsCount = WheelsCount.Three;
break; break;
} }
case 2: { case 1: {
wheelsCount = WheelsCount.Four; wheelsCount = WheelsCount.Four;
break; break;
} }
default:
break;
} }
} }
private final Color color; private Color color;
public ExtraWheelsDraw(int num, Color color) { public void Init(int num, Color color) {
setWheelsNum(num); setWheelsNum(num);
this.color = color; this.color = color;
} }
@ -32,17 +28,16 @@ public class ExtraWheelsDraw {
g.drawOval(startPosX, startPosY + 40, 10, 10); g.drawOval(startPosX, startPosY + 40, 10, 10);
g.drawOval(startPosX + 90, startPosY + 40, 10, 10); g.drawOval(startPosX + 90, startPosY + 40, 10, 10);
switch (wheelsCount) { switch (wheelsCount) {
case Two: { case Four: {
break; g.drawOval(startPosX + 70, startPosY + 40, 10, 10);
} }
case Three: { case Three: {
g.drawOval(startPosX + 20, startPosY + 40, 10, 10); g.drawOval(startPosX + 20, startPosY + 40, 10, 10);
break; break;
} }
case Four: { default:
g.drawOval(startPosX + 20, startPosY + 40, 10, 10); break;
g.drawOval(startPosX + 70, startPosY + 40, 10, 10);
}
} }
} }
} }