PIbd-22_Smirnov_A_A_RoadTra.../DrawingRoadTrain.java

91 lines
3.5 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import java.awt.*;
public class DrawingRoadTrain {
private WindowDrawing windowDrawing;
public EntityRoadTrain EntityRoadTrain;
private int _pictureWidth;
private int _pictureHeight;
private int _startPosX;
private int _startPosY;
private int _roadTrainWidth = 200;
private int _roadTrainHeight = 100;
public boolean Init(int speed, double weight, Color bodyColor, Color
additionalColor, boolean wheel, boolean door, boolean light, int numWindow, int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
if (_pictureHeight < _roadTrainHeight || _pictureWidth < _roadTrainWidth)
return false;
EntityRoadTrain = new EntityRoadTrain();
EntityRoadTrain.Init(speed, weight, bodyColor, additionalColor,wheel, door, light, numWindow);
windowDrawing = new WindowDrawing();
windowDrawing.setNumWindow(numWindow);
return true;
}
public void SetPosition(int x, int y)
{
_startPosX = Math.min(x, _pictureWidth-_roadTrainWidth);
_startPosY = Math.min(y, _pictureHeight- _roadTrainHeight);
}
public void MoveTransport(Direction direction)
{
if (EntityRoadTrain == null){
return;
}
switch (direction)
{
case Left:
if (_startPosX - EntityRoadTrain.Step > 0)
{
_startPosX -= (int) EntityRoadTrain.Step;
}
break;
case Up:
if (_startPosY - EntityRoadTrain.Step > 0)
{
_startPosY -= (int) EntityRoadTrain.Step;
}
break;
case Right:
if (_startPosX + _roadTrainWidth + EntityRoadTrain.Step < _pictureWidth)
{
_startPosX += (int) EntityRoadTrain.Step;
}
break;
case Down:
if (_startPosY + _roadTrainHeight + EntityRoadTrain.Step < _pictureHeight)
{
_startPosY += (int) EntityRoadTrain.Step;
}
break;
}
}
public void DrawTransport(Graphics2D g) {
if (EntityRoadTrain == null) {
return;
}
// машина
g.drawRect(_startPosX, _startPosY + 50, 160, 20); // кузов
g.drawOval(_startPosX + 5, _startPosY + 70, 30, 30); // колесо
g.drawOval(_startPosX + 40, _startPosY + 70, 30, 30); // колесо
g.drawOval(_startPosX + 120, _startPosY + 70, 30, 30); // колесо
g.drawRect(_startPosX + 120, _startPosY + 10, 40, 40); // кабина
g.drawRect(_startPosX + 10, _startPosY, 90, 50); // бак с водой
g.drawRect(_startPosX + 130, _startPosY + 20, 30, 20); // окно
g.drawLine(_startPosX + 160, _startPosY + 70, _startPosX + 180, _startPosY + 80); // держатель для щетки
g.drawRect(_startPosX + 170, _startPosY + 80, 40, 10); // щетка
// обвесы
g.setColor(EntityRoadTrain.AdditionalColor);
if (EntityRoadTrain.Wheel) {
g.fillOval(_startPosX + 75, _startPosY + 70, 30, 30); // колесо
}
if (EntityRoadTrain.Door) {
g.fillRect(_startPosX + 40, _startPosY + 20, 20, 30); // дверь
}
if (EntityRoadTrain.Light) {
g.fillRect(_startPosX + 135, _startPosY, 10, 10); // мигалка
}
}
}