126 lines
4.7 KiB
C#
126 lines
4.7 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace AirplaneWithRadar
|
||
{
|
||
internal class DrawingAirplaneWithRadar
|
||
{
|
||
public EntityAirplaneWithRadar AirplaneWithRadar { get; private set; }
|
||
private float _startPosX;
|
||
private float _startPosY;
|
||
private int? _pictureWidth = null;
|
||
private int? _pictureHeight = null;
|
||
private readonly int _airplaneWithRadarWidth = 50;
|
||
private readonly int _airplaneWithRadarHeight = 27;
|
||
public void Init(int speed, float weight, Color bodyColor)
|
||
{
|
||
AirplaneWithRadar = new EntityAirplaneWithRadar();
|
||
AirplaneWithRadar.Init(speed, weight, bodyColor);
|
||
}
|
||
public void SetPosition(int x, int y, int width, int height)
|
||
{
|
||
if (x + _airplaneWithRadarWidth <= width && y + _airplaneWithRadarHeight <= height && x >= 0 && y >= 0)
|
||
{
|
||
_startPosX = x;
|
||
_startPosY = y;
|
||
_pictureWidth = width;
|
||
_pictureHeight = height;
|
||
}
|
||
}
|
||
public void MoveTransport(Direction direction)
|
||
{
|
||
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
|
||
{
|
||
return;
|
||
}
|
||
switch (direction)
|
||
{
|
||
// вправо
|
||
case Direction.Right:
|
||
if (_startPosX + _airplaneWithRadarWidth + AirplaneWithRadar.Step < _pictureWidth)
|
||
{
|
||
_startPosX += AirplaneWithRadar.Step;
|
||
}
|
||
break;
|
||
//влево
|
||
case Direction.Left:
|
||
if (_startPosX - AirplaneWithRadar.Step > 0)
|
||
{
|
||
_startPosX -= AirplaneWithRadar.Step;
|
||
}
|
||
break;
|
||
//вверх
|
||
case Direction.Up:
|
||
if (_startPosY - AirplaneWithRadar.Step > 0)
|
||
{
|
||
_startPosY -= AirplaneWithRadar.Step;
|
||
}
|
||
break;
|
||
//вниз
|
||
case Direction.Down:
|
||
if (_startPosY + _airplaneWithRadarHeight + AirplaneWithRadar.Step + 30 < _pictureHeight)
|
||
{
|
||
_startPosY += AirplaneWithRadar.Step;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
public void DrawTransport(Graphics g)
|
||
{
|
||
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||
{
|
||
return;
|
||
}
|
||
|
||
Pen pen = new(Color.Black);
|
||
|
||
// Корпус
|
||
g.DrawRectangle(pen, _startPosX, _startPosY + 10, 40, 10);
|
||
|
||
// Окно
|
||
Brush darkBrush = new SolidBrush(AirplaneWithRadar?.BodyColor ?? Color.Black);
|
||
g.FillRectangle(darkBrush, _startPosX + 12, _startPosY + 13, 20, 2);
|
||
|
||
// Хвост
|
||
darkBrush = new SolidBrush(Color.Black);
|
||
g.DrawLine(pen, _startPosX, _startPosY + 12, _startPosX, _startPosY);
|
||
g.DrawLine(pen, _startPosX, _startPosY, _startPosX + 10, _startPosY + 10);
|
||
|
||
// Заднее шасси
|
||
g.FillRectangle(darkBrush, _startPosX + 10, _startPosY + 21, 2, 2);
|
||
g.FillRectangle(darkBrush, _startPosX + 13, _startPosY + 23, 4, 4);
|
||
g.FillRectangle(darkBrush, _startPosX + 8, _startPosY + 23, 2, 4);
|
||
|
||
// Переднее шасси
|
||
g.FillRectangle(darkBrush, _startPosX + 35, _startPosY + 21, 2, 2);
|
||
g.FillRectangle(darkBrush, _startPosX + 35, _startPosY + 23, 4, 4);
|
||
|
||
// Нос
|
||
g.DrawLine(pen, _startPosX + 40, _startPosY + 10, _startPosX + 47, _startPosY + 15);
|
||
g.DrawLine(pen, _startPosX + 40, _startPosY + 20, _startPosX + 50, _startPosY + 15);
|
||
}
|
||
public void ChangeBorders(int width, int height)
|
||
{
|
||
_pictureWidth = width;
|
||
_pictureHeight = height;
|
||
if (_pictureWidth <= _airplaneWithRadarWidth || _pictureHeight <= _airplaneWithRadarHeight)
|
||
{
|
||
_pictureWidth = null;
|
||
_pictureHeight = null;
|
||
return;
|
||
}
|
||
if (_startPosX + _airplaneWithRadarWidth > _pictureWidth)
|
||
{
|
||
_startPosX = _pictureWidth.Value - _airplaneWithRadarWidth;
|
||
}
|
||
if (_startPosY + _airplaneWithRadarHeight > _pictureHeight)
|
||
{
|
||
_startPosY = _pictureHeight.Value - _airplaneWithRadarHeight;
|
||
}
|
||
}
|
||
}
|
||
}
|