lab_5_done

This commit is contained in:
SooNooClose 2023-11-07 13:26:06 +04:00
parent ebf2b8d81e
commit 3898aac199
11 changed files with 42 additions and 51 deletions

View File

@ -5,14 +5,10 @@ using System.Text;
using System.Threading.Tasks;
using ProjectExcavator.Entities;
namespace ProjectExcavator.DrawningObjects
namespace ProjectExcavator
{
public class DrawningExcavatorBodyKits : DrawningExcavator
{
public void setAdditionalColor(Color color)
{
(EntityExcavator as EntityExcavatorBodyKits).AdditionalColor = color;
}
/// <summary>
/// Конструктор
/// </summary>

View File

@ -6,14 +6,10 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectExcavator.DrawningObjects
namespace ProjectExcavator
{
public class DrawningExcavator
{
public void setBodyColor(Color color)
{
EntityExcavator.BodyColor = color;
}
{
/// <summary>
/// Класс-сущность
/// </summary>
@ -72,12 +68,12 @@ namespace ProjectExcavator.DrawningObjects
public DrawningExcavator(int speed, double weight, Color bodyColor, int
width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
if (_pictureHeight < _excavatorHeight || _pictureWidth < _excavatorWidth)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
}
EntityExcavator = new EntityExcavator(speed, weight, bodyColor);
}
/// <summary>

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectExcavator.DrawningObjects;
namespace ProjectExcavator.MovementStrategy
{

View File

@ -19,7 +19,11 @@ namespace ProjectExcavator.Entities
/// <summary>
/// Основной цвет
/// </summary>
public Color BodyColor { get; set; }
public Color BodyColor { get; private set; }
public void setBodyColor(Color color)
{
BodyColor = color;
}
/// <summary>
/// Шаг перемещения экскаватора
/// </summary>

View File

@ -17,7 +17,11 @@ namespace ProjectExcavator.Entities
/// <summary>
/// Дополнительный цвет (для опциональных элементов)
/// </summary>
public Color AdditionalColor { get; set; }
public Color AdditionalColor { get; private set; }
public void setAdditionalColor(Color color)
{
AdditionalColor = color;
}
/// <summary>
/// признак наличия вспомогательных опор
/// </summary>

View File

@ -1,14 +0,0 @@
using ProjectExcavator.DrawningObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectExcavator
{/// <summary>
/// Делегат для передачи объекта-автомобиля
/// </summary>
/// <param name="excavator"></param>
public delegate void ExcavatorDelegate(DrawningExcavator excavator);
}

View File

@ -1,4 +1,4 @@
using ProjectExcavator.DrawningObjects;
using ProjectExcavator;
using ProjectExcavator.MovementStrategy;
using System.Drawing;

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectExcavator.MovementStrategy;
using ProjectExcavator.DrawningObjects;
using ProjectExcavator;
using ProjectExcavator.Generic;
namespace ProjectExcavator.Generic

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectExcavator.DrawningObjects;
using ProjectExcavator;
using ProjectExcavator.Generic;
using ProjectExcavator.MovementStrategy;

View File

@ -1,8 +1,8 @@
using ProjectExcavator.DrawningObjects;
using ProjectExcavator;
using ProjectExcavator.Generic;
using ProjectExcavator.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
@ -14,8 +14,7 @@ using System.Windows.Forms;
namespace ProjectExcavator
{
public partial class FormExcavatorCollection : Form
{
private readonly ExcavatorGenericCollection<DrawningExcavator, DrawningObjectExcavator> _excavators;
{
/// <summary>
/// Набор объектов
/// </summary>

View File

@ -1,4 +1,4 @@
using ProjectExcavator.DrawningObjects;
using ProjectExcavator;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -9,37 +9,43 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System;
using ProjectExcavator.Entities;
namespace ProjectExcavator
{
public partial class FormExcavatorConfig : Form
{
Color defaultColor;
DrawningExcavator? _excavator = null;
private event ExcavatorDelegate EventAddExcavator;
readonly Color defaultColor;
DrawningExcavator? _excavator;
private event Action<DrawningExcavator> EventAddExcavator;
public FormExcavatorConfig()
{
InitializeComponent();
panelBlue.MouseDown += panelColor_MouseDown;
panelCyan.MouseDown += panelColor_MouseDown;
panelFuchsia.MouseDown += panelColor_MouseDown;
panelLime.MouseDown += panelColor_MouseDown;
panelOrange.MouseDown += panelColor_MouseDown;
panelRed.MouseDown += panelColor_MouseDown;
panelYellow.MouseDown += panelColor_MouseDown;
panelSilver.MouseDown += panelColor_MouseDown;
defaultColor = labelColor.BackColor;
buttonCansel.Click += (s, e) => Close();
}
private void DrawExcavator()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_excavator?.SetPosition(5, 5);
if (_excavator is DrawningExcavatorBodyKits)
(_excavator as DrawningExcavatorBodyKits)?.DrawTransport(gr);
else
_excavator?.DrawTransport(gr);
_excavator?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
/// </summary>
/// Добавление события
/// </summary>
/// <param name="ev">Привязанный метод</param>
internal void AddEvent(ExcavatorDelegate ev)
internal void AddEvent(Action<DrawningExcavator> ev)
{
if (EventAddExcavator == null)
{
@ -138,14 +144,14 @@ namespace ProjectExcavator
switch (((Label)sender).Name)
{
case "labelColor":
_excavator.setBodyColor((Color)e.Data.GetData(typeof(Color)));
_excavator.EntityExcavator.setBodyColor((Color)e.Data.GetData(typeof(Color)));
break;
case "labelAdditionalColor":
if (!(_excavator is DrawningExcavatorBodyKits))
if (_excavator is not DrawningExcavatorBodyKits)
{
return;
}
(_excavator as DrawningExcavatorBodyKits).setAdditionalColor((Color)e.Data.GetData(typeof(Color)));
(_excavator.EntityExcavator as EntityExcavatorBodyKits).setAdditionalColor((Color)e.Data.GetData(typeof(Color)));
break;
}
DrawExcavator();