Закончил делать лабораторную

This commit is contained in:
Shtyrkin_Egor 2024-03-18 11:30:02 +04:00
parent 92db26edc6
commit f504666346
2 changed files with 139 additions and 9 deletions

View File

@ -18,9 +18,9 @@ public class DrawningAircraftCarrier
private int? _startPosY;
private readonly int _drawningAircraftCarrierWidth = 110;
private readonly int _drawningAircraftCarrierWidth = 150;
private readonly int _drawningAircraftCarrierHeight = 60;
private readonly int _drawningAircraftCarrierHeight = 65;
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool aircraftDeck, bool controlRoom)
{
@ -34,9 +34,34 @@ public class DrawningAircraftCarrier
public bool SetPictureSize(int width, int height)
{
if (width < _drawningAircraftCarrierWidth || height < _drawningAircraftCarrierHeight)
{
return false;
}
_pictureWidth = width;
_pictureHeight = height;
if (_startPosX != null || _startPosY != null)
{
if (_startPosX + _drawningAircraftCarrierWidth > _pictureWidth)
{
_startPosX = -_drawningAircraftCarrierWidth + _pictureWidth;
}
else if (_startPosX < 0)
{
_startPosX = 0;
}
if (_startPosY + _drawningAircraftCarrierHeight > _pictureHeight)
{
_startPosY = -_drawningAircraftCarrierHeight + _pictureHeight;
}
else if (_startPosY < 0)
{
_startPosY = 0;
}
}
return true;
}
public void SetPosition(int x, int y)
@ -46,9 +71,18 @@ public class DrawningAircraftCarrier
return;
}
if(x < 0 || x + _drawningAircraftCarrierWidth > _pictureWidth)
{
x = 0;
}
if(y < 0 || y + _drawningAircraftCarrierHeight > _pictureHeight)
{
y = 0;
}
_startPosX = x;
_startPosY = y;
}
public bool MoveTransport(DirectionType direction)
@ -61,25 +95,25 @@ public class DrawningAircraftCarrier
switch (direction)
{
case DirectionType.Left:
if (_startPosX - EntityAircraftCarrier.Step > 0)
if (_startPosX.Value - EntityAircraftCarrier.Step > 0)
{
_startPosX -= (int)EntityAircraftCarrier.Step;
}
return true;
case DirectionType.Up:
if (_startPosY - EntityAircraftCarrier.Step > 0)
if (_startPosY.Value - EntityAircraftCarrier.Step > 0)
{
_startPosY -= (int)EntityAircraftCarrier.Step;
}
return true;
case DirectionType.Right:
if (_startPosX + EntityAircraftCarrier.Step < _pictureWidth)
if (_startPosX.Value + _drawningAircraftCarrierWidth + EntityAircraftCarrier.Step < _pictureWidth)
{
_startPosX += (int)EntityAircraftCarrier.Step;
}
return true;
case DirectionType.Down:
if (_startPosY + EntityAircraftCarrier.Step < _pictureHeight)
if (_startPosY.Value + _drawningAircraftCarrierHeight + EntityAircraftCarrier.Step < _pictureHeight)
{
_startPosY += (int)EntityAircraftCarrier.Step;
}
@ -99,9 +133,72 @@ public class DrawningAircraftCarrier
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(EntityAircraftCarrier.AdditionalColor);
//границы авианосца
Point[] FramePoints = {
new Point(_startPosX.Value + 10, _startPosY.Value + 10),
new Point(_startPosX.Value + 110, _startPosY.Value + 10),
new Point(_startPosX.Value + 149, _startPosY.Value + 35),
new Point(_startPosX.Value + 110, _startPosY.Value + 60),
new Point(_startPosX.Value + 10, _startPosY.Value + 60),
};
g.DrawPolygon(pen, FramePoints);
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 15, 5, 18);
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 37, 5, 18);
//корпус авианосца
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 10, 70, 30);
Brush br = new SolidBrush(EntityAircraftCarrier.BodyColor);
g.FillPolygon(br, FramePoints);
//отсеки авианосца
Brush brGray = new SolidBrush(Color.Gray);
g.FillRectangle(brGray, _startPosX.Value + 85, _startPosY.Value + 20, 15, 30);
g.FillRectangle(brGray, _startPosX.Value + 65, _startPosY.Value + 30, 20, 10);
g.FillEllipse(brGray, _startPosX.Value + 105, _startPosY.Value + 24, 20, 20);
//выделяем рамкой отсеки авианосца
g.DrawRectangle(pen, _startPosX.Value + 85, _startPosY.Value + 20, 15, 30);
g.DrawRectangle(pen, _startPosX.Value + 65, _startPosY.Value + 30, 20, 10);
g.DrawEllipse(pen, _startPosX.Value + 105, _startPosY.Value + 24, 20, 20);
//двигатели авианосца
Brush brBlack = new SolidBrush(Color.Black);
g.FillRectangle(brBlack, _startPosX.Value + 5, _startPosY.Value + 15, 5, 18);
g.FillRectangle(brBlack, _startPosX.Value + 5, _startPosY.Value + 37, 5, 18);
//рубка управления
if (EntityAircraftCarrier.ControlRoom)
{
g.FillRectangle(additionalBrush, _startPosX.Value + 40, _startPosY.Value + 52, 15, 15);
g.FillRectangle(additionalBrush, _startPosX.Value + 70, _startPosY.Value + 52, 15, 15);
g.FillRectangle(additionalBrush, _startPosX.Value + 55, _startPosY.Value + 56, 15, 7);
g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 56, 5, 7);
g.FillRectangle(additionalBrush, _startPosX.Value + 85, _startPosY.Value + 56, 5, 7);
g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value + 52, 15, 15);
g.DrawRectangle(pen, _startPosX.Value + 70, _startPosY.Value + 52, 15, 15);
g.DrawRectangle(pen, _startPosX.Value + 55, _startPosY.Value + 56, 15, 7);
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 56, 5, 7);
g.DrawRectangle(pen, _startPosX.Value + 85, _startPosY.Value + 56, 5, 7);
g.DrawRectangle(pen, _startPosX.Value + 44, _startPosY.Value + 56, 7, 7);
g.DrawRectangle(pen, _startPosX.Value + 74, _startPosY.Value + 56, 7, 7);
}
//палуба для взлёта самолётов
if (EntityAircraftCarrier.AircraftDeck)
{
Point[] DeckPoint =
{
new Point(_startPosX.Value + 10, _startPosY.Value + 35),
new Point(_startPosX.Value + 10, _startPosY.Value + 55),
new Point(_startPosX.Value + 55, _startPosY.Value + 30),
new Point(_startPosX.Value + 55, _startPosY.Value + 10),
};
g.FillPolygon(additionalBrush, DeckPoint);
g.DrawPolygon(pen, DeckPoint);
g.DrawLine(pen, _startPosX.Value + 10, _startPosY.Value + 45, _startPosX.Value + 55, _startPosY.Value + 20);
}
}
}

View File

@ -6,22 +6,55 @@ using System.Threading.Tasks;
namespace ProjectAircraftCarrier;
/// <summary>
///
/// </summary>
public class EntityAircraftCarrier
{
/// <summary>
///
/// </summary>
public int Speed { get; private set; }
/// <summary>
///
/// </summary>
public double Weight { get; private set; }
/// <summary>
///
/// </summary>
public Color BodyColor { get; private set; }
/// <summary>
///
/// </summary>
public Color AdditionalColor { get; private set; }
/// <summary>
///
/// </summary>
public bool AircraftDeck { get; private set; }
/// <summary>
///
/// </summary>
public bool ControlRoom { get; private set; }
/// <summary>
///
/// </summary>
public double Step => Speed * 100 / Weight;
/// <summary>
///
/// </summary>
/// <param name="speed"></param>
/// <param name="weight"></param>
/// <param name="bodyColor"></param>
/// <param name="additionalColor"></param>
/// <param name="aircraftDeck"></param>
/// <param name="controlRoom"></param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool aircraftDeck, bool controlRoom)
{
Speed = speed;