235 lines
7.9 KiB
C#
235 lines
7.9 KiB
C#
using ProjectCruiser;
|
|
using System.Drawing.Drawing2D;
|
|
|
|
namespace ProjectCruiser;
|
|
/// <summary>
|
|
/// Êëàññ, îòâå÷àþùèé çà ïðîðèñîâêó è ïåðåìåùåíèå îáúåêòà-ñóùíîñòè
|
|
/// </summary>
|
|
public class DrawningCruiser
|
|
{
|
|
/// <summary>
|
|
/// Êëàññ-ñóùíîñòü
|
|
/// </summary>
|
|
public EntityCruiser? EntityCruiser { get; private set; }
|
|
/// <summary>
|
|
/// Øèðèíà îêíà
|
|
/// </summary>
|
|
private int? _pictureWidth;
|
|
/// <summary>
|
|
/// Âûñîòà îêíà
|
|
/// </summary>
|
|
private int? _pictureHeight;
|
|
/// <summary>
|
|
/// Ëåâàÿ êîîðäèíàòà ïðîðèñîâêè àâòîìîáèëÿ
|
|
/// </summary>
|
|
private int? _startPosX;
|
|
/// <summary>
|
|
/// Âåðõíÿÿ êîîðèäíàòà ïðîðèñîâêè àâòîìîáèëÿ
|
|
/// </summary>
|
|
private int? _startPosY;
|
|
|
|
/// <summary>
|
|
/// Øèðèíà ïðîðèñîâêè àâòîìîáèëÿ
|
|
/// </summary>
|
|
private readonly int _drawningCruiserWidth = 110;
|
|
/// <summary>
|
|
/// Âûñîòà ïðîðèñîâêè àâòîìîáèëÿ
|
|
/// </summary>
|
|
private readonly int _drawningCruiserHeight = 60;
|
|
/// <summary>
|
|
/// Èíèöèàëèçàöèÿ ñâîéñòâ
|
|
/// </summary>
|
|
/// <param name="speed">Ñêîðîñòü</param>
|
|
/// <param name="weight">Âåñ</param>
|
|
/// <param name="bodyColor">Îñíîâíîé öâåò</param>
|
|
/// <param name="additionalColor">Äîïîëíèòåëüíûé öâåò</param>
|
|
/// <param name="helicopterArea">Ïðèçíàê íàëè÷èÿ îáâåñà</param>
|
|
/// <param name="boat">Ïðèçíàê íàëè÷èÿ àíòèêðûëà</param>
|
|
/// <param name="wepon">Ïðèçíàê íàëè÷èÿ ãîíî÷íîé ïîëîñû</param>
|
|
public void Init(int speed, double weight, Color bodyColor, Color
|
|
additionalColor, bool helicopterArea, bool boat, bool wepon)
|
|
{
|
|
EntityCruiser = new EntityCruiser();
|
|
EntityCruiser.Init(speed, weight, bodyColor, additionalColor,
|
|
helicopterArea, boat, wepon);
|
|
_pictureWidth = null;
|
|
_pictureHeight = null;
|
|
_startPosX = null;
|
|
_startPosY = null;
|
|
}
|
|
/// <summary>
|
|
/// Óñòàíîâêà ãðàíèö ïîëÿ
|
|
/// </summary>
|
|
/// <param name="width">Øèðèíà ïîëÿ</param>
|
|
/// <param name="height">Âûñîòà ïîëÿ</param>
|
|
/// <returns>true - ãðàíèöû çàäàíû, false - ïðîâåðêà íå ïðîéäåíà, íåëüçÿ ðàçìåñòèòü îáúåêò â ýòèõ ðàçìåðàõ</returns>
|
|
public bool SetPictureSize(int width, int height)
|
|
{
|
|
// TODO ïðîâåðêà, ÷òî îáúåêò "âëåçàåò" â ðàçìåðû ïîëÿ
|
|
// åñëè âëåçàåò, ñîõðàíÿåì ãðàíèöû è êîððåêòèðóåì ïîçèöèþ îáúåêòà,åñëè îíà áûëà óæå óñòàíîâëåíà
|
|
|
|
if (_startPosX + 150 > width)
|
|
{
|
|
_startPosX -= (_startPosX + 150) - width;
|
|
}
|
|
if (_startPosY + 80 > height)
|
|
{
|
|
_startPosY -= (_startPosY + 80) - height;
|
|
}
|
|
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
return true;
|
|
}
|
|
/// <summary>
|
|
/// Óñòàíîâêà ïîçèöèè
|
|
/// </summary>
|
|
/// <param name="x">Êîîðäèíàòà X</param>
|
|
/// <param name="y">Êîîðäèíàòà Y</param>
|
|
public void SetPosition(int x, int y)
|
|
{
|
|
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if(x + 150 > _pictureWidth)
|
|
{
|
|
x -= (x+150) - _pictureWidth.Value;
|
|
}
|
|
|
|
if (y + 50 > _pictureHeight)
|
|
{
|
|
y -= (y+50) - _pictureHeight.Value;
|
|
}
|
|
// TODO åñëè ïðè óñòàíîâêå îáúåêòà â ýòè êîîðäèíàòû, îí áóäåò "âûõîäèòü" çà ãðàíèöû ôîðìû
|
|
// òî íàäî èçìåíèòü êîîðäèíàòû, ÷òîáû îí îñòàâàëñÿ â ýòèõ ãðàíèöàõ
|
|
|
|
_startPosX = x;
|
|
_startPosY = y;
|
|
|
|
|
|
|
|
}
|
|
/// <summary>
|
|
/// Èçìåíåíèå íàïðàâëåíèÿ ïåðåìåùåíèÿ
|
|
/// </summary>
|
|
/// <param name="direction">Íàïðàâëåíèå</param>
|
|
/// <returns>true - ïåðåìåùåíå âûïîëíåíî, false - ïåðåìåùåíèå íåâîçìîæíî</returns>
|
|
public bool MoveTransport(DirectionType direction)
|
|
{
|
|
if (EntityCruiser == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
|
{
|
|
return false;
|
|
}
|
|
switch (direction)
|
|
{
|
|
//âëåâî
|
|
case DirectionType.Left:
|
|
if (_startPosX.Value - EntityCruiser.Step > 0)
|
|
{
|
|
_startPosX -= (int)EntityCruiser.Step;
|
|
}
|
|
|
|
return true;
|
|
//ââåðõ
|
|
case DirectionType.Up:
|
|
if (_startPosY.Value - EntityCruiser.Step > 0)
|
|
{
|
|
_startPosY -= (int)EntityCruiser.Step;
|
|
}
|
|
return true;
|
|
// âïðàâî
|
|
case DirectionType.Right:
|
|
if (_startPosX.Value >= 640)
|
|
{
|
|
return true;
|
|
}
|
|
//TODO ïðîïèñàòü ëîãèêó ñäâèãà â ïðàâî
|
|
if (_startPosX.Value + EntityCruiser.Step > 0)
|
|
{
|
|
_startPosX += (int)EntityCruiser.Step;
|
|
}
|
|
return true;
|
|
//âíèç
|
|
case DirectionType.Down:
|
|
//TODO ïðîïèñàòü ëîãèêó ñäâèãà â âíèç
|
|
if(_startPosY.Value >= 390)
|
|
{
|
|
return true;
|
|
}
|
|
if (_startPosY.Value + EntityCruiser.Step > 0)
|
|
{
|
|
_startPosY += (int)EntityCruiser.Step;
|
|
}
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Ïðîðèñîâêà îáúåêòà
|
|
/// </summary>
|
|
/// <param name="g"></param>
|
|
public void DrawTransport(Graphics g)
|
|
{
|
|
if (EntityCruiser == null || !_startPosX.HasValue ||
|
|
!_startPosY.HasValue)
|
|
{
|
|
return;
|
|
}
|
|
Pen pen = new(Color.Black, 2);
|
|
Brush additionalBrush = new SolidBrush(Color.Black);
|
|
Brush weaponBrush = new SolidBrush(Color.Black);
|
|
Brush weaponBrush2 = new SolidBrush(EntityCruiser.AdditionalColor);
|
|
Brush helicopterAreaBrush = new HatchBrush(HatchStyle.ZigZag, EntityCruiser.AdditionalColor, Color.FromArgb(163, 163, 163));
|
|
Brush boatBrush = new SolidBrush(EntityCruiser.AdditionalColor);
|
|
|
|
//ãðàíèöû êðóèñåðà
|
|
|
|
g.DrawLine(pen, _startPosX.Value, _startPosY.Value, _startPosX.Value + 105, _startPosY.Value);
|
|
g.DrawLine(pen, _startPosX.Value + 105, _startPosY.Value, _startPosX.Value + 147, _startPosY.Value + 24);
|
|
|
|
g.DrawLine(pen, _startPosX.Value, _startPosY.Value + 49, _startPosX.Value + 105, _startPosY.Value + 49);
|
|
g.DrawLine(pen, _startPosX.Value + 105, _startPosY.Value + 49, _startPosX.Value + 147, _startPosY.Value + 24);
|
|
|
|
g.DrawLine(pen, _startPosX.Value, _startPosY.Value, _startPosX.Value, _startPosY.Value + 49);
|
|
|
|
//âíóòðåííîñòè êðóèñåðà
|
|
g.DrawEllipse(pen, _startPosX.Value + 94, _startPosY.Value + 14, 19, 19);
|
|
|
|
g.DrawRectangle(pen, _startPosX.Value + 63, _startPosY.Value + 11, 21, 28);
|
|
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 17, 28, 14);
|
|
|
|
//çàä
|
|
g.FillRectangle(additionalBrush, _startPosX.Value - 3, _startPosY.Value + 7, 3, 14);
|
|
g.FillRectangle(additionalBrush, _startPosX.Value - 3, _startPosY.Value + 26, 3, 14);
|
|
|
|
if (EntityCruiser.HelicopterArea)
|
|
{
|
|
g.FillEllipse(helicopterAreaBrush, _startPosX.Value + 5, _startPosY.Value + 9, 25, 30);
|
|
g.DrawEllipse(pen, _startPosX.Value + 5, _startPosY.Value + 9, 25, 30);
|
|
}
|
|
|
|
if (EntityCruiser.Boat)
|
|
{
|
|
g.DrawEllipse(pen, _startPosX.Value + 34, _startPosY.Value + 2, 30, 7);
|
|
g.FillEllipse(boatBrush, _startPosX.Value + 34, _startPosY.Value + 2, 30, 7);
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 34, _startPosY.Value + 39, 30, 7);
|
|
g.FillEllipse(boatBrush, _startPosX.Value + 34, _startPosY.Value + 39, 30, 7);
|
|
}
|
|
|
|
if (EntityCruiser.Weapon)
|
|
{
|
|
g.DrawEllipse(pen, _startPosX.Value + 97, _startPosY.Value + 36, 10, 10);
|
|
g.FillEllipse(weaponBrush2, _startPosX.Value + 97, _startPosY.Value + 36, 10, 10);
|
|
|
|
|
|
g.FillRectangle(weaponBrush, _startPosX.Value + 107, _startPosY.Value + 40, 15, 5);
|
|
|
|
|
|
}
|
|
|
|
}
|
|
} |