Lab_1_Kryukov_AI_Excavator

This commit is contained in:
1SooNoo1 2023-09-16 14:44:49 +04:00
parent bd90692048
commit 2852c96445
8 changed files with 300 additions and 34 deletions

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectExcavator
{
public enum DirectionType
{
/// <summary>
/// Вверх
/// </summary>
Up = 1,
/// <summary>
/// Вниз
/// </summary>
Down = 2,
/// <summary>
/// Влево
/// </summary>
Left = 3,
/// <summary>
/// Вправо
/// </summary>
Right = 4
}
}

View File

@ -0,0 +1,172 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectExcavator
{
internal class DrawningExcavator
{
/// <summary>
/// Класс-сущность
/// </summary>
public EntityExcavator? EntityExcavator { 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 _excavatorWidth = 190;
/// <summary>
/// Высота прорисовки автомобиля
/// </summary>
private readonly int _excavatorHeight = 170;
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Цвет кузова</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия вспомогательных опор</param>
/// <param name="backet">Признак наличия ковша</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
/// <returns>true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах</returns>
public bool Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool bodyKit, bool backet, int width, int height)
{
// TODO: Продумать проверки
_pictureWidth = width;
_pictureHeight = height;
EntityExcavator = new EntityExcavator();
EntityExcavator.Init(speed, weight, bodyColor, additionalColor, bodyKit, backet);
return true;
}
/// <summary>
/// Установка позиции
/// </summary>
/// <param name="x">Координата X</param>
/// <param name="y">Координата Y</param>
public void SetPosition(int x, int y)
{
// TODO: Изменение x, y
_startPosX = x;
_startPosY = y;
}
/// <summary>
/// Изменение направления перемещения
/// </summary>
/// <param name="direction">Направление</param>
public void MoveTransport(DirectionType direction)
{
if (EntityExcavator == null)
{
return;
}
switch (direction)
{
//влево
case DirectionType.Left:
if (_startPosX - EntityExcavator.Step > 0)
{
_startPosX -= (int)EntityExcavator.Step;
}
break;
//вверх
case DirectionType.Up:
if (_startPosY - EntityExcavator.Step > -50)
{
_startPosY -= (int)EntityExcavator.Step;
}
break;
// вправо
case DirectionType.Right:
if (_startPosX + EntityExcavator.Step < _pictureWidth - _excavatorWidth)
{
_startPosX += (int)EntityExcavator.Step;
}
break;
//вниз
case DirectionType.Down:
if (_startPosY + EntityExcavator.Step < _pictureHeight - _excavatorHeight)
{
_startPosY += (int)EntityExcavator.Step;
}
break;
}
}
/// <summary>
/// Прорисовка объекта
/// </summary>
/// <param name="g"></param>
public void DrawTransport(Graphics g)
{
if (EntityExcavator == null)
{
return;
}
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(EntityExcavator.AdditionalColor);
if (EntityExcavator.BodyKit)
{
g.FillRectangle(additionalBrush, _startPosX + 20, _startPosY + 120, 130, 10);
g.DrawLine(pen, _startPosX + 20, _startPosY + 120, _startPosX + 150, _startPosY + 120);
}
//корпус
Brush bodyBrush = new SolidBrush(Color.Red);
g.FillRectangle(bodyBrush, _startPosX + 20, _startPosY + 110, 130, 20);
g.FillRectangle(bodyBrush, _startPosX + 100, _startPosY + 70, 30, 40);
g.FillRectangle(bodyBrush, _startPosX + 30, _startPosY + 90, 10, 20);
g.DrawRectangle(pen, _startPosX + 20, _startPosY + 110, 130, 20);
g.DrawRectangle(pen, _startPosX + 100, _startPosY + 70, 30, 40);
g.DrawRectangle(pen, _startPosX + 30, _startPosY + 90, 10, 20);
//гусеница
Point[] points = {
new Point(_startPosX + 20, _startPosY + 130),
new Point(_startPosX + 15, _startPosY+ 135),
new Point(_startPosX + 15, _startPosY + 145),
new Point(_startPosX + 20, _startPosY + 150),
new Point(_startPosX + 145, _startPosY + 150),
new Point(_startPosX + 150, _startPosY + 145),
new Point(_startPosX + 150, _startPosY + 135),
new Point(_startPosX + 145, _startPosY + 130)};
g.DrawPolygon(pen, points);
g.DrawEllipse(pen, _startPosX + 20, _startPosY + 130, 20, 20);
g.DrawEllipse(pen, _startPosX + 40, _startPosY + 130, 20, 20);
g.DrawEllipse(pen, _startPosX + 60, _startPosY + 130, 20, 20);
g.DrawEllipse(pen, _startPosX + 80, _startPosY + 130, 20, 20);
g.DrawEllipse(pen, _startPosX + 100, _startPosY + 130, 20, 20);
g.DrawEllipse(pen, _startPosX + 120, _startPosY + 130, 20, 20);
//ковш
if (EntityExcavator.Backet)
{
Point[] pointsBacket = {
new Point(_startPosX + 150, _startPosY + 75),
new Point(_startPosX + 150, _startPosY + 135),
new Point(_startPosX + 195, _startPosY + 135),
};
g.FillPolygon(additionalBrush, pointsBacket);
g.DrawPolygon(pen, pointsBacket);
}
}
}
}

View File

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectExcavator
{
internal class EntityExcavator
{
// <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 BodyKit { get; private set; }
/// <summary>
/// Признак (опция) наличия ковша
/// </summary>
public bool Backet { get; private set; }
/// <summary>
/// Шаг перемещения автомобиля
/// </summary>
public double Step => (double)Speed * 100 / Weight;
/// <summary>
/// Инициализация полей объекта-класса спортивного автомобиля
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия обвеса</param>
/// <param name="backet">Признак наличия антикрыла</param>
public void Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool bodyKit, bool backet)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
BodyKit = bodyKit;
Backet = backet;
}
}
}

View File

@ -1,6 +1,6 @@
namespace ProjectExcavator
{
partial class Form1
partial class ExcavatorForm
{
/// <summary>
/// Required designer variable.
@ -28,10 +28,16 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
SuspendLayout();
//
// Form1
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Name = "Form1";
Text = "Excavator";
ResumeLayout(false);
}
#endregion

View File

@ -1,8 +1,8 @@
namespace ProjectExcavator
{
public partial class Form1 : Form
public partial class ExcavatorForm : Form
{
public Form1()
public ExcavatorForm()
{
InitializeComponent();
}

View File

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
@ -26,36 +26,36 @@
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->

View File

@ -11,7 +11,7 @@ namespace ProjectExcavator
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
Application.Run(new ExcavatorForm());
}
}
}

View File

@ -18,6 +18,5 @@
/// Вправо
/// </summary>
Right = 4
}
}