128 lines
3.7 KiB
Java
128 lines
3.7 KiB
Java
import java.awt.*;
|
|
import javax.swing.*;
|
|
import java.awt.event.*;
|
|
import java.util.Random;
|
|
import java.util.Timer;
|
|
import java.util.TimerTask;
|
|
import java.io.*;
|
|
import java.util.Scanner;
|
|
import java.util.Stack;
|
|
|
|
|
|
|
|
public class DrawningBoat {
|
|
private EntityBoat Boat;
|
|
public EntityBoat Boat() {
|
|
return Boat;
|
|
}
|
|
|
|
private float _startPosX;
|
|
public float get_startPosX() {
|
|
return _startPosX;
|
|
}
|
|
|
|
private float _startPosY;
|
|
public float get_startPosY() {
|
|
return _startPosY;
|
|
}
|
|
|
|
private int _pictureWidth;
|
|
|
|
private int _pictureHeight;
|
|
|
|
private int _boatWidth = 170;
|
|
public int get_boatWidth() {
|
|
return _boatWidth;
|
|
}
|
|
|
|
private int _boatHeight = 60;
|
|
public int get_boatHeight() {
|
|
return _boatHeight;
|
|
}
|
|
|
|
public void Init(int speed, float weight, Color bodyColor)
|
|
{
|
|
Boat = new EntityBoat();
|
|
Boat.Init(speed, weight, bodyColor);
|
|
}
|
|
|
|
public void SetPosition(int x, int y, int width, int height) {
|
|
if (x + _boatWidth <= width && y + _boatHeight <= height && x > 0 && y > 0)
|
|
{
|
|
_startPosX = x;
|
|
_startPosY = y;
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
}
|
|
}
|
|
|
|
public void MoveTransport(Direction direction) {
|
|
try {
|
|
Integer.valueOf(_pictureWidth);
|
|
Integer.valueOf(_pictureHeight);
|
|
} catch (Exception e) {
|
|
return;
|
|
}
|
|
switch (direction)
|
|
{
|
|
// вправо
|
|
case Right:
|
|
if (_startPosX + _boatWidth + Boat.Step < _pictureWidth)
|
|
{
|
|
_startPosX += Boat.Step;
|
|
}
|
|
break;
|
|
//влево
|
|
case Left:
|
|
if (_startPosX - Boat.Step > 0)
|
|
{
|
|
_startPosX -= Boat.Step;
|
|
}
|
|
break;
|
|
//вверх
|
|
case Up:
|
|
if (_startPosY - Boat.Step > 0)
|
|
{
|
|
_startPosY -= Boat.Step;
|
|
}
|
|
break;
|
|
//вниз
|
|
case Down:
|
|
if (_startPosY + _boatHeight + Boat.Step < _pictureHeight)
|
|
{
|
|
_startPosY += Boat.Step;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void DrawTransport(Graphics g) {
|
|
if (_startPosX < 0 || _startPosY < 0) {
|
|
return;
|
|
}
|
|
try {
|
|
Integer.valueOf(_pictureWidth);
|
|
Integer.valueOf(_pictureHeight);
|
|
} catch (Exception e) {
|
|
return;
|
|
}
|
|
Pen pen = new(Color.Black, 3);
|
|
Brush br = new SolidBrush(Boat?.BodyColor ?? Color.Black);
|
|
Brush brBrown = new SolidBrush(Color.Brown);
|
|
// Внешняя часть лодки
|
|
g.DrawLine(pen, _startPosX, _startPosY, _startPosX + 120, _startPosY + 0);
|
|
g.DrawLine(pen, _startPosX + 120, _startPosY, _startPosX + 170, _startPosY + 30);
|
|
g.DrawLine(pen, _startPosX + 170, _startPosY + 30, _startPosX + 120, _startPosY + 60);
|
|
g.DrawLine(pen, _startPosX + 120, _startPosY + 60, _startPosX, _startPosY + 60);
|
|
g.DrawLine(pen, _startPosX, _startPosY + 60, _startPosX, _startPosY);
|
|
PointF pt1 = new PointF(_startPosX, _startPosY);
|
|
PointF pt2 = new PointF(_startPosX + 120, _startPosY);
|
|
PointF pt3 = new PointF(_startPosX + 170, _startPosY + 30);
|
|
PointF pt4 = new PointF(_startPosX + 120, _startPosY + 60);
|
|
PointF pt5 = new PointF(_startPosX, _startPosY + 60);
|
|
g.FillPolygon(br, new PointF[] { pt1, pt2, pt3, pt4, pt5});
|
|
// Внутренняя часть лодки
|
|
g.FillEllipse(brBrown, _startPosX + 10, _startPosY + 10, 110, 40);
|
|
}
|
|
}
|