Compare commits

...

2 Commits

Author SHA1 Message Date
Артём Ерастов
ade3f04903 исправления 2024-10-01 21:49:49 +04:00
Артём Ерастов
a4c26fed31 изменения_1.1 2024-10-01 21:16:10 +04:00
5 changed files with 246 additions and 225 deletions

View File

@ -4,12 +4,9 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace lab0; namespace Teplohod;
public enum DirectionType public enum DirectionType
{ {
Up=1, Up = 1, Down = 2, Left = 3, Right = 4,
Down=2,
Left=3,
Right=4,
} }

View File

@ -3,50 +3,57 @@ using System.Drawing;
namespace Teplohod; namespace Teplohod;
public class DrawingTeplohod public class DrawningTeplohod
{ {
/// <summary> /// <summary>
/// Класс-сущность /// Класс-сущность
/// </summary> /// </summary>
public EntityTeplohod? EntityTeplohod { get; set; } public EntityTeplohod? EntityTeplohod { get; private set; }
/// <summary> /// <summary>
/// Ширина окна /// Ширина окна
/// </summary> /// </summary>
private int? _pictureWidth; private int? _pictureWidth;
/// <summary> /// <summary>
/// Высота окна /// Высота окна
/// </summary> /// </summary>
private int? _pictureHeight; private int? _pictureHeight;
/// <summary>
/// Левая координата прорисовки теплохода
/// </summary>
private int? _startPosX;
/// <summary> /// <summary>
/// Верхняя кооридната прорисовки теплохода /// Левая координата прорисовки автомобиля
/// </summary>
private int? _startPosX;
/// <summary>
/// Верхняя кооридната прорисовки автомобиля
/// </summary> /// </summary>
private int? _startPosY; private int? _startPosY;
/// <summary> /// <summary>
/// Ширина прорисовки теплохода /// Ширина прорисовки автомобиля
/// </summary> /// </summary>
private readonly int _drawningTeplohodWidth = 150; private readonly int _drawningTeplohodWidth = 110;
/// <summary> /// <summary>
/// Высота прорисовки теплохода /// Высота прорисовки автомобиля
/// </summary> /// </summary>
private readonly int _drawningTeplohodHeight = 88; private readonly int _drawningTeplohodHeight = 60;
/// <summary> /// <summary>
/// Инициализация свойств /// Инициализация свойств
/// </summary> /// </summary>
/// <param name="speed">Скорость</param> /// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param> /// <param name="weight">Вес</param>
/// <param name="bodycolor">Основной цвет</param> /// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalcolor">Дополнительный цвет</param> /// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="pipes">Признак наличия труб</param> /// <param name="pipes">Признак наличия обвеса</param>
/// <param name="fueltank">Признак наличия топливных баков</param> /// <param name="tank">Признак наличия антикрыла</param>
public void Init(int speed, double weight, Color bodycolor, Color additionalcolor, bool pipes, bool fueltank) /// <param name="firstDack">Признак наличия гоночной полосы</param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool pipes, bool tank, bool firstDack)
{ {
EntityTeplohod = new EntityTeplohod(); EntityTeplohod = new EntityTeplohod();
EntityTeplohod.Init(speed, weight, bodycolor, additionalcolor, pipes, fueltank); EntityTeplohod.Init(speed, weight, bodyColor, additionalColor, pipes, tank, firstDack);
_pictureWidth = null; _pictureWidth = null;
_pictureHeight = null; _pictureHeight = null;
_startPosX = null; _startPosX = null;
@ -61,33 +68,24 @@ public class DrawingTeplohod
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns> /// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
public bool SetPictureSize(int width, int height) public bool SetPictureSize(int width, int height)
{ {
if (EntityTeplohod == null) if (_drawningTeplohodWidth <= width && _drawningTeplohodHeight <= height)
{ {
return false; _pictureWidth = width;
} _pictureHeight = height;
// Проверяем, что объект не выходит за пределы формы
if (width >= _drawningTeplohodWidth && height >= _drawningTeplohodHeight)
{
_pictureWidth = width;
_pictureHeight = height;
// Если уже заданы координаты прорисовки, то корректируем их, чтобы объект оставался видимым
if (_startPosX.HasValue && _startPosY.HasValue) if (_startPosX.HasValue && _startPosY.HasValue)
{ {
if (_startPosX + _drawningTeplohodWidth > _pictureWidth) if (_startPosX + _drawningTeplohodWidth > _pictureWidth)
{ {
_startPosX = _pictureWidth - _drawningTeplohodWidth; _startPosX = _pictureWidth - _drawningTeplohodWidth;
} }
if (_startPosY + _drawningTeplohodHeight > _pictureHeight) if (_startPosY + _drawningTeplohodHeight > _pictureHeight)
{ {
_startPosY = _pictureHeight - _drawningTeplohodHeight; _startPosY = _pictureHeight - _drawningTeplohodHeight;
} }
} }
return true;
return true; }
}
return false; return false;
} }
@ -102,26 +100,11 @@ public class DrawingTeplohod
{ {
return; return;
} }
if (x < 0) x = 0;
else if (x + _drawningTeplohodWidth > _pictureWidth) x = _pictureWidth.Value - _drawningTeplohodWidth;
// Проверяем, выходит ли объект за границы формы if (y < 0) y = 0;
if (x < 0) else if (y + _drawningTeplohodHeight > _pictureHeight) y = _pictureHeight.Value - _drawningTeplohodHeight;
{
x = 0;
}
else if (x + _drawningTeplohodWidth > _pictureWidth)
{
x = _pictureWidth.Value - _drawningTeplohodWidth;
}
if (y < 0)
{
y = 0;
}
else if (y + _drawningTeplohodHeight > _pictureHeight)
{
y = _pictureHeight.Value - _drawningTeplohodHeight;
}
_startPosX = x; _startPosX = x;
_startPosY = y; _startPosY = y;
} }
@ -137,6 +120,7 @@ public class DrawingTeplohod
{ {
return false; return false;
} }
switch (direction) switch (direction)
{ {
//влево //влево
@ -155,75 +139,73 @@ public class DrawingTeplohod
return true; return true;
// вправо // вправо
case DirectionType.Right: case DirectionType.Right:
if (_startPosX.Value + EntityTeplohod.Step + _drawningTeplohodWidth < _pictureWidth) if (_startPosX.Value + _drawningTeplohodWidth + EntityTeplohod.Step < _pictureWidth)
{
_startPosX += (int)EntityTeplohod.Step; _startPosX += (int)EntityTeplohod.Step;
}
return true; return true;
//вниз //вниз
case DirectionType.Down: case DirectionType.Down:
if (_startPosY.Value + EntityTeplohod.Step + _drawningTeplohodHeight < _pictureHeight) if (_startPosY.Value + _drawningTeplohodHeight + EntityTeplohod.Step < _pictureHeight)
{
_startPosY += (int)EntityTeplohod.Step; _startPosY += (int)EntityTeplohod.Step;
}
return true; return true;
default: default:
return false; return false;
} }
} }
/// <summary> /// <summary>
/// Прорисовка объекта /// Прорисовка объекта
/// </summary> /// </summary>
/// <param name="g"></param> /// <param name="g"></param>
public void DrawTransport(Graphics g) public void DrawTransport(Graphics g)
{ {
if (EntityTeplohod == null || !_startPosX.HasValue || if (EntityTeplohod == null || !_startPosX.HasValue || !_startPosY.HasValue)
!_startPosY.HasValue)
{ {
return; return;
} }
Pen pen = new(Color.Black); Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(EntityTeplohod.AdditionalColor);
Brush bodybrush = new SolidBrush(EntityTeplohod.BodyColor); Brush bodybrush = new SolidBrush(EntityTeplohod.BodyColor);
Brush bodybrush2 = new SolidBrush(EntityTeplohod.AdditionalColor);
// Трубы
//корпус
g.DrawRectangle(pen, new Rectangle(_startPosX.Value + 30, _startPosY.Value + 40, 90, 10));
g.FillRectangle(bodybrush, _startPosX.Value + 30, _startPosY.Value + 40, 90, 10);
g.DrawPolygon(pen, new[]{
new Point(_startPosX.Value, _startPosY.Value + 50),
new Point(_startPosX.Value + 150, _startPosY.Value + 50),
new Point(_startPosX.Value + 130, _startPosY.Value + 80),
new Point(_startPosX.Value + 20, _startPosY.Value + 80)
});
g.FillPolygon(bodybrush, new[]{
new Point(_startPosX.Value, _startPosY.Value + 50),
new Point(_startPosX.Value + 150, _startPosY.Value + 50),
new Point(_startPosX.Value + 130, _startPosY.Value + 80),
new Point(_startPosX.Value + 20, _startPosY.Value + 80)
});
g.DrawLine(pen, _startPosX.Value, _startPosY.Value + 50, _startPosX.Value + 150, _startPosY.Value + 50);
//трубы
if (EntityTeplohod.Pipes) if (EntityTeplohod.Pipes)
{ {
g.DrawRectangle(pen, new Rectangle(_startPosX.Value + 5, _startPosY.Value, 15, 50)); g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value, 10, 20);
g.FillRectangle(additionalBrush, _startPosX.Value + 5, _startPosY.Value, 15, 50); g.FillRectangle(bodybrush2, _startPosX.Value + 30, _startPosY.Value, 10, 20);
} }
//топливный бак
if (EntityTeplohod.FuelTank) //границы Теплохода
g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value, 30, 20);
Point point1 = new Point(_startPosX.Value, _startPosY.Value + 20);
Point point2 = new Point(_startPosX.Value + 150, _startPosY.Value + 20);
Point point3 = new Point(_startPosX.Value + 130, _startPosY.Value + 45);
Point point4 = new Point(_startPosX.Value + 40, _startPosY.Value + 45);
Point point5 = new Point(_startPosX.Value, _startPosY.Value + 20);
Point[] pointsTeplohod = { point1, point2, point3, point4, point5 };
g.DrawPolygon(pen, pointsTeplohod);
g.FillRectangle(bodybrush, _startPosX.Value + 100, _startPosY.Value, 30, 20);
g.FillPolygon(bodybrush2, pointsTeplohod);
if (EntityTeplohod.FirstDack)
{ {
Brush brRed = new SolidBrush(Color.Red); Brush bodybrush3 = new SolidBrush(Color.Yellow);
g.DrawRectangle(pen, new Rectangle(_startPosX.Value + 35, _startPosY.Value + 5, 80, 30)); g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 5, 48, 15);
g.FillRectangle(brRed, _startPosX.Value + 35, _startPosY.Value + 5, 80, 30); g.FillRectangle(bodybrush3, _startPosX.Value + 51, _startPosY.Value + 5, 47, 15);
}
// топливный бак
if (EntityTeplohod.Tank)
{
Brush bodybrush4 = new SolidBrush(Color.Red);
g.DrawRectangle(pen, _startPosX.Value + 131, _startPosY.Value + 5, 15, 15);
g.FillRectangle(bodybrush4, _startPosX.Value + 131, _startPosY.Value + 5, 15, 15);
} }
g.DrawLine(pen, _startPosX.Value + 35, _startPosY.Value + 35, _startPosX.Value + 30, _startPosY.Value + 40);
g.DrawLine(pen, _startPosX.Value + 115, _startPosY.Value + 35, _startPosX.Value + 120, _startPosY.Value + 40);
//якорь
g.DrawLine(pen, _startPosX.Value + 25, _startPosY.Value + 55, _startPosX.Value + 25, _startPosY.Value + 75);
g.DrawLine(pen, _startPosX.Value + 17, _startPosY.Value + 65, _startPosX.Value + 33, _startPosY.Value + 65);
g.DrawLine(pen, _startPosX.Value + 23, _startPosY.Value + 75, _startPosX.Value + 27, _startPosY.Value + 75);
} }
} }

View File

@ -2,28 +2,65 @@
public class EntityTeplohod public class EntityTeplohod
{ {
public int Speed { get; private set; }
public double Weight { get; private set; } /// <summary>
/// Скорость
/// </summary>
public int Speed { get; private set; }
/// <summary>
/// Вес
/// </summary>
public double Weight { get; private set; }
/// <summary>
/// Основной цвет
/// </summary>
public Color BodyColor { get; private set; } public Color BodyColor { get; private set; }
/// <summary>
/// Дополнительный цвет (для опциональных элементов)
/// </summary>
public Color AdditionalColor { get; private set; } public Color AdditionalColor { get; private set; }
public bool Pipes { get; private set; } /// <summary>
/// Признак (опция) наличия труб
/// </summary>
public bool Pipes { get; private set; }
public bool FuelTank { get; private set; } /// <summary>
/// Признак (опция) наличия топливного бака
/// </summary>
public bool Tank { get; private set; }
/// <summary>
/// Признак (опция) наличия гоночной полосы
/// </summary>
public bool FirstDack { get; private set; }
/// <summary>
/// Шаг перемещения автомобиля
/// </summary>
public double Step => Speed * 100 / Weight; public double Step => Speed * 100 / Weight;
public void Init(int speed, double weight, Color bodycolor, Color additionalcolor, bool pipes, bool fueltank) /// <summary>
/// Инициализация полей объекта-класса спортивного автомобиля
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="pipes">Признак наличия обвеса</param>
/// <param name="tank">Признак наличия антикрыла</param>
/// <param name="firstDack">Признак наличия гоночной полосы</param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool pipes, bool tank, bool firstDack)
{ {
Speed = speed; Speed = speed;
Weight = weight; Weight = weight;
BodyColor = bodycolor; BodyColor = bodyColor;
AdditionalColor = additionalcolor; AdditionalColor = additionalColor;
Pipes = pipes; Pipes = pipes;
FuelTank = fueltank; Tank = tank;
FirstDack = firstDack;
} }
} }

View File

@ -3,12 +3,12 @@
partial class FormTeplohod partial class FormTeplohod
{ {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.
/// </summary> /// </summary>
private System.ComponentModel.IContainer components = null; private System.ComponentModel.IContainer components = null;
/// <summary> /// <summary>
/// Clean up any resources being used. /// Clean up any resources being used.
/// </summary> /// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
@ -23,8 +23,8 @@
#region Windows Form Designer generated code #region Windows Form Designer generated code
/// <summary> /// <summary>
/// Required method for Designer support - do not modify /// Required method for Designer support - do not modify
/// the contents of this method with the code editor. /// the contents of this method with the code editor.
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
@ -41,55 +41,67 @@
// //
pictureBoxTeplohod.Dock = DockStyle.Fill; pictureBoxTeplohod.Dock = DockStyle.Fill;
pictureBoxTeplohod.Location = new Point(0, 0); pictureBoxTeplohod.Location = new Point(0, 0);
pictureBoxTeplohod.Margin = new Padding(3, 4, 3, 4);
pictureBoxTeplohod.Name = "pictureBoxTeplohod"; pictureBoxTeplohod.Name = "pictureBoxTeplohod";
pictureBoxTeplohod.Size = new Size(882, 553); pictureBoxTeplohod.Size = new Size(775, 487);
pictureBoxTeplohod.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxTeplohod.TabIndex = 0; pictureBoxTeplohod.TabIndex = 0;
pictureBoxTeplohod.TabStop = false; pictureBoxTeplohod.TabStop = false;
// //
// buttonCreate // buttonCreate
// //
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(12, 512); buttonCreate.Location = new Point(12, 415);
buttonCreate.Margin = new Padding(3, 4, 3, 4);
buttonCreate.Name = "buttonCreate"; buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(94, 29); buttonCreate.Size = new Size(93, 49);
buttonCreate.TabIndex = 1; buttonCreate.TabIndex = 1;
buttonCreate.Text = "создать"; buttonCreate.Text = "СОЗДАТЬ";
buttonCreate.UseVisualStyleBackColor = true; buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += buttonCreate_Click; buttonCreate.Click += ButtonCreateSportCar_Click;
// //
// buttonLeft // buttonLeft
// //
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackColor = SystemColors.ButtonFace;
buttonLeft.BackgroundImage = Properties.Resources.влево; buttonLeft.BackgroundImage = Properties.Resources.влево;
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch; buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
buttonLeft.Location = new Point(738, 500); buttonLeft.Location = new Point(557, 415);
buttonLeft.Margin = new Padding(3, 4, 3, 4);
buttonLeft.Name = "buttonLeft"; buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(40, 40); buttonLeft.Size = new Size(50, 50);
buttonLeft.TabIndex = 2; buttonLeft.TabIndex = 2;
buttonLeft.UseVisualStyleBackColor = true; buttonLeft.Text = " ";
buttonLeft.UseVisualStyleBackColor = false;
buttonLeft.Click += ButtonMove_Click; buttonLeft.Click += ButtonMove_Click;
// //
// buttonUp // buttonUp
// //
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackColor = SystemColors.Menu;
buttonUp.BackgroundImage = Properties.Resources.вверх; buttonUp.BackgroundImage = Properties.Resources.вверх;
buttonUp.BackgroundImageLayout = ImageLayout.Stretch; buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
buttonUp.Location = new Point(784, 454); buttonUp.ImageAlign = ContentAlignment.MiddleLeft;
buttonUp.Location = new Point(613, 357);
buttonUp.Margin = new Padding(3, 4, 3, 4);
buttonUp.Name = "buttonUp"; buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(40, 40); buttonUp.Size = new Size(50, 50);
buttonUp.TabIndex = 3; buttonUp.TabIndex = 3;
buttonUp.UseVisualStyleBackColor = true; buttonUp.Text = " ";
buttonUp.UseVisualStyleBackColor = false;
buttonUp.Click += ButtonMove_Click; buttonUp.Click += ButtonMove_Click;
// //
// buttonRight // buttonRight
// //
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.вправо; buttonRight.BackgroundImage = Properties.Resources.вправо;
buttonRight.BackgroundImageLayout = ImageLayout.Stretch; buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
buttonRight.Location = new Point(830, 501); buttonRight.Location = new Point(669, 415);
buttonRight.Margin = new Padding(3, 4, 3, 4);
buttonRight.Name = "buttonRight"; buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(40, 40); buttonRight.Size = new Size(50, 50);
buttonRight.TabIndex = 4; buttonRight.TabIndex = 5;
buttonRight.Text = " ";
buttonRight.UseVisualStyleBackColor = true; buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click; buttonRight.Click += ButtonMove_Click;
// //
@ -97,11 +109,13 @@
// //
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.вниз; buttonDown.BackgroundImage = Properties.Resources.вниз;
buttonDown.BackgroundImageLayout = ImageLayout.Stretch; buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
buttonDown.Location = new Point(784, 500); buttonDown.Location = new Point(613, 415);
buttonDown.Margin = new Padding(3, 4, 3, 4);
buttonDown.Name = "buttonDown"; buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(40, 40); buttonDown.Size = new Size(50, 50);
buttonDown.TabIndex = 5; buttonDown.TabIndex = 6;
buttonDown.Text = " ";
buttonDown.UseVisualStyleBackColor = true; buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click; buttonDown.Click += ButtonMove_Click;
// //
@ -109,17 +123,19 @@
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(882, 553); ClientSize = new Size(775, 487);
Controls.Add(buttonDown); Controls.Add(buttonDown);
Controls.Add(buttonRight); Controls.Add(buttonRight);
Controls.Add(buttonUp); Controls.Add(buttonUp);
Controls.Add(buttonLeft); Controls.Add(buttonLeft);
Controls.Add(buttonCreate); Controls.Add(buttonCreate);
Controls.Add(pictureBoxTeplohod); Controls.Add(pictureBoxTeplohod);
Margin = new Padding(3, 4, 3, 4);
Name = "FormTeplohod"; Name = "FormTeplohod";
Text = "Теплоход"; Text = "Form1";
((System.ComponentModel.ISupportInitialize)pictureBoxTeplohod).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxTeplohod).EndInit();
ResumeLayout(false); ResumeLayout(false);
PerformLayout();
} }
#endregion #endregion

View File

@ -1,102 +1,91 @@
using lab0; namespace Teplohod
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Teplohod;
public partial class FormTeplohod : Form
{ {
/// <summary> public partial class FormTeplohod : Form
/// Поле-объект для прорисовки объекта
/// </summary>
private DrawingTeplohod? _drawingTeplohod;
public FormTeplohod()
{ {
InitializeComponent(); public FormTeplohod()
}
/// <summary>
/// Метод прорисовки теплохода
/// </summary>
private void Draw()
{
if (_drawingTeplohod == null)
{ {
return; InitializeComponent();
} }
Bitmap bmp = new(pictureBoxTeplohod.Width, pictureBoxTeplohod.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawingTeplohod.DrawTransport(gr);
pictureBoxTeplohod.Image = bmp;
}
/// <summary>
/// Поле-объект для прорисовки объекта
/// </summary>
private DrawningTeplohod? _drawningTeplohod;
/// <summary> /// <summary>
/// Обработка нажатия кнопки "Создать" /// Конструктор формы
/// </summary> /// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreate_Click(object sender, EventArgs e)
{
Random random = new();
_drawingTeplohod = new DrawingTeplohod();
_drawingTeplohod.Init(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)));
_drawingTeplohod.SetPictureSize(pictureBoxTeplohod.Width, pictureBoxTeplohod.Height);
_drawingTeplohod.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
/// <summary>
/// Перемещение объекта по форме (нажатие кнопок навигации) /// <summary>
/// </summary> /// Метод прорисовки машины
/// <param name="sender"></param> /// </summary>
/// <param name="e"></param> private void Draw()
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawingTeplohod == null)
{ {
return; if (_drawningTeplohod == null)
{
return;
}
Bitmap bmp = new(pictureBoxTeplohod.Width, pictureBoxTeplohod.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningTeplohod.DrawTransport(gr);
pictureBoxTeplohod.Image = bmp;
} }
string name = ((Button)sender)?.Name ?? string.Empty;
bool result = false; /// <summary>
switch (name) /// Обработка нажатия кнопки "Создать"
{ /// </summary>
case "buttonUp": /// <param name="sender"></param>
result = /// <param name="e"></param>
_drawingTeplohod.MoveTransport(DirectionType.Up); private void ButtonCreateSportCar_Click(object sender, EventArgs e)
break;
case "buttonDown":
result =
_drawingTeplohod.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
result =
_drawingTeplohod.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
result =
_drawingTeplohod.MoveTransport(DirectionType.Right);
break;
}
if (result)
{ {
Random random = new();
_drawningTeplohod = new DrawningTeplohod();
_drawningTeplohod.Init(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)), Convert.ToBoolean(random.Next(0, 2)));
_drawningTeplohod.SetPictureSize(pictureBoxTeplohod.Width, pictureBoxTeplohod.Height);
_drawningTeplohod.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw(); Draw();
} }
/// <summary>
/// Перемещение объекта по форме (нажатие кнопок навигации)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawningTeplohod == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
bool result = false;
switch (name)
{
case "buttonUp":
result = _drawningTeplohod.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
result = _drawningTeplohod.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
result = _drawningTeplohod.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
result = _drawningTeplohod.MoveTransport(DirectionType.Right);
break;
}
if (result)
{
Draw();
}
}
} }
} }