Лабораторная работа №1
This commit is contained in:
parent
906f781d5f
commit
33f58a2310
@ -1,4 +1,7 @@
|
|||||||
namespace ProjectMotorBoat;
|
using System;
|
||||||
|
using System.DirectoryServices.ActiveDirectory;
|
||||||
|
|
||||||
|
namespace ProjectMotorBoat;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
@ -34,12 +37,12 @@ public class DrawingMotorBoat
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина прорисовки катера
|
/// Ширина прорисовки катера
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawningBoatWidth = 110;
|
private readonly int _drawningBoatWidth = 100;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота прорисовки катера
|
/// Высота прорисовки катера
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawningBoatHeight = 60;
|
private readonly int _drawningBoatHeight = 50;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация свойств
|
/// Инициализация свойств
|
||||||
@ -70,9 +73,25 @@ public class DrawingMotorBoat
|
|||||||
public bool SetPictureSize(int width, int height)
|
public bool SetPictureSize(int width, int height)
|
||||||
{
|
{
|
||||||
// TODO проверка, что объект "влезает" в размеры поля
|
// TODO проверка, что объект "влезает" в размеры поля
|
||||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена ✔
|
||||||
|
if (_drawningBoatWidth < width)
|
||||||
|
{
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
|
if (_startPosX + _drawningBoatWidth > _pictureWidth)
|
||||||
|
{
|
||||||
|
_startPosX = _pictureWidth - _drawningBoatWidth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_drawningBoatHeight < height)
|
||||||
|
{
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
|
if (_startPosY + _drawningBoatHeight > _pictureHeight)
|
||||||
|
{
|
||||||
|
_startPosY = _pictureHeight - _drawningBoatHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +107,17 @@ public class DrawingMotorBoat
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
// то надо изменить координаты, чтобы он оставался в этих границах ✔
|
||||||
|
if (x + _drawningBoatWidth > _pictureWidth)
|
||||||
|
{
|
||||||
|
x = (int)_pictureWidth - _drawningBoatWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y + _drawningBoatHeight > _pictureHeight)
|
||||||
|
{
|
||||||
|
y = (int)_pictureHeight - _drawningBoatHeight;
|
||||||
|
}
|
||||||
|
|
||||||
_startPosX = x;
|
_startPosX = x;
|
||||||
_startPosY = y;
|
_startPosY = y;
|
||||||
}
|
}
|
||||||
@ -123,21 +152,21 @@ public class DrawingMotorBoat
|
|||||||
return true;
|
return true;
|
||||||
// вправо
|
// вправо
|
||||||
case DirectionType.Right:
|
case DirectionType.Right:
|
||||||
//TODO прописать логику сдвига в право
|
//TODO прописать логику сдвига в право ✔
|
||||||
|
|
||||||
//if (_startPosX.Value + EntityMotorBoat.Step < _pictureWidth)
|
if (_startPosX.Value + EntityMotorBoat.Step < _pictureWidth - _drawningBoatWidth)
|
||||||
//{
|
{
|
||||||
// _startPosX += (int)EntityMotorBoat.Step;
|
_startPosX += (int)EntityMotorBoat.Step;
|
||||||
//}
|
}
|
||||||
return true;
|
return true;
|
||||||
//вниз
|
//вниз
|
||||||
case DirectionType.Down:
|
case DirectionType.Down:
|
||||||
//TODO прописать логику сдвига в низ
|
//TODO прописать логику сдвига в низ ✔
|
||||||
|
|
||||||
//if (_startPosY.Value + EntityMotorBoat.Step < _pictureHeight)
|
if (_startPosY.Value + EntityMotorBoat.Step < _pictureHeight - _drawningBoatHeight)
|
||||||
//{
|
{
|
||||||
// _startPosY += (int)EntityMotorBoat.Step;
|
_startPosY += (int)EntityMotorBoat.Step;
|
||||||
//}
|
}
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
@ -154,5 +183,90 @@ public class DrawingMotorBoat
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush additionalBrush = new SolidBrush(EntityMotorBoat.AdditionalColor);
|
||||||
|
Brush br = new SolidBrush(EntityMotorBoat.BodyColor);
|
||||||
|
|
||||||
|
// Границы катера
|
||||||
|
Point[] points =
|
||||||
|
{
|
||||||
|
new Point(_startPosX.Value, _startPosY.Value + 10),
|
||||||
|
new Point(_startPosX.Value + 70, _startPosY.Value + 10),
|
||||||
|
new Point(_startPosX.Value + 100, _startPosY.Value + 25),
|
||||||
|
new Point(_startPosX.Value + 70, _startPosY.Value + 40),
|
||||||
|
new Point(_startPosX.Value, _startPosY.Value + 40),
|
||||||
|
new Point(_startPosX.Value, _startPosY.Value + 10),
|
||||||
|
};
|
||||||
|
g.DrawLines(pen, points);
|
||||||
|
|
||||||
|
points = new Point[]
|
||||||
|
{
|
||||||
|
new Point(_startPosX.Value + 1, _startPosY.Value + 11),
|
||||||
|
new Point(_startPosX.Value + 72, _startPosY.Value + 11),
|
||||||
|
new Point(_startPosX.Value + 99, _startPosY.Value + 25),
|
||||||
|
new Point(_startPosX.Value + 70, _startPosY.Value + 40),
|
||||||
|
new Point(_startPosX.Value + 1, _startPosY.Value + 40),
|
||||||
|
new Point(_startPosX.Value + 1, _startPosY.Value + 11),
|
||||||
|
};
|
||||||
|
g.FillPolygon(br, points);
|
||||||
|
|
||||||
|
// Палуба
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 20, 65, 10);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 15, 55, 20);
|
||||||
|
|
||||||
|
g.FillRectangle(br, _startPosX.Value + 6, _startPosY.Value + 20, 64, 11);
|
||||||
|
g.FillRectangle(br, _startPosX.Value + 11, _startPosY.Value + 16, 56, 19);
|
||||||
|
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 5, _startPosY.Value + 15, 10, 10);
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 60, _startPosY.Value + 15, 10, 10);
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 5, _startPosY.Value + 25, 10, 10);
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 60, _startPosY.Value + 25, 10, 10);
|
||||||
|
|
||||||
|
g.FillEllipse(br, _startPosX.Value + 5, _startPosY.Value + 15, 11, 11);
|
||||||
|
g.FillEllipse(br, _startPosX.Value + 59, _startPosY.Value + 15, 11, 11);
|
||||||
|
g.FillEllipse(br, _startPosX.Value + 5, _startPosY.Value + 24, 11, 11);
|
||||||
|
g.FillEllipse(br, _startPosX.Value + 59, _startPosY.Value + 24, 11, 11);
|
||||||
|
|
||||||
|
// Мотор в корме
|
||||||
|
if (EntityMotorBoat.InboardEngine)
|
||||||
|
{
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 3, _startPosY.Value + 13, 20, 24);
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 4, _startPosY.Value + 14, 19, 23);
|
||||||
|
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 5, _startPosY.Value + 15, 6, 6);
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 14, _startPosY.Value + 15, 6, 6);
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 5, _startPosY.Value + 28, 6, 6);
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 14, _startPosY.Value + 28, 6, 6);
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 6, _startPosY.Value + 16, 4, 4);
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 15, _startPosY.Value + 16, 4, 4);
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 6, _startPosY.Value + 29, 4, 4);
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 15, _startPosY.Value + 29, 4, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Вёсла
|
||||||
|
if (EntityMotorBoat.Paddle)
|
||||||
|
{
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 32, _startPosY.Value + 3, 2, 17);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 32, _startPosY.Value + 30, 2, 17);
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 33, _startPosY.Value + 3, 1, 17);
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 33, _startPosY.Value + 31, 1, 16);
|
||||||
|
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value, 6, 8);
|
||||||
|
g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 42, 6, 8);
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 30, _startPosY.Value, 6, 8);
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 42, 6, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Защитное стекло
|
||||||
|
if (EntityMotorBoat.ProtectiveGlass)
|
||||||
|
{
|
||||||
|
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||||
|
g.FillRectangle(brBlue, _startPosX.Value + 45, _startPosY.Value + 20, 25, 11);
|
||||||
|
g.FillRectangle(brBlue, _startPosX.Value + 45, _startPosY.Value + 16, 17, 19);
|
||||||
|
|
||||||
|
g.FillEllipse(brBlue, _startPosX.Value + 59, _startPosY.Value + 15, 11, 11);
|
||||||
|
g.FillEllipse(brBlue, _startPosX.Value + 59, _startPosY.Value + 24, 11, 11);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -29,7 +29,7 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
pictureBoxMotorBoat = new PictureBox();
|
pictureBoxMotorBoat = new PictureBox();
|
||||||
buttonCreate = new Button();
|
buttonCreateMotorBoat = new Button();
|
||||||
buttonLeft = new Button();
|
buttonLeft = new Button();
|
||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
@ -47,16 +47,16 @@
|
|||||||
pictureBoxMotorBoat.TabIndex = 0;
|
pictureBoxMotorBoat.TabIndex = 0;
|
||||||
pictureBoxMotorBoat.TabStop = false;
|
pictureBoxMotorBoat.TabStop = false;
|
||||||
//
|
//
|
||||||
// buttonCreate
|
// buttonCreateMotorBoat
|
||||||
//
|
//
|
||||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
buttonCreateMotorBoat.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
buttonCreate.Location = new Point(12, 448);
|
buttonCreateMotorBoat.Location = new Point(12, 448);
|
||||||
buttonCreate.Name = "buttonCreate";
|
buttonCreateMotorBoat.Name = "buttonCreateMotorBoat";
|
||||||
buttonCreate.Size = new Size(75, 23);
|
buttonCreateMotorBoat.Size = new Size(75, 23);
|
||||||
buttonCreate.TabIndex = 1;
|
buttonCreateMotorBoat.TabIndex = 1;
|
||||||
buttonCreate.Text = "Создать";
|
buttonCreateMotorBoat.Text = "Создать";
|
||||||
buttonCreate.UseVisualStyleBackColor = true;
|
buttonCreateMotorBoat.UseVisualStyleBackColor = true;
|
||||||
buttonCreate.Click += ButtonCreate_Click;
|
buttonCreateMotorBoat.Click += ButtonCreateMotorBoat_Click;
|
||||||
//
|
//
|
||||||
// buttonLeft
|
// buttonLeft
|
||||||
//
|
//
|
||||||
@ -68,6 +68,7 @@
|
|||||||
buttonLeft.Size = new Size(35, 35);
|
buttonLeft.Size = new Size(35, 35);
|
||||||
buttonLeft.TabIndex = 2;
|
buttonLeft.TabIndex = 2;
|
||||||
buttonLeft.UseVisualStyleBackColor = true;
|
buttonLeft.UseVisualStyleBackColor = true;
|
||||||
|
buttonLeft.Click += ButtonMoveMotorBoat_click;
|
||||||
//
|
//
|
||||||
// buttonUp
|
// buttonUp
|
||||||
//
|
//
|
||||||
@ -79,6 +80,7 @@
|
|||||||
buttonUp.Size = new Size(35, 35);
|
buttonUp.Size = new Size(35, 35);
|
||||||
buttonUp.TabIndex = 3;
|
buttonUp.TabIndex = 3;
|
||||||
buttonUp.UseVisualStyleBackColor = true;
|
buttonUp.UseVisualStyleBackColor = true;
|
||||||
|
buttonUp.Click += ButtonMoveMotorBoat_click;
|
||||||
//
|
//
|
||||||
// buttonRight
|
// buttonRight
|
||||||
//
|
//
|
||||||
@ -90,6 +92,7 @@
|
|||||||
buttonRight.Size = new Size(35, 35);
|
buttonRight.Size = new Size(35, 35);
|
||||||
buttonRight.TabIndex = 4;
|
buttonRight.TabIndex = 4;
|
||||||
buttonRight.UseVisualStyleBackColor = true;
|
buttonRight.UseVisualStyleBackColor = true;
|
||||||
|
buttonRight.Click += ButtonMoveMotorBoat_click;
|
||||||
//
|
//
|
||||||
// buttonDown
|
// buttonDown
|
||||||
//
|
//
|
||||||
@ -101,6 +104,7 @@
|
|||||||
buttonDown.Size = new Size(35, 35);
|
buttonDown.Size = new Size(35, 35);
|
||||||
buttonDown.TabIndex = 5;
|
buttonDown.TabIndex = 5;
|
||||||
buttonDown.UseVisualStyleBackColor = true;
|
buttonDown.UseVisualStyleBackColor = true;
|
||||||
|
buttonDown.Click += ButtonMoveMotorBoat_click;
|
||||||
//
|
//
|
||||||
// FormMotorBoat
|
// FormMotorBoat
|
||||||
//
|
//
|
||||||
@ -111,7 +115,7 @@
|
|||||||
Controls.Add(buttonRight);
|
Controls.Add(buttonRight);
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
Controls.Add(buttonLeft);
|
Controls.Add(buttonLeft);
|
||||||
Controls.Add(buttonCreate);
|
Controls.Add(buttonCreateMotorBoat);
|
||||||
Controls.Add(pictureBoxMotorBoat);
|
Controls.Add(pictureBoxMotorBoat);
|
||||||
Name = "FormMotorBoat";
|
Name = "FormMotorBoat";
|
||||||
Text = "Катер";
|
Text = "Катер";
|
||||||
@ -123,7 +127,7 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private PictureBox pictureBoxMotorBoat;
|
private PictureBox pictureBoxMotorBoat;
|
||||||
private Button buttonCreate;
|
private Button buttonCreateMotorBoat;
|
||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
|
@ -1,25 +1,45 @@
|
|||||||
using System;
|
namespace ProjectMotorBoat;
|
||||||
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 ProjectMotorBoat
|
/// <summary>
|
||||||
|
/// Форма работы с объектом "Катер"
|
||||||
|
/// </summary>
|
||||||
|
public partial class FormMotorBoat : Form
|
||||||
{
|
{
|
||||||
public partial class FormMotorBoat : Form
|
/// <summary>
|
||||||
{
|
/// Поле-объект для прорисовки объекта
|
||||||
|
/// </summary>
|
||||||
private DrawingMotorBoat? _drawingMotorBoat;
|
private DrawingMotorBoat? _drawingMotorBoat;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор формы
|
||||||
|
/// </summary>
|
||||||
public FormMotorBoat()
|
public FormMotorBoat()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
/// <summary>
|
||||||
|
/// Метод прорисовки катера
|
||||||
|
/// </summary>
|
||||||
|
private void Draw()
|
||||||
|
{
|
||||||
|
if (_drawingMotorBoat == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Bitmap bmp = new(pictureBoxMotorBoat.Width, pictureBoxMotorBoat.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_drawingMotorBoat.DrawTransport(gr);
|
||||||
|
pictureBoxMotorBoat.Image = bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия кнопки "Создать"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonCreateMotorBoat_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new();
|
Random random = new();
|
||||||
_drawingMotorBoat = new DrawingMotorBoat();
|
_drawingMotorBoat = new DrawingMotorBoat();
|
||||||
@ -31,11 +51,42 @@ namespace ProjectMotorBoat
|
|||||||
_drawingMotorBoat.SetPictureSize(pictureBoxMotorBoat.Width, pictureBoxMotorBoat.Height);
|
_drawingMotorBoat.SetPictureSize(pictureBoxMotorBoat.Width, pictureBoxMotorBoat.Height);
|
||||||
_drawingMotorBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
_drawingMotorBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
|
||||||
Bitmap bmp = new(pictureBoxMotorBoat.Width, pictureBoxMotorBoat.Height);
|
Draw();
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
}
|
||||||
_drawingMotorBoat.DrawTransport(gr);
|
|
||||||
pictureBoxMotorBoat.Image = bmp;
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonMoveMotorBoat_click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawingMotorBoat == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
|
bool result = false;
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "buttonUp":
|
||||||
|
result = _drawingMotorBoat.MoveTransport(DirectionType.Up);
|
||||||
|
break;
|
||||||
|
case "buttonDown":
|
||||||
|
result = _drawingMotorBoat.MoveTransport(DirectionType.Down);
|
||||||
|
break;
|
||||||
|
case "buttonLeft":
|
||||||
|
result = _drawingMotorBoat.MoveTransport(DirectionType.Left);
|
||||||
|
break;
|
||||||
|
case "buttonRight":
|
||||||
|
result = _drawingMotorBoat.MoveTransport(DirectionType.Right);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<TargetFramework>net7.0-windows</TargetFramework>
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<UseWindowsForms>true</UseWindowsForms>
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user