PIbd-11 Permyakov R.G. AccordionBus Hard Lab1 #1
@ -3,7 +3,7 @@
|
||||
<grid id="27dc6" binding="panelAccordionBus" layout-manager="GridLayoutManager" row-count="3" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="844" height="581"/>
|
||||
<xy x="67" y="22" width="797" height="579"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<background color="-4671565"/>
|
||||
|
@ -1,8 +1,13 @@
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawningAccordionBus {
|
||||
private EntityAccordionBus entityAccordionBus;
|
||||
|
||||
DrawningDoors drawningDoors = new DrawningDoors();
|
||||
|
||||
Random rnd = new Random();
|
||||
|
||||
public EntityAccordionBus getEntityAccordionBus(){return entityAccordionBus;}
|
||||
|
||||
private Integer pictureWidth;
|
||||
@ -69,19 +74,19 @@ public class DrawningAccordionBus {
|
||||
switch (direction){
|
||||
case Left:
|
||||
if (startPosX - step > 0) startPosX -= (int)step;
|
||||
else startPosX = 0;
|
||||
else startPosX = 10;
|
||||
return true;
|
||||
case Right:
|
||||
if (startPosX + drawingBusWidth + step < pictureWidth - heightCap) startPosX += (int)step;
|
||||
else startPosX = pictureWidth - drawingBusWidth;
|
||||
if (startPosX + drawingBusWidth + step < pictureWidth) startPosX += (int)step;
|
||||
else startPosX = pictureWidth - drawingBusWidth + 8;
|
||||
return true;
|
||||
case Up:
|
||||
if (startPosY - step > heightCap) startPosY -= (int)step;
|
||||
else startPosY = heightCap;
|
||||
return true;
|
||||
case Down:
|
||||
if (startPosY + drawingBusHeight < pictureHeight) startPosY += (int)step;
|
||||
else startPosY = pictureHeight - drawingBusHeight;
|
||||
if (startPosY + drawingBusHeight + step < pictureHeight + heightCap) startPosY += (int)step;
|
||||
else startPosY = pictureHeight - drawingBusHeight + heightCap + 10;
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
@ -93,11 +98,11 @@ public class DrawningAccordionBus {
|
||||
|
||||
//корпус
|
||||
g.setColor(entityAccordionBus.getBodyColor());
|
||||
g.fillRect(startPosX.intValue(), startPosY.intValue() + 10, 60, 15);
|
||||
g.fillRect(startPosX.intValue() + 70, startPosY.intValue() + 10, 60, 15);
|
||||
g.fillRect(startPosX, startPosY + 10, 60, 15);
|
||||
g.fillRect(startPosX + 70, startPosY + 10, 60, 15);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(startPosX.intValue() + 70, startPosY.intValue() + 10, 60, 15);
|
||||
g.drawRect(startPosX.intValue(), startPosY.intValue() + 10, 60, 15);
|
||||
g.drawRect(startPosX + 70, startPosY + 10, 60, 15);
|
||||
g.drawRect(startPosX, startPosY + 10, 60, 15);
|
||||
|
||||
//доп. линия
|
||||
if (entityAccordionBus.getAdditionalLine()){
|
||||
@ -175,43 +180,7 @@ public class DrawningAccordionBus {
|
||||
}
|
||||
|
||||
//двери
|
||||
switch(entityAccordionBus.getEnumerateDoors()){
|
||||
case threeDoors:
|
||||
g.setColor(entityAccordionBus.getAdditionalColor());
|
||||
g.fillRect(startPosX + 20, startPosY + 15, 5, 10);
|
||||
g.fillRect(startPosX + 123, startPosY + 15, 5, 10);
|
||||
g.fillRect(startPosX + 87, startPosY + 15, 5, 10);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(startPosX + 20, startPosY + 15, 5, 10);
|
||||
g.drawRect(startPosX + 123, startPosY + 15, 5, 10);
|
||||
g.drawRect(startPosX + 87, startPosY + 15, 5, 10);
|
||||
break;
|
||||
case fourDoors:
|
||||
g.setColor(entityAccordionBus.getAdditionalColor());
|
||||
g.fillRect(startPosX + 20, startPosY + 15, 5, 10);
|
||||
g.fillRect(startPosX + 123, startPosY + 15, 5, 10);
|
||||
g.fillRect(startPosX + 87, startPosY + 15, 5, 10);
|
||||
g.fillRect(startPosX + 53, startPosY + 15, 5, 10);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(startPosX + 20, startPosY + 15, 5, 10);
|
||||
g.drawRect(startPosX + 123, startPosY + 15, 5, 10);
|
||||
g.drawRect(startPosX + 87, startPosY + 15, 5, 10);
|
||||
g.drawRect(startPosX + 53, startPosY + 15, 5, 10);
|
||||
break;
|
||||
case fiveDoors:
|
||||
g.setColor(entityAccordionBus.getAdditionalColor());
|
||||
g.fillRect(startPosX + 20, startPosY + 15, 5, 10);
|
||||
g.fillRect(startPosX + 123, startPosY + 15, 5, 10);
|
||||
g.fillRect(startPosX + 87, startPosY + 15, 5, 10);
|
||||
g.fillRect(startPosX + 53, startPosY + 15, 5, 10);
|
||||
g.fillRect(startPosX + 27, startPosY + 19, 11, 5);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(startPosX + 20, startPosY + 15, 5, 10);
|
||||
g.drawRect(startPosX + 123, startPosY + 15, 5, 10);
|
||||
g.drawRect(startPosX + 87, startPosY + 15, 5, 10);
|
||||
g.drawRect(startPosX + 53, startPosY + 15, 5, 10);
|
||||
g.drawRect(startPosX + 27, startPosY + 19, 11, 5);
|
||||
break;
|
||||
}
|
||||
drawningDoors.setEnumer((int)rnd.nextInt(3) + 3);
|
||||
|
||||
drawningDoors.paintDoors(startPosX, startPosY, g, entityAccordionBus.getAdditionalColor());
|
||||
}
|
||||
}
|
54
AccordionBus/src/DrawningDoors.java
Normal file
54
AccordionBus/src/DrawningDoors.java
Normal file
@ -0,0 +1,54 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningDoors {
|
||||
private EnumerateDoors enumer;
|
||||
|
||||
public void setEnumer(int value){
|
||||
if (value == 3) enumer = EnumerateDoors.threeDoors;
|
||||
if (value == 4) enumer = EnumerateDoors.fourDoors;
|
||||
if (value == 5) enumer = EnumerateDoors.fiveDoors;
|
||||
}
|
||||
|
||||
public boolean paintDoors(int startPosX, int startPosY, Graphics g, Color color){
|
||||
if (enumer == null) return false;
|
||||
switch(enumer){
|
||||
case threeDoors:
|
||||
g.setColor(color);
|
||||
g.fillRect(startPosX + 20, startPosY + 15, 5, 10);
|
||||
g.fillRect(startPosX + 123, startPosY + 15, 5, 10);
|
||||
g.fillRect(startPosX + 87, startPosY + 15, 5, 10);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(startPosX + 20, startPosY + 15, 5, 10);
|
||||
g.drawRect(startPosX + 123, startPosY + 15, 5, 10);
|
||||
g.drawRect(startPosX + 87, startPosY + 15, 5, 10);
|
||||
break;
|
||||
case fourDoors:
|
||||
g.setColor(color);
|
||||
g.fillRect(startPosX + 20, startPosY + 15, 5, 10);
|
||||
eegov
commented
Имеется дублирующийся код Имеется дублирующийся код
|
||||
g.fillRect(startPosX + 123, startPosY + 15, 5, 10);
|
||||
g.fillRect(startPosX + 87, startPosY + 15, 5, 10);
|
||||
g.fillRect(startPosX + 53, startPosY + 15, 5, 10);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(startPosX + 20, startPosY + 15, 5, 10);
|
||||
g.drawRect(startPosX + 123, startPosY + 15, 5, 10);
|
||||
g.drawRect(startPosX + 87, startPosY + 15, 5, 10);
|
||||
g.drawRect(startPosX + 53, startPosY + 15, 5, 10);
|
||||
break;
|
||||
case fiveDoors:
|
||||
g.setColor(color);
|
||||
g.fillRect(startPosX + 20, startPosY + 15, 5, 10);
|
||||
g.fillRect(startPosX + 123, startPosY + 15, 5, 10);
|
||||
g.fillRect(startPosX + 87, startPosY + 15, 5, 10);
|
||||
g.fillRect(startPosX + 53, startPosY + 15, 5, 10);
|
||||
g.fillRect(startPosX + 27, startPosY + 19, 11, 5);
|
||||
g.setColor(Color.black);
|
||||
g.drawRect(startPosX + 20, startPosY + 15, 5, 10);
|
||||
g.drawRect(startPosX + 123, startPosY + 15, 5, 10);
|
||||
g.drawRect(startPosX + 87, startPosY + 15, 5, 10);
|
||||
g.drawRect(startPosX + 53, startPosY + 15, 5, 10);
|
||||
g.drawRect(startPosX + 27, startPosY + 19, 11, 5);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user
Это делается в init