Лабараторная работа №2 2

This commit is contained in:
IlyasValiulov 2024-02-19 15:29:36 +04:00
parent 75a051074f
commit 0619b0de35
5 changed files with 14 additions and 32 deletions

View File

@ -8,27 +8,22 @@ public class DrawningShip
/// Класс-сущность /// Класс-сущность
/// </summary> /// </summary>
public EntityShip? EntityShip { get; protected set; } public EntityShip? EntityShip { get; protected set; }
/// <summary> /// <summary>
/// Ширина окна /// Ширина окна
/// </summary> /// </summary>
private int? _pictureWidth; private int? _pictureWidth;
/// <summary> /// <summary>
/// Высота окна /// Высота окна
/// </summary> /// </summary>
private int? _pictureHeight; private int? _pictureHeight;
/// <summary> /// <summary>
/// Левая координата прорисовки /// Левая координата прорисовки
/// </summary> /// </summary>
protected int? _startPosX; protected int? _startPosX;
/// <summary> /// <summary>
/// Верхняя кооридната прорисовки /// Верхняя кооридната прорисовки
/// </summary> /// </summary>
protected int? _startPosY; protected int? _startPosY;
/// <summary> /// <summary>
/// Ширина прорисовки /// Ширина прорисовки
/// </summary> /// </summary>

View File

@ -4,10 +4,6 @@ namespace ProjectWarmlyShip.Drawnings;
public class DrawningWarmlyShip : DrawningShip public class DrawningWarmlyShip : DrawningShip
{ {
/// <summary>
/// Класс-сущность
/// </summary>
public EntityWarmlyShip? EntityWarmlyShip { get; private set; }
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
@ -36,15 +32,8 @@ public class DrawningWarmlyShip : DrawningShip
base.DrawTransport(g); base.DrawTransport(g);
if (warmlyship.FuelTank) if (warmlyship.FuelTank)
{ {
//if (EntityWarmlyShip.ShipPipes)
//{
// g.FillRectangle(brush, _startPosX.Value + 40, _startPosY.Value + 120, 70, 10);
//}
//else
// g.FillRectangle(brush, _startPosX.Value + 40, _startPosY.Value + 60, 70, 10);
g.FillRectangle(brush, _startPosX.Value + 40, _startPosY.Value + 60, 70, 10); g.FillRectangle(brush, _startPosX.Value + 40, _startPosY.Value + 60, 70, 10);
} }
if (warmlyship.ShipPipes) _startPosY -= 60; if (warmlyship.ShipPipes) _startPosY -= 60;
} }
} }

View File

@ -12,6 +12,17 @@ namespace ProjectWarmlyShip
InitializeComponent(); InitializeComponent();
_strategy = null; _strategy = null;
} }
private void Draw()
{
if (_drawningShip == null)
{
return;
}
Bitmap bmp = new(pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningShip.DrawTransport(gr);
pictureBoxWarmlyShip.Image = bmp;
}
private void CreateObject(string type) private void CreateObject(string type)
{ {
Random random = new Random(); Random random = new Random();
@ -34,11 +45,7 @@ namespace ProjectWarmlyShip
_drawningShip.SetPosition(random.Next(10, 100), random.Next(10, 100)); _drawningShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
_strategy = null; _strategy = null;
comboBoxStrategy.Enabled = true; comboBoxStrategy.Enabled = true;
Bitmap bmp = new(pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height); Draw();
Graphics gr = Graphics.FromImage(bmp);
_drawningShip.DrawTransport(gr);
pictureBoxWarmlyShip.Image = bmp;
} }
/// <summary> /// <summary>
/// Кнопка создания теплохода /// Кнопка создания теплохода
@ -83,10 +90,7 @@ namespace ProjectWarmlyShip
} }
if (result) if (result)
{ {
Bitmap bmp = new(pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height); Draw();
Graphics gr = Graphics.FromImage(bmp);
_drawningShip.DrawTransport(gr);
pictureBoxWarmlyShip.Image = bmp;
} }
} }
private void buttonStrategyStep_Click(object sender, EventArgs e) private void buttonStrategyStep_Click(object sender, EventArgs e)
@ -116,10 +120,7 @@ namespace ProjectWarmlyShip
} }
comboBoxStrategy.Enabled = false; comboBoxStrategy.Enabled = false;
_strategy.MakeStep(); _strategy.MakeStep();
Bitmap bmp = new(pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height); Draw();
Graphics gr = Graphics.FromImage(bmp);
_drawningShip.DrawTransport(gr);
pictureBoxWarmlyShip.Image = bmp;
if (_strategy.GetStatus == StrategyStatus.Finish) if (_strategy.GetStatus == StrategyStatus.Finish)
{ {
comboBoxStrategy.Enabled = true; comboBoxStrategy.Enabled = true;
@ -127,5 +128,4 @@ namespace ProjectWarmlyShip
} }
} }
} }
} }

View File

@ -2,7 +2,6 @@
public interface IMoveableObjects public interface IMoveableObjects
{ {
//Получение координаты обхекта
ObjectParameters? GetObjectPosition { get; } ObjectParameters? GetObjectPosition { get; }
/// <summary> /// <summary>
/// Шаг объекта /// Шаг объекта

View File

@ -45,5 +45,4 @@ public class MoveableShip : IMoveableObjects
_ => DirectionType.Unknow, _ => DirectionType.Unknow,
}; };
} }
} }