179 lines
5.9 KiB
Java
179 lines
5.9 KiB
Java
|
package ProjectElectricLocomotive;
|
||
|
import java.awt.*;
|
||
|
import java.security.cert.PolicyNode;
|
||
|
|
||
|
public class DrawingLocomotive {
|
||
|
public EntityLocomotive EntityLocomotive;
|
||
|
private DrawingWheel _drawingWheel;
|
||
|
private int _pictureWidth;
|
||
|
private int _pictureHeight;
|
||
|
public int _startPosX;
|
||
|
public int _startPosY;
|
||
|
private int _locoWidth = 150;
|
||
|
private int _locoHeight = 50;
|
||
|
|
||
|
public int GetPosX(){
|
||
|
return _startPosX;
|
||
|
}
|
||
|
public int GetPosY(){
|
||
|
return _startPosY;
|
||
|
}
|
||
|
public int GetWidth(){
|
||
|
return _locoWidth;
|
||
|
}
|
||
|
public int GetHeight(){
|
||
|
return _locoHeight;
|
||
|
}
|
||
|
|
||
|
public DrawingLocomotive(int speed, double weight, Color bodyColor, int width, int heigth)
|
||
|
{
|
||
|
if (width < _locoWidth || heigth < _locoHeight)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
_pictureWidth = width;
|
||
|
_pictureHeight = heigth;
|
||
|
EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor);
|
||
|
}
|
||
|
|
||
|
protected DrawingLocomotive(int speed, double weight, Color bodyColor, int width,
|
||
|
int height, int locoWidth, int locoHeight)
|
||
|
{
|
||
|
if (width < _locoWidth || height < _locoHeight)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
_pictureWidth = width;
|
||
|
_pictureHeight = height;
|
||
|
_locoWidth = locoWidth;
|
||
|
_locoHeight = locoHeight;
|
||
|
EntityLocomotive = new EntityLocomotive(speed, weight, bodyColor);
|
||
|
}
|
||
|
|
||
|
//Установка позиции
|
||
|
public void SetPosition(int x, int y)
|
||
|
{
|
||
|
if (x < 0 || x + _locoWidth > _pictureWidth)
|
||
|
{
|
||
|
x = _pictureWidth - _locoWidth;
|
||
|
}
|
||
|
if (y < 0 || y + _locoHeight > _pictureHeight)
|
||
|
{
|
||
|
y = _pictureHeight - _locoHeight;
|
||
|
}
|
||
|
_startPosX = x;
|
||
|
_startPosY = y;
|
||
|
}
|
||
|
|
||
|
public void MoveTransport(DyrectionType direction) {
|
||
|
if (EntityLocomotive == null) {
|
||
|
return;
|
||
|
}
|
||
|
switch (direction) {
|
||
|
case Left:
|
||
|
if (_startPosX - EntityLocomotive.Step() > 0) {
|
||
|
_startPosX -= (int) EntityLocomotive.Step();
|
||
|
}
|
||
|
break;
|
||
|
case Up:
|
||
|
if (_startPosY - EntityLocomotive.Step() > 0) {
|
||
|
_startPosY -= (int) EntityLocomotive.Step();
|
||
|
}
|
||
|
break;
|
||
|
case Right:
|
||
|
if (_startPosX + EntityLocomotive.Step() + _locoWidth < _pictureWidth) {
|
||
|
_startPosX += (int) EntityLocomotive.Step();
|
||
|
}
|
||
|
break;
|
||
|
case Down:
|
||
|
if (_startPosY + EntityLocomotive.Step() + _locoHeight < _pictureHeight) {
|
||
|
_startPosY += (int) EntityLocomotive.Step();
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
public void DrawTransport(Graphics g)
|
||
|
{
|
||
|
{
|
||
|
if (EntityLocomotive == null) return;
|
||
|
}
|
||
|
|
||
|
Color colorBlack = Color.BLACK;
|
||
|
/*Brush blackBrush = new SolidBrush(Color.Black);*/
|
||
|
Color windows = Color.BLUE;
|
||
|
Color bodyColor = EntityLocomotive.BodyColor;
|
||
|
|
||
|
//локомотив
|
||
|
g.setColor(bodyColor);
|
||
|
Polygon locoP = new Polygon();
|
||
|
locoP.addPoint(_startPosX, _startPosY + 40);
|
||
|
locoP.addPoint(_startPosX, _startPosY + 30);
|
||
|
locoP.addPoint(_startPosX + 20, _startPosY + 20);
|
||
|
locoP.addPoint(_startPosX + 70, _startPosY + 20);
|
||
|
locoP.addPoint(_startPosX +80, _startPosY + 30);
|
||
|
locoP.addPoint(_startPosX +80, _startPosY + 40);
|
||
|
locoP.addPoint(_startPosX +75, _startPosY + 45);
|
||
|
locoP.addPoint(_startPosX +5, _startPosY + 45);
|
||
|
locoP.addPoint(_startPosX, _startPosY + 40);
|
||
|
g.fillPolygon(locoP);
|
||
|
|
||
|
g.setColor(colorBlack);
|
||
|
/*locoP.addPoint(_startPosX, _startPosY + 40);
|
||
|
locoP.addPoint(_startPosX, _startPosY + 30);
|
||
|
locoP.addPoint(_startPosX + 20, _startPosY + 20);
|
||
|
locoP.addPoint(_startPosX + 70, _startPosY + 20);
|
||
|
locoP.addPoint(_startPosX +80, _startPosY + 30);
|
||
|
locoP.addPoint(_startPosX +80, _startPosY + 40);
|
||
|
locoP.addPoint(_startPosX +75, _startPosY + 45);
|
||
|
locoP.addPoint(_startPosX +5, _startPosY + 45);
|
||
|
locoP.addPoint(_startPosX, _startPosY + 40);*/
|
||
|
g.drawPolygon(locoP);
|
||
|
|
||
|
|
||
|
//окошки
|
||
|
Polygon window = new Polygon();
|
||
|
window.addPoint(_startPosX + 10, _startPosY + 30);
|
||
|
window.addPoint(_startPosX +15, _startPosY + 25);
|
||
|
window.addPoint(_startPosX + 20, _startPosY + 25);
|
||
|
window.addPoint(_startPosX + 20, _startPosY + 30);
|
||
|
window.addPoint(_startPosX +10, _startPosY + 30);
|
||
|
g.setColor(windows);
|
||
|
g.fillPolygon(window);
|
||
|
g.fillRect(_startPosX + 25, _startPosY + 25, 10, 5);
|
||
|
g.setColor(Color.black);
|
||
|
g.drawPolygon(window);
|
||
|
g.drawRect(_startPosX + 25, _startPosY + 25, 10, 5);
|
||
|
|
||
|
//обязательные колеса
|
||
|
//loco
|
||
|
g.fillOval(_startPosX + 10, _startPosY + 45, 5, 5);
|
||
|
g.fillOval(_startPosX + 25, _startPosY + 45, 5, 5);
|
||
|
g.fillOval(_startPosX + 50, _startPosY + 45, 5, 5);
|
||
|
g.fillOval(_startPosX + 65, _startPosY + 45, 5, 5);
|
||
|
}
|
||
|
|
||
|
public boolean CanMove(DyrectionType direction)
|
||
|
{
|
||
|
if (EntityLocomotive == null)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
switch(direction) {
|
||
|
//влево
|
||
|
case Left:
|
||
|
if (_startPosX - EntityLocomotive.Step() > 0) return true;
|
||
|
break;
|
||
|
case Up:
|
||
|
if (_startPosY - EntityLocomotive.Step() > 0) return true;
|
||
|
break;
|
||
|
case Right:
|
||
|
if (_startPosX + EntityLocomotive.Step() < _pictureWidth) return true;
|
||
|
break;
|
||
|
case Down:
|
||
|
if (_startPosY + EntityLocomotive.Step() < _pictureHeight) return true;
|
||
|
break;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
}
|