d
This commit is contained in:
parent
a7bb259761
commit
fdba4a7bba
25
ArtilleryUnit/ArtilleryUnit.sln
Normal file
25
ArtilleryUnit/ArtilleryUnit.sln
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.9.34728.123
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArtilleryUnit", "ArtilleryUnit\ArtilleryUnit.csproj", "{BD69E8D6-7716-4B2C-8043-4D5F78273792}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{BD69E8D6-7716-4B2C-8043-4D5F78273792}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{BD69E8D6-7716-4B2C-8043-4D5F78273792}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{BD69E8D6-7716-4B2C-8043-4D5F78273792}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{BD69E8D6-7716-4B2C-8043-4D5F78273792}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {4D09057D-D11F-4AAC-80B5-29BBEC32C2B8}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
11
ArtilleryUnit/ArtilleryUnit/ArtilleryUnit.csproj
Normal file
11
ArtilleryUnit/ArtilleryUnit/ArtilleryUnit.csproj
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>net8.0-windows</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
23
ArtilleryUnit/ArtilleryUnit/DirectionType.cs
Normal file
23
ArtilleryUnit/ArtilleryUnit/DirectionType.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
namespace ProjectArtilleryUnit;
|
||||||
|
/// <summary>
|
||||||
|
/// Направление перемещения
|
||||||
|
/// </summary>
|
||||||
|
public enum DirectionType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Вверх
|
||||||
|
/// </summary>
|
||||||
|
Up = 1,
|
||||||
|
/// <summary>
|
||||||
|
/// Вниз
|
||||||
|
/// </summary>
|
||||||
|
Down = 2,
|
||||||
|
/// <summary>
|
||||||
|
/// Влево
|
||||||
|
/// </summary>
|
||||||
|
Left = 3,
|
||||||
|
/// <summary>
|
||||||
|
/// Вправо
|
||||||
|
/// </summary>
|
||||||
|
Right = 4
|
||||||
|
}
|
230
ArtilleryUnit/ArtilleryUnit/DrawningTank.cs
Normal file
230
ArtilleryUnit/ArtilleryUnit/DrawningTank.cs
Normal file
@ -0,0 +1,230 @@
|
|||||||
|
using ProjectArtilleryUnit;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
using System.Security.Cryptography.Xml;
|
||||||
|
|
||||||
|
namespace ProjectArtilleryUnit;
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
|
/// </summary>
|
||||||
|
public class DrawningArtilleryUnit
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-сущность
|
||||||
|
/// </summary>
|
||||||
|
public EntityArtilleryUnit? EntityArtilleryUnit { 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 _drawningArtilleryUnitWidth = 150;
|
||||||
|
/// <summary>
|
||||||
|
/// Высота прорисовки танка
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _drawningArtilleryUnitHeight = 50;
|
||||||
|
private readonly int _drawningEnginesWidth = 3;
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация свойств
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="motor">Признак наличия вертолетной площадки</param>
|
||||||
|
/// <param name="boat">Признак наличия шлюпок</param>
|
||||||
|
/// <param name="glass">Признак наличия пушки</param>
|
||||||
|
|
||||||
|
public void Init(int speed, double weight, Color bodyColor, Color
|
||||||
|
additionalColor, bool motor, bool boat, bool glass)
|
||||||
|
{
|
||||||
|
EntityArtilleryUnit = new EntityArtilleryUnit();
|
||||||
|
EntityArtilleryUnit.Init(speed, weight, bodyColor, additionalColor,
|
||||||
|
motor, boat, glass);
|
||||||
|
_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)
|
||||||
|
{
|
||||||
|
// TODO проверка, что объект "влезает" в размеры поля
|
||||||
|
// если влезает, сохраняем границы и корректируем позицию объекта,если она была уже установлена
|
||||||
|
|
||||||
|
if (_drawningArtilleryUnitHeight > height || _drawningArtilleryUnitWidth > width)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
_pictureWidth = width;
|
||||||
|
_pictureHeight = height;
|
||||||
|
|
||||||
|
if (_startPosX.HasValue && _startPosY.HasValue)
|
||||||
|
{
|
||||||
|
SetPosition(_startPosX.Value, _startPosY.Value + 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/// <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 + _drawningArtilleryUnitWidth > _pictureWidth || y < 0 || y + _drawningArtilleryUnitHeight > _pictureHeight)
|
||||||
|
{
|
||||||
|
_startPosX = _pictureWidth - _drawningArtilleryUnitWidth;
|
||||||
|
_startPosY = _pictureHeight - _drawningArtilleryUnitHeight;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_startPosX = x;
|
||||||
|
_startPosY = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Изменение направления перемещения
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="direction">Направление</param>
|
||||||
|
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||||
|
public bool MoveTransport(DirectionType direction)
|
||||||
|
{
|
||||||
|
if (EntityArtilleryUnit == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
switch (direction)
|
||||||
|
{
|
||||||
|
//влево
|
||||||
|
case DirectionType.Left:
|
||||||
|
if (_startPosX.Value - EntityArtilleryUnit.Step - _drawningEnginesWidth > 0)
|
||||||
|
{
|
||||||
|
_startPosX -= (int)EntityArtilleryUnit.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
//вверх
|
||||||
|
case DirectionType.Up:
|
||||||
|
if (_startPosY.Value - EntityArtilleryUnit.Step > 0)
|
||||||
|
{
|
||||||
|
_startPosY -= (int)EntityArtilleryUnit.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
// вправо
|
||||||
|
case DirectionType.Right:
|
||||||
|
//TODO прописать логику сдвига в право
|
||||||
|
if (_startPosX.Value + EntityArtilleryUnit.Step + _drawningArtilleryUnitWidth < _pictureWidth)
|
||||||
|
{
|
||||||
|
_startPosX += (int)EntityArtilleryUnit.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
//вниз
|
||||||
|
case DirectionType.Down:
|
||||||
|
if (_startPosY.Value + EntityArtilleryUnit.Step + _drawningArtilleryUnitHeight < _pictureHeight)
|
||||||
|
{
|
||||||
|
_startPosY += (int)EntityArtilleryUnit.Step;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Прорисовка объекта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="g"></param>
|
||||||
|
public void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityArtilleryUnit == null || !_startPosX.HasValue ||
|
||||||
|
!_startPosY.HasValue)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pen pen = new(EntityArtilleryUnit.BodyColor, 2);
|
||||||
|
Pen pen2 = new(Color.Black, 2);
|
||||||
|
Pen pen3 = new(Color.Black, 3);
|
||||||
|
Pen pen4 = new(Color.Red, 4);
|
||||||
|
Brush Brush = new SolidBrush(Color.Black);
|
||||||
|
Brush Brush2 = new SolidBrush(EntityArtilleryUnit.AdditionalColor);
|
||||||
|
Brush additionalBrush = new SolidBrush(EntityArtilleryUnit.AdditionalColor);
|
||||||
|
|
||||||
|
//границы танка
|
||||||
|
Point[] points = { new Point(_startPosX.Value + 60, _startPosY.Value + 6), new Point(_startPosX.Value + 110, _startPosY.Value + 6), new Point(_startPosX.Value + 110, _startPosY.Value + 11), new Point(_startPosX.Value + 80, _startPosY.Value + 21), new Point(_startPosX.Value + 60, _startPosY.Value + 21), new Point(_startPosX.Value + 45, _startPosY.Value + 16), new Point(_startPosX.Value + 45, _startPosY.Value + 11) };
|
||||||
|
|
||||||
|
g.DrawPolygon(pen, points);
|
||||||
|
g.FillPolygon(additionalBrush, points);
|
||||||
|
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 7, _startPosY.Value + 21, 132, 10);
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 7, _startPosY.Value + 21, 132, 10);
|
||||||
|
|
||||||
|
g.DrawArc(pen2, _startPosX.Value, _startPosY.Value + 6 + 22, 25, 25, 70, 200);
|
||||||
|
g.DrawArc(pen2, _startPosX.Value + 122, _startPosY.Value + 28, 25, 25, 260, 200);
|
||||||
|
g.DrawLine(pen2, _startPosX.Value + 10, _startPosY.Value + 29, _startPosX.Value + 135, _startPosY.Value + 29);
|
||||||
|
g.DrawLine(pen2, _startPosX.Value + 10, _startPosY.Value + 53, _startPosX.Value + 135, _startPosY.Value + 53);
|
||||||
|
g.DrawEllipse(pen3, _startPosX.Value + 5, _startPosY.Value + 31 , 18, 18);
|
||||||
|
g.DrawEllipse(pen3, _startPosX.Value + 125, _startPosY.Value + 31, 18, 18);
|
||||||
|
g.DrawEllipse(pen3, _startPosX.Value + 103, _startPosY.Value + 37, 12, 12);
|
||||||
|
g.DrawEllipse(pen3, _startPosX.Value + 34, _startPosY.Value + 37, 12, 12);
|
||||||
|
g.DrawEllipse(pen3, _startPosX.Value + 57, _startPosY.Value + 37, 12, 12);
|
||||||
|
g.DrawEllipse(pen3, _startPosX.Value + 80, _startPosY.Value + 37, 12, 12);
|
||||||
|
g.DrawArc(pen2, _startPosX.Value + 47, _startPosY.Value + 24, 10, 10, 0, 170);
|
||||||
|
g.DrawArc(pen2, _startPosX.Value + 70, _startPosY.Value + 24, 10, 10, 0, 170);
|
||||||
|
g.DrawArc(pen2, _startPosX.Value + 93, _startPosY.Value + 24, 10, 10, 0, 170);
|
||||||
|
|
||||||
|
//внутренности танка
|
||||||
|
|
||||||
|
if (EntityArtilleryUnit.Muzzle)
|
||||||
|
{
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 11, 35, 3);
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 11, 35, 3);
|
||||||
|
g.DrawPolygon(pen, points);
|
||||||
|
g.FillPolygon(additionalBrush, points);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EntityArtilleryUnit.Gun)
|
||||||
|
{
|
||||||
|
g.DrawLine(pen4, _startPosX.Value + 113, _startPosY.Value + 11, _startPosX.Value + 119, _startPosY.Value + 13);
|
||||||
|
g.DrawLine(pen4, _startPosX.Value + 115, _startPosY.Value + 6, _startPosX.Value + 121, _startPosY.Value + 8);
|
||||||
|
g.DrawLine(pen4, _startPosX.Value + 117, _startPosY.Value + 1, _startPosX.Value + 123, _startPosY.Value + 4);
|
||||||
|
|
||||||
|
Point[] points2 = { new Point(_startPosX.Value + 122, _startPosY.Value - 1), new Point(_startPosX.Value + 147, _startPosY.Value + 6), new Point(_startPosX.Value + 142, _startPosY.Value + 21), new Point(_startPosX.Value + 117, _startPosY.Value + 16)};
|
||||||
|
g.DrawPolygon(pen2, points2);
|
||||||
|
g.FillPolygon(Brush, points2);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (EntityArtilleryUnit.Luke)
|
||||||
|
{
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 60, _startPosY.Value + 4, 25, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
62
ArtilleryUnit/ArtilleryUnit/EntityTank.cs
Normal file
62
ArtilleryUnit/ArtilleryUnit/EntityTank.cs
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
namespace ProjectArtilleryUnit;
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-сущность "автобус"
|
||||||
|
/// </summary>
|
||||||
|
public class EntityArtilleryUnit
|
||||||
|
{
|
||||||
|
//свойства
|
||||||
|
/// <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 Muzzle { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак (опция) наличие лестницы
|
||||||
|
/// </summary>
|
||||||
|
public bool Gun { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак (опция) наличие фар
|
||||||
|
/// </summary>
|
||||||
|
public bool Luke { 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>
|
||||||
|
/// <param name="additionalColor">дополнительный цвет</param>
|
||||||
|
/// <param name="motor">второй этаж</param>
|
||||||
|
/// <param name="oars">лестница</param>
|
||||||
|
/// <param name="glass">наличие фар</param>
|
||||||
|
public void Init(int speed, double weight, Color bodyColor, Color
|
||||||
|
additionalColor, bool motor, bool oars, bool glass)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
AdditionalColor = additionalColor;
|
||||||
|
Muzzle = motor;
|
||||||
|
Gun = oars;
|
||||||
|
Luke = glass;
|
||||||
|
}
|
||||||
|
}
|
147
ArtilleryUnit/ArtilleryUnit/FormArtilleryUnit.Designer.cs
generated
Normal file
147
ArtilleryUnit/ArtilleryUnit/FormArtilleryUnit.Designer.cs
generated
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
|
||||||
|
namespace ProjectArtilleryUnit
|
||||||
|
{
|
||||||
|
partial class FormArtilleryUnit
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormArtilleryUnit));
|
||||||
|
pictureBox1 = new PictureBox();
|
||||||
|
button1 = new Button();
|
||||||
|
buttonUp = new Button();
|
||||||
|
buttonDown = new Button();
|
||||||
|
buttonRight = new Button();
|
||||||
|
buttonLeft = new Button();
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// pictureBox1
|
||||||
|
//
|
||||||
|
pictureBox1.Dock = DockStyle.Fill;
|
||||||
|
pictureBox1.Location = new Point(0, 0);
|
||||||
|
pictureBox1.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
pictureBox1.Name = "pictureBox1";
|
||||||
|
pictureBox1.Size = new Size(700, 338);
|
||||||
|
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||||
|
pictureBox1.TabIndex = 0;
|
||||||
|
pictureBox1.TabStop = false;
|
||||||
|
//
|
||||||
|
// button1
|
||||||
|
//
|
||||||
|
button1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
button1.Location = new Point(10, 307);
|
||||||
|
button1.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
button1.Name = "button1";
|
||||||
|
button1.Size = new Size(82, 22);
|
||||||
|
button1.TabIndex = 1;
|
||||||
|
button1.Text = "создать";
|
||||||
|
button1.UseVisualStyleBackColor = true;
|
||||||
|
button1.Click += ButtonCreateArtilleryUnit_Click;
|
||||||
|
//
|
||||||
|
// buttonUp
|
||||||
|
//
|
||||||
|
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage");
|
||||||
|
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonUp.Location = new Point(632, 280);
|
||||||
|
buttonUp.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
buttonUp.Name = "buttonUp";
|
||||||
|
buttonUp.Size = new Size(26, 22);
|
||||||
|
buttonUp.TabIndex = 2;
|
||||||
|
buttonUp.UseVisualStyleBackColor = true;
|
||||||
|
buttonUp.Click += ButtonMove_Click;
|
||||||
|
//
|
||||||
|
// buttonDown
|
||||||
|
//
|
||||||
|
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage");
|
||||||
|
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonDown.Location = new Point(632, 307);
|
||||||
|
buttonDown.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
buttonDown.Name = "buttonDown";
|
||||||
|
buttonDown.Size = new Size(26, 22);
|
||||||
|
buttonDown.TabIndex = 3;
|
||||||
|
buttonDown.UseVisualStyleBackColor = true;
|
||||||
|
buttonDown.Click += ButtonMove_Click;
|
||||||
|
//
|
||||||
|
// buttonRight
|
||||||
|
//
|
||||||
|
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage");
|
||||||
|
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonRight.Location = new Point(663, 307);
|
||||||
|
buttonRight.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
buttonRight.Name = "buttonRight";
|
||||||
|
buttonRight.Size = new Size(26, 22);
|
||||||
|
buttonRight.TabIndex = 4;
|
||||||
|
buttonRight.UseVisualStyleBackColor = true;
|
||||||
|
buttonRight.Click += ButtonMove_Click;
|
||||||
|
//
|
||||||
|
// buttonLeft
|
||||||
|
//
|
||||||
|
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
|
buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage");
|
||||||
|
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
|
buttonLeft.Location = new Point(600, 307);
|
||||||
|
buttonLeft.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
buttonLeft.Name = "buttonLeft";
|
||||||
|
buttonLeft.Size = new Size(26, 22);
|
||||||
|
buttonLeft.TabIndex = 5;
|
||||||
|
buttonLeft.UseVisualStyleBackColor = true;
|
||||||
|
buttonLeft.Click += ButtonMove_Click;
|
||||||
|
//
|
||||||
|
// FormArtilleryUnit
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(700, 338);
|
||||||
|
Controls.Add(buttonLeft);
|
||||||
|
Controls.Add(buttonRight);
|
||||||
|
Controls.Add(buttonDown);
|
||||||
|
Controls.Add(buttonUp);
|
||||||
|
Controls.Add(button1);
|
||||||
|
Controls.Add(pictureBox1);
|
||||||
|
Margin = new Padding(3, 2, 3, 2);
|
||||||
|
Name = "FormArtilleryUnit";
|
||||||
|
Text = "FormArtilleryUnit";
|
||||||
|
//Load += this.FormArtilleryUnit_Load_1;
|
||||||
|
Click += ButtonMove_Click;
|
||||||
|
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private PictureBox pictureBox1;
|
||||||
|
private Button button1;
|
||||||
|
private Button buttonUp;
|
||||||
|
private Button buttonDown;
|
||||||
|
private Button buttonRight;
|
||||||
|
private Button buttonLeft;
|
||||||
|
}
|
||||||
|
}
|
91
ArtilleryUnit/ArtilleryUnit/FormArtilleryUnit.cs
Normal file
91
ArtilleryUnit/ArtilleryUnit/FormArtilleryUnit.cs
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
namespace ProjectArtilleryUnit
|
||||||
|
{
|
||||||
|
public partial class FormArtilleryUnit : Form
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Поле-объект для прорисовки объекта
|
||||||
|
/// </summary>
|
||||||
|
private DrawningArtilleryUnit? _drawningArtilleryUnit;
|
||||||
|
public FormArtilleryUnit()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Метод прорисовки круисера
|
||||||
|
/// </summary>
|
||||||
|
private void Draw()
|
||||||
|
{
|
||||||
|
if (_drawningArtilleryUnit == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Bitmap bmp = new(pictureBox1.Width,
|
||||||
|
pictureBox1.Height);
|
||||||
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
|
_drawningArtilleryUnit.DrawTransport(gr);
|
||||||
|
pictureBox1.Image = bmp;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия кнопки "Создать"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonCreateArtilleryUnit_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Random random = new();
|
||||||
|
_drawningArtilleryUnit = new DrawningArtilleryUnit();
|
||||||
|
_drawningArtilleryUnit.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)));
|
||||||
|
_drawningArtilleryUnit.SetPictureSize(pictureBox1.Width,
|
||||||
|
pictureBox1.Height);
|
||||||
|
|
||||||
|
//начальное положение круисера
|
||||||
|
_drawningArtilleryUnit.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_drawningArtilleryUnit == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||||
|
bool result = false;
|
||||||
|
switch (name)
|
||||||
|
{
|
||||||
|
case "buttonUp":
|
||||||
|
result =
|
||||||
|
_drawningArtilleryUnit.MoveTransport(DirectionType.Up);
|
||||||
|
break;
|
||||||
|
case "buttonDown":
|
||||||
|
result =
|
||||||
|
_drawningArtilleryUnit.MoveTransport(DirectionType.Down);
|
||||||
|
break;
|
||||||
|
case "buttonLeft":
|
||||||
|
result =
|
||||||
|
_drawningArtilleryUnit.MoveTransport(DirectionType.Left);
|
||||||
|
break;
|
||||||
|
case "buttonRight":
|
||||||
|
result =
|
||||||
|
_drawningArtilleryUnit.MoveTransport(DirectionType.Right);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1540
ArtilleryUnit/ArtilleryUnit/FormArtilleryUnit.resx
Normal file
1540
ArtilleryUnit/ArtilleryUnit/FormArtilleryUnit.resx
Normal file
File diff suppressed because it is too large
Load Diff
17
ArtilleryUnit/ArtilleryUnit/Program.cs
Normal file
17
ArtilleryUnit/ArtilleryUnit/Program.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
namespace ProjectArtilleryUnit
|
||||||
|
{
|
||||||
|
internal static class Program
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The main entry point for the application.
|
||||||
|
/// </summary>
|
||||||
|
[STAThread]
|
||||||
|
static void Main()
|
||||||
|
{
|
||||||
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
|
// see https://aka.ms/applicationconfiguration.
|
||||||
|
ApplicationConfiguration.Initialize();
|
||||||
|
Application.Run(new FormArtilleryUnit());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user