Добавление родитлей и ввод конструкторов

This commit is contained in:
кристина лаврова 2024-04-24 09:28:37 +04:00
parent ae4870fe45
commit c2e17f58db
8 changed files with 524 additions and 333 deletions

View File

@ -1,241 +0,0 @@
namespace lab1;
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawningEntityFighter
{
/// <summary>
/// Класс-сущность
/// </summary>
public EntityFighter? EntityFighter { 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 _drawningFighterWidth = 91;
/// <summary>
/// Высота прорисовки истребителя
/// </summary>
private readonly int _drawningFighterHeight = 65;
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">>Вес истребителя</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="rockets">Признак наличия ракет</param>
/// <param name="extraWings">Признак наличия доп. крыльев</param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool rockets, bool extraWings)
{
EntityFighter = new EntityFighter();
EntityFighter.Init(speed, weight, bodyColor, additionalColor, rockets, extraWings);
_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)
{
if (width >= _drawningFighterWidth && height >= _drawningFighterHeight)
{
_pictureWidth = width;
_pictureHeight = height;
if (_startPosX.HasValue && _startPosY.HasValue)
{
SetPosition(_startPosX.Value, _startPosY.Value);
}
return true;
}
return false;
}
/// <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 < 0)
{
x = 0;
}
else if (x > _pictureWidth.Value - _drawningFighterWidth)
{
x = _pictureWidth.Value - _drawningFighterWidth;
}
if (y < 0)
{
y = 0;
}
else if (y > _pictureHeight.Value - _drawningFighterHeight)
{
y = _pictureHeight.Value - _drawningFighterHeight;
}
_startPosX = x;
_startPosY = y;
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
public bool MoveTransport(DirectionType direction)
{
if (EntityFighter == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return false;
}
switch (direction)
{
//влево
case DirectionType.Left:
if (_startPosX.Value - EntityFighter.Step > 0)
{
_startPosX -= (int)EntityFighter.Step;
}
return true;
//Вверх
case DirectionType.Up:
if (_startPosY.Value - EntityFighter.Step > 0)
{
_startPosY -= (int)EntityFighter.Step;
}
return true;
//Вправо
case DirectionType.Right:
if (_startPosX.Value + EntityFighter.Step + _drawningFighterWidth < _pictureWidth)
{
_startPosX += (int)EntityFighter.Step;
}
return true;
//Вниз
case DirectionType.Down:
if (_startPosY.Value + EntityFighter.Step + _drawningFighterHeight < _pictureHeight)
{
_startPosY += (int)EntityFighter.Step;
}
return true;
default:
return false;
}
}
/// <summary>
/// Прорисовка объекта
/// </summary>
/// <param name="g"></param>
public void DrawTransport(Graphics g)
{
if (EntityFighter == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(EntityFighter.AdditionalColor);
Brush BodyBrush = new SolidBrush(EntityFighter.BodyColor);
Brush CraneBrush = new SolidBrush(EntityFighter.AdditionalColor);
//корпус
g.FillRectangle(BodyBrush, _startPosX.Value + 10, _startPosY.Value + 30, 62, 12);
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 30, 62, 12);
g.FillRectangle(BodyBrush, _startPosX.Value + 22, _startPosY.Value + 16, 4, 15);
g.DrawRectangle(pen, _startPosX.Value + 22, _startPosY.Value + 16, 4, 14);
g.FillRectangle(BodyBrush, _startPosX.Value + 37, _startPosY.Value + 1, 5, 30);
g.DrawRectangle(pen, _startPosX.Value + 37, _startPosY.Value + 1, 5, 30);
//стекло
g.FillRectangle(additionalBrush, _startPosX.Value + 52, _startPosY.Value + 14, 21, 16);
g.DrawRectangle(pen, _startPosX.Value + 52, _startPosY.Value + 14, 20, 16);
//гусеницы
g.DrawLine(pen, _startPosX.Value + 8, _startPosY.Value + 42, _startPosX.Value + 10, _startPosY.Value + 42);
g.DrawLine(pen, _startPosX.Value + 7, _startPosY.Value + 43, _startPosX.Value + 7, _startPosY.Value + 53);
g.DrawLine(pen, _startPosX.Value + 8, _startPosY.Value + 54, _startPosX.Value + 12, _startPosY.Value + 54);
g.DrawLine(pen, _startPosX.Value + 13, _startPosY.Value + 55, _startPosX.Value + 69, _startPosY.Value + 55);
g.DrawLine(pen, _startPosX.Value + 70, _startPosY.Value + 54, _startPosX.Value + 73, _startPosY.Value + 54);
g.DrawLine(pen, _startPosX.Value + 74, _startPosY.Value + 53, _startPosX.Value + 74, _startPosY.Value + 43);
g.DrawLine(pen, _startPosX.Value + 71, _startPosY.Value + 42, _startPosX.Value + 73, _startPosY.Value + 42);
//колеса
g.FillEllipse(BodyBrush, _startPosX.Value + 10, _startPosY.Value + 44, 9, 9);
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 44, 9, 9);
g.FillEllipse(BodyBrush, _startPosX.Value + 63, _startPosY.Value + 44, 9, 9);
g.DrawEllipse(pen, _startPosX.Value + 63, _startPosY.Value + 44, 9, 9);
g.FillEllipse(BodyBrush, _startPosX.Value + 25, _startPosY.Value + 48, 6, 6);
g.DrawEllipse(pen, _startPosX.Value + 25, _startPosY.Value + 48, 6, 6);
g.FillEllipse(BodyBrush, _startPosX.Value + 38, _startPosY.Value + 48, 6, 6);
g.DrawEllipse(pen, _startPosX.Value + 38, _startPosY.Value + 48, 6, 6);
g.FillEllipse(BodyBrush, _startPosX.Value + 50, _startPosY.Value + 48, 6, 6);
g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 48, 6, 6);
g.FillEllipse(BodyBrush, _startPosX.Value + 33, _startPosY.Value + 44, 4, 4);
g.DrawEllipse(pen, _startPosX.Value + 33, _startPosY.Value + 44, 4, 4);
g.FillEllipse(BodyBrush, _startPosX.Value + 45, _startPosY.Value + 44, 4, 4);
g.DrawEllipse(pen, _startPosX.Value + 45, _startPosY.Value + 44, 4, 4);
if (EntityFighter.Kovsh)
{
//ковш
g.DrawRectangle(pen, _startPosX.Value - 2, _startPosY.Value + 37, 8, 15);
g.FillRectangle(CraneBrush, _startPosX.Value - 2, _startPosY.Value + 37, 8, 15);
g.DrawRectangle(pen, _startPosX.Value - -6, _startPosY.Value + 37, 4, 1);
}
//противовес
if (EntityFighter.Otval)
{
g.DrawRectangle(pen, _startPosX.Value + 73, _startPosY.Value + 37, 17, 1);
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 37, 1, 17);
}
}
}

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace lab1;
namespace lab1.Drawnings;
public enum DirectionType
{

View File

@ -0,0 +1,104 @@
using lab1.Entities;
namespace lab1.Drawnings;
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawningEntityFighter : DrawningTrackedVehicle
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">>Вес истребителя</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="rockets">Признак наличия ракет</param>
/// <param name="extraWings">Признак наличия доп. крыльев</param>
public DrawningEntityFighter(int speed, double weight, Color bodyColor, Color additionalColor, bool rockets, bool extraWings) : base (91, 65)
{
EntityTrackedVehicle = new EntityFighter(speed, weight, bodyColor, additionalColor, rockets, extraWings);
}
public override void DrawTransport(Graphics g)
{
if (EntityTrackedVehicle == null || EntityTrackedVehicle is not EntityFighter fighter || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(fighter.AdditionalColor);
Brush BodyBrush = new SolidBrush(fighter.BodyColor);
Brush CraneBrush = new SolidBrush(fighter.AdditionalColor);
//корпус
g.FillRectangle(BodyBrush, _startPosX.Value + 10, _startPosY.Value + 30, 62, 12);
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 30, 62, 12);
g.FillRectangle(BodyBrush, _startPosX.Value + 22, _startPosY.Value + 16, 4, 15);
g.DrawRectangle(pen, _startPosX.Value + 22, _startPosY.Value + 16, 4, 14);
g.FillRectangle(BodyBrush, _startPosX.Value + 37, _startPosY.Value + 1, 5, 30);
g.DrawRectangle(pen, _startPosX.Value + 37, _startPosY.Value + 1, 5, 30);
//стекло
g.FillRectangle(additionalBrush, _startPosX.Value + 52, _startPosY.Value + 14, 21, 16);
g.DrawRectangle(pen, _startPosX.Value + 52, _startPosY.Value + 14, 20, 16);
//гусеницы
g.DrawLine(pen, _startPosX.Value + 8, _startPosY.Value + 42, _startPosX.Value + 10, _startPosY.Value + 42);
g.DrawLine(pen, _startPosX.Value + 7, _startPosY.Value + 43, _startPosX.Value + 7, _startPosY.Value + 53);
g.DrawLine(pen, _startPosX.Value + 8, _startPosY.Value + 54, _startPosX.Value + 12, _startPosY.Value + 54);
g.DrawLine(pen, _startPosX.Value + 13, _startPosY.Value + 55, _startPosX.Value + 69, _startPosY.Value + 55);
g.DrawLine(pen, _startPosX.Value + 70, _startPosY.Value + 54, _startPosX.Value + 73, _startPosY.Value + 54);
g.DrawLine(pen, _startPosX.Value + 74, _startPosY.Value + 53, _startPosX.Value + 74, _startPosY.Value + 43);
g.DrawLine(pen, _startPosX.Value + 71, _startPosY.Value + 42, _startPosX.Value + 73, _startPosY.Value + 42);
//колеса
g.FillEllipse(BodyBrush, _startPosX.Value + 10, _startPosY.Value + 44, 9, 9);
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 44, 9, 9);
g.FillEllipse(BodyBrush, _startPosX.Value + 63, _startPosY.Value + 44, 9, 9);
g.DrawEllipse(pen, _startPosX.Value + 63, _startPosY.Value + 44, 9, 9);
g.FillEllipse(BodyBrush, _startPosX.Value + 25, _startPosY.Value + 48, 6, 6);
g.DrawEllipse(pen, _startPosX.Value + 25, _startPosY.Value + 48, 6, 6);
g.FillEllipse(BodyBrush, _startPosX.Value + 38, _startPosY.Value + 48, 6, 6);
g.DrawEllipse(pen, _startPosX.Value + 38, _startPosY.Value + 48, 6, 6);
g.FillEllipse(BodyBrush, _startPosX.Value + 50, _startPosY.Value + 48, 6, 6);
g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 48, 6, 6);
g.FillEllipse(BodyBrush, _startPosX.Value + 33, _startPosY.Value + 44, 4, 4);
g.DrawEllipse(pen, _startPosX.Value + 33, _startPosY.Value + 44, 4, 4);
g.FillEllipse(BodyBrush, _startPosX.Value + 45, _startPosY.Value + 44, 4, 4);
g.DrawEllipse(pen, _startPosX.Value + 45, _startPosY.Value + 44, 4, 4);
_startPosX += 10;
_startPosY += 25;
base.DrawTransport(g);
_startPosX -= 10;
_startPosY -= 25;
if (fighter.Kovsh)
{
//ковш
g.DrawRectangle(pen, _startPosX.Value - 2, _startPosY.Value + 37, 8, 15);
g.FillRectangle(CraneBrush, _startPosX.Value - 2, _startPosY.Value + 37, 8, 15);
g.DrawRectangle(pen, _startPosX.Value - -6, _startPosY.Value + 37, 4, 1);
}
//противовес
if (fighter.Otval)
{
g.DrawRectangle(pen, _startPosX.Value + 73, _startPosY.Value + 37, 17, 1);
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 37, 1, 17);
}
}
}

View File

@ -0,0 +1,244 @@
using lab1.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace lab1.Drawnings;
public class DrawningTrackedVehicle
{ /// <summary>
/// Класс-сущность
/// </summary>
public EntityTrackedVehicle? EntityTrackedVehicle { get; protected set; }
/// <summary>
/// Ширина окна
/// </summary>
private int? _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
private int? _pictureHeight;
/// <summary>
/// Левая координата прорисовки истребителя
/// </summary>
protected int? _startPosX;
/// <summary>
/// Верхняя координата прорисовки истребителя
/// </summary>
protected int? _startPosY;
/// <summary>
/// Ширина прорисовки истребителя
/// </summary>
private readonly int _drawningFighterWidth = 63;
/// <summary>
/// Высота прорисовки истребителя
/// </summary>
private readonly int _drawningFighterHeight = 54;
/// <summary>
/// Пустой конструктор
/// </summary>
private DrawningTrackedVehicle()
{
_pictureWidth = null;
_pictureHeight = null;
_startPosX = null;
_startPosY = null;
}
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">>Вес истребителя</param>
/// <param name="bodyColor">Основной цвет</param>
public DrawningTrackedVehicle(int speed, double weight, Color bodyColor) : this()
{
EntityTrackedVehicle = new EntityTrackedVehicle(speed, weight, bodyColor);
}
/// <summary>
/// Конструктор для наследников
/// </summary>
/// <param name="_drawningFighterWidth"> Ширина прорисовки истребителя</param>
/// <param name="_drawningFighterHeight">>Высота прорисовки истребителя</param>
protected DrawningTrackedVehicle(int _drawningFighterWidth, int _drawningFighterHeight) : this()
{
_drawningFighterWidth = _drawningFighterWidth;
_drawningFighterHeight = _drawningFighterHeight;
}
/// <summary>
/// Установка границ поля
/// </summary>
/// <param name="width">Ширина поля</param>
/// <param name="height">Высота поля</param>
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
public bool SetPictureSize(int width, int height)
{
if (width >= _drawningFighterWidth && height >= _drawningFighterHeight)
{
_pictureWidth = width;
_pictureHeight = height;
if (_startPosX.HasValue && _startPosY.HasValue)
{
SetPosition(_startPosX.Value, _startPosY.Value);
}
return true;
}
return false;
}
/// <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 < 0)
{
x = 0;
}
else if (x > _pictureWidth.Value - _drawningFighterWidth)
{
x = _pictureWidth.Value - _drawningFighterWidth;
}
if (y < 0)
{
y = 0;
}
else if (y > _pictureHeight.Value - _drawningFighterHeight)
{
y = _pictureHeight.Value - _drawningFighterHeight;
}
_startPosX = x;
_startPosY = y;
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
public bool MoveTransport(DirectionType direction)
{
if (EntityTrackedVehicle == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return false;
}
switch (direction)
{
//влево
case DirectionType.Left:
if (_startPosX.Value - EntityTrackedVehicle.Step > 0)
{
_startPosX -= (int)EntityTrackedVehicle.Step;
}
return true;
//Вверх
case DirectionType.Up:
if (_startPosY.Value - EntityTrackedVehicle.Step > 0)
{
_startPosY -= (int)EntityTrackedVehicle.Step;
}
return true;
//Вправо
case DirectionType.Right:
if (_startPosX.Value + EntityTrackedVehicle.Step + _drawningFighterWidth < _pictureWidth)
{
_startPosX += (int)EntityTrackedVehicle.Step;
}
return true;
//Вниз
case DirectionType.Down:
if (_startPosY.Value + EntityTrackedVehicle.Step + _drawningFighterHeight < _pictureHeight)
{
_startPosY += (int)EntityTrackedVehicle.Step;
}
return true;
default:
return false;
}
}
/// <summary>
/// Прорисовка объекта
/// </summary>
/// <param name="g"></param>
public virtual void DrawTransport(Graphics g)
{
if (EntityTrackedVehicle == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
Pen pen = new(Color.Black);
Brush BodyBrush = new SolidBrush(EntityTrackedVehicle.BodyColor);
//корпус
g.FillRectangle(BodyBrush, _startPosX.Value, _startPosY.Value + 5, 62, 12);
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 5, 62, 12);
g.FillRectangle(BodyBrush, _startPosX.Value + 12, _startPosY.Value - 9, 4, 15);
g.DrawRectangle(pen, _startPosX.Value +12, _startPosY.Value - 9, 4, 14);
g.FillRectangle(BodyBrush, _startPosX.Value + 27, _startPosY.Value - 24, 5, 30);
g.DrawRectangle(pen, _startPosX.Value + 27, _startPosY.Value - 24, 5, 30);
//стекло
g.FillRectangle(BodyBrush, _startPosX.Value + 42, _startPosY.Value - 11, 21, 16);
g.DrawRectangle(pen, _startPosX.Value + 42, _startPosY.Value -11, 20, 16);
//гусеницы
g.DrawLine(pen, _startPosX.Value - 2, _startPosY.Value + 17, _startPosX.Value, _startPosY.Value + 17);
g.DrawLine(pen, _startPosX.Value - 3, _startPosY.Value + 18, _startPosX.Value - 3, _startPosY.Value + 28);
g.DrawLine(pen, _startPosX.Value - 2, _startPosY.Value + 29, _startPosX.Value + 2, _startPosY.Value + 29);
g.DrawLine(pen, _startPosX.Value + 3, _startPosY.Value + 30, _startPosX.Value + 59, _startPosY.Value + 30);
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 29, _startPosX.Value + 63, _startPosY.Value + 29);
g.DrawLine(pen, _startPosX.Value + 64, _startPosY.Value + 28, _startPosX.Value + 64, _startPosY.Value + 18);
g.DrawLine(pen, _startPosX.Value + 61, _startPosY.Value + 17, _startPosX.Value + 63, _startPosY.Value + 17);
//колеса
g.FillEllipse(BodyBrush, _startPosX.Value, _startPosY.Value + 19, 9, 9);
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 19, 9, 9);
g.FillEllipse(BodyBrush, _startPosX.Value + 53, _startPosY.Value + 19, 9, 9);
g.DrawEllipse(pen, _startPosX.Value + 53, _startPosY.Value + 19, 9, 9);
g.FillEllipse(BodyBrush, _startPosX.Value + 15, _startPosY.Value + 23, 6, 6);
g.DrawEllipse(pen, _startPosX.Value + 15, _startPosY.Value + 23, 6, 6);
g.FillEllipse(BodyBrush, _startPosX.Value + 28, _startPosY.Value + 23, 6, 6);
g.DrawEllipse(pen, _startPosX.Value + 28, _startPosY.Value + 23, 6, 6);
g.FillEllipse(BodyBrush, _startPosX.Value + 40, _startPosY.Value + 23, 6, 6);
g.DrawEllipse(pen, _startPosX.Value + 40, _startPosY.Value + 23, 6, 6);
g.FillEllipse(BodyBrush, _startPosX.Value + 23, _startPosY.Value + 19, 4, 4);
g.DrawEllipse(pen, _startPosX.Value + 23, _startPosY.Value + 19, 4, 4);
g.FillEllipse(BodyBrush, _startPosX.Value + 35, _startPosY.Value + 19, 4, 4);
g.DrawEllipse(pen, _startPosX.Value + 35, _startPosY.Value + 19, 4, 4);
}
}

View File

@ -1,23 +1,12 @@

namespace lab1;
namespace lab1.Entities;
/// <summary>
/// Класс-сущность "Истребитель"
/// </summary>
public class EntityFighter
public class EntityFighter : EntityTrackedVehicle
{
/// <summary>
/// Скорость
/// </summary>
public int Speed { get; set; }
/// <summary>
/// Вес
/// </summary>
public double Weight { get; set; }
/// <summary>
/// Основной цвет
/// </summary>
public Color BodyColor { get; private set; }
/// <summary>
/// Дополнительный цвет (для опциональных элементов)
/// </summary>
@ -30,10 +19,7 @@ public class EntityFighter
/// Признак (опция) наличия доп. крыльев
/// </summary>
public bool Otval { get; private set; }
/// <summary>
/// Шаг перемещения истребителя
/// </summary>
public double Step => Speed * 100 / Weight;
/// <summary>
/// Инициализация полей объекта-класса истребителя
/// </summary>
@ -44,11 +30,9 @@ public class EntityFighter
/// <param name="rockets">Признак наличия ракет</param>
/// <param name="extraWings">Признак наличия доп. крыльев</param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool rockets, bool extraWings)
public EntityFighter(int speed, double weight, Color bodyColor, Color additionalColor, bool rockets, bool extraWings) : base(speed, weight, bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
Kovsh = rockets;
Otval = extraWings;

View File

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace lab1.Entities;
/// <summary>
/// Класс-сущность "Гусеничная машина"
/// </summary>
public class EntityTrackedVehicle
{
/// <summary>
/// Скорость
/// </summary>
public int Speed { get; set; }
/// <summary>
/// Вес
/// </summary>
public double Weight { get; set; }
/// <summary>
/// Основной цвет
/// </summary>
public Color BodyColor { 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>
public EntityTrackedVehicle(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
}
}

View File

@ -34,6 +34,7 @@
buttonDown = new Button();
buttonUp = new Button();
buttonRight = new Button();
buttonCreateTrackedVehicle = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxFighter).BeginInit();
SuspendLayout();
//
@ -51,11 +52,11 @@
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(12, 538);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(112, 34);
buttonCreate.Size = new Size(226, 34);
buttonCreate.TabIndex = 1;
buttonCreate.Text = "создать";
buttonCreate.Text = "создать истребитель";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += buttonCreate_Click_1;
buttonCreate.Click += ButtonCreate_Click;
//
// buttonLeft
//
@ -68,7 +69,7 @@
buttonLeft.Size = new Size(52, 52);
buttonLeft.TabIndex = 2;
buttonLeft.UseVisualStyleBackColor = false;
buttonLeft.Click += buttonMove_Click;
buttonLeft.Click += ButtonMove_Click;
//
// buttonDown
//
@ -81,7 +82,7 @@
buttonDown.Size = new Size(52, 52);
buttonDown.TabIndex = 3;
buttonDown.UseVisualStyleBackColor = false;
buttonDown.Click += buttonMove_Click;
buttonDown.Click += ButtonMove_Click;
//
// buttonUp
//
@ -94,7 +95,7 @@
buttonUp.Size = new Size(52, 52);
buttonUp.TabIndex = 4;
buttonUp.UseVisualStyleBackColor = false;
buttonUp.Click += buttonMove_Click;
buttonUp.Click += ButtonMove_Click;
//
// buttonRight
//
@ -107,13 +108,25 @@
buttonRight.Size = new Size(52, 52);
buttonRight.TabIndex = 5;
buttonRight.UseVisualStyleBackColor = false;
buttonRight.Click += buttonMove_Click;
buttonRight.Click += ButtonMove_Click;
//
// buttonCreateTrackedVehicle
//
buttonCreateTrackedVehicle.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateTrackedVehicle.Location = new Point(234, 538);
buttonCreateTrackedVehicle.Name = "buttonCreateTrackedVehicle";
buttonCreateTrackedVehicle.Size = new Size(264, 34);
buttonCreateTrackedVehicle.TabIndex = 6;
buttonCreateTrackedVehicle.Text = "создать гусеничную машину";
buttonCreateTrackedVehicle.UseVisualStyleBackColor = true;
buttonCreateTrackedVehicle.Click += ButtonCreateTrackedVehicle_Click;
//
// FormFighter
//
AutoScaleDimensions = new SizeF(10F, 25F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1015, 584);
Controls.Add(buttonCreateTrackedVehicle);
Controls.Add(buttonRight);
Controls.Add(buttonUp);
Controls.Add(buttonDown);
@ -135,5 +148,6 @@
private Button buttonDown;
private Button buttonUp;
private Button buttonRight;
private Button buttonCreateTrackedVehicle;
}
}

View File

@ -1,4 +1,5 @@
using lab1;
using lab1.Drawnings;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -9,13 +10,13 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace lab1
{
namespace lab1;
public partial class FormFighter : Form
{
private DrawningEntityFighter? _drawningFighter;
private DrawningTrackedVehicle? _drawningTrackedVehicle;
public FormFighter()
{
InitializeComponent();
@ -23,22 +24,74 @@ namespace lab1
private void Draw()
{
if (_drawningFighter == null)
if (_drawningTrackedVehicle == null)
{
return;
}
Bitmap bmp = new(pictureBoxFighter.Width, pictureBoxFighter.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningFighter.DrawTransport(gr);
_drawningTrackedVehicle.DrawTransport(gr);
pictureBoxFighter.Image = bmp;
}
/// <summary>
/// Создание объекта класса-перемещения
/// </summary>
/// <param name="type"></param>
private void CreateObject(string type)
{
Random random = new();
switch (type)
{
case nameof(DrawningTrackedVehicle):
_drawningTrackedVehicle = new DrawningTrackedVehicle(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
break;
case nameof(DrawningEntityFighter):
_drawningTrackedVehicle = new DrawningEntityFighter(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
break;
default:
return;
}
_drawningTrackedVehicle.SetPictureSize(pictureBoxFighter.Width, pictureBoxFighter.Height);
_drawningTrackedVehicle.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void buttonMove_Click(object sender, EventArgs e)
/// <summary>
/// Обработка нажатия кнопки "Создать истребитель"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningEntityFighter));
/// <summary>
/// Обработка нажатия кнопки "Создать гусеничную машину"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateTrackedVehicle_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrackedVehicle));
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawningFighter == null)
if (_drawningTrackedVehicle == null)
{
return;
}
@ -48,16 +101,16 @@ namespace lab1
switch (name)
{
case "buttonUp":
result = _drawningFighter.MoveTransport(DirectionType.Up);
result = _drawningTrackedVehicle.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
result = _drawningFighter.MoveTransport(DirectionType.Down);
result = _drawningTrackedVehicle.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
result = _drawningFighter.MoveTransport(DirectionType.Left);
result = _drawningTrackedVehicle.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
result = _drawningFighter.MoveTransport(DirectionType.Right);
result = _drawningTrackedVehicle.MoveTransport(DirectionType.Right);
break;
}
@ -67,24 +120,12 @@ namespace lab1
}
}
private void buttonCreate_Click_1(object sender, EventArgs e)
{
{
Random random = new();
_drawningFighter = new DrawningEntityFighter();
_drawningFighter.Init(random.Next(100, 300), random.Next(1200, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
_drawningFighter.SetPictureSize(pictureBoxFighter.Width, pictureBoxFighter.Height);
_drawningFighter.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
}
private void FormFighter_Load(object sender, EventArgs e)
{
}
}
}