lab1
This commit is contained in:
parent
1451b8763d
commit
0d434bbfa0
25
ProjectCruiser.sln
Normal file
25
ProjectCruiser.sln
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.7.34024.191
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProjectCruiser", "ProjectCruiser\ProjectCruiser.csproj", "{3BF07215-1029-4175-8FF7-2D2CFA321CC6}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{3BF07215-1029-4175-8FF7-2D2CFA321CC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3BF07215-1029-4175-8FF7-2D2CFA321CC6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3BF07215-1029-4175-8FF7-2D2CFA321CC6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3BF07215-1029-4175-8FF7-2D2CFA321CC6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {FAA09B63-E9F8-4270-B6B1-2D064FB5399F}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
23
ProjectCruiser/DirectionType.cs
Normal file
23
ProjectCruiser/DirectionType.cs
Normal file
@ -0,0 +1,23 @@
|
||||
namespace ProjectCruiser;
|
||||
/// <summary>
|
||||
/// Íàïðàâëåíèå ïåðåìåùåíèÿ
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Ââåðõ
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
||||
/// Âíèç
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
/// <summary>
|
||||
/// Âëåâî
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
/// <summary>
|
||||
/// Âïðàâî
|
||||
/// </summary>
|
||||
Right = 4
|
||||
}
|
235
ProjectCruiser/DrawningCruiser.cs
Normal file
235
ProjectCruiser/DrawningCruiser.cs
Normal file
@ -0,0 +1,235 @@
|
||||
using ProjectCruiser;
|
||||
using System.Drawing.Drawing2D;
|
||||
|
||||
namespace ProjectCruiser;
|
||||
/// <summary>
|
||||
/// Êëàññ, îòâå÷àþùèé çà ïðîðèñîâêó è ïåðåìåùåíèå îáúåêòà-ñóùíîñòè
|
||||
/// </summary>
|
||||
public class DrawningCruiser
|
||||
{
|
||||
/// <summary>
|
||||
/// Êëàññ-ñóùíîñòü
|
||||
/// </summary>
|
||||
public EntityCruiser? EntityCruiser { 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 _drawningCruiserWidth = 110;
|
||||
/// <summary>
|
||||
/// Âûñîòà ïðîðèñîâêè àâòîìîáèëÿ
|
||||
/// </summary>
|
||||
private readonly int _drawningCruiserHeight = 60;
|
||||
/// <summary>
|
||||
/// Èíèöèàëèçàöèÿ ñâîéñòâ
|
||||
/// </summary>
|
||||
/// <param name="speed">Ñêîðîñòü</param>
|
||||
/// <param name="weight">Âåñ</param>
|
||||
/// <param name="bodyColor">Îñíîâíîé öâåò</param>
|
||||
/// <param name="additionalColor">Äîïîëíèòåëüíûé öâåò</param>
|
||||
/// <param name="helicopterArea">Ïðèçíàê íàëè÷èÿ îáâåñà</param>
|
||||
/// <param name="boat">Ïðèçíàê íàëè÷èÿ àíòèêðûëà</param>
|
||||
/// <param name="wepon">Ïðèçíàê íàëè÷èÿ ãîíî÷íîé ïîëîñû</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool helicopterArea, bool boat, bool wepon)
|
||||
{
|
||||
EntityCruiser = new EntityCruiser();
|
||||
EntityCruiser.Init(speed, weight, bodyColor, additionalColor,
|
||||
helicopterArea, boat, wepon);
|
||||
_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 (_startPosX + 150 > width)
|
||||
{
|
||||
_startPosX -= (_startPosX + 150) - width;
|
||||
}
|
||||
if (_startPosY + 80 > height)
|
||||
{
|
||||
_startPosY -= (_startPosY + 80) - height;
|
||||
}
|
||||
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
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 + 150 > _pictureWidth)
|
||||
{
|
||||
x -= (x+150) - _pictureWidth.Value;
|
||||
}
|
||||
|
||||
if (y + 50 > _pictureHeight)
|
||||
{
|
||||
y -= (y+50) - _pictureHeight.Value;
|
||||
}
|
||||
// TODO åñëè ïðè óñòàíîâêå îáúåêòà â ýòè êîîðäèíàòû, îí áóäåò "âûõîäèòü" çà ãðàíèöû ôîðìû
|
||||
// òî íàäî èçìåíèòü êîîðäèíàòû, ÷òîáû îí îñòàâàëñÿ â ýòèõ ãðàíèöàõ
|
||||
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Èçìåíåíèå íàïðàâëåíèÿ ïåðåìåùåíèÿ
|
||||
/// </summary>
|
||||
/// <param name="direction">Íàïðàâëåíèå</param>
|
||||
/// <returns>true - ïåðåìåùåíå âûïîëíåíî, false - ïåðåìåùåíèå íåâîçìîæíî</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityCruiser == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//âëåâî
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityCruiser.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityCruiser.Step;
|
||||
}
|
||||
|
||||
return true;
|
||||
//ââåðõ
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityCruiser.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityCruiser.Step;
|
||||
}
|
||||
return true;
|
||||
// âïðàâî
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value >= 640)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
//TODO ïðîïèñàòü ëîãèêó ñäâèãà â ïðàâî
|
||||
if (_startPosX.Value + EntityCruiser.Step > 0)
|
||||
{
|
||||
_startPosX += (int)EntityCruiser.Step;
|
||||
}
|
||||
return true;
|
||||
//âíèç
|
||||
case DirectionType.Down:
|
||||
//TODO ïðîïèñàòü ëîãèêó ñäâèãà â âíèç
|
||||
if(_startPosY.Value >= 390)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (_startPosY.Value + EntityCruiser.Step > 0)
|
||||
{
|
||||
_startPosY += (int)EntityCruiser.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Ïðîðèñîâêà îáúåêòà
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityCruiser == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black, 2);
|
||||
Brush additionalBrush = new SolidBrush(Color.Black);
|
||||
Brush weaponBrush = new SolidBrush(Color.Black);
|
||||
Brush weaponBrush2 = new SolidBrush(EntityCruiser.AdditionalColor);
|
||||
Brush helicopterAreaBrush = new HatchBrush(HatchStyle.ZigZag, EntityCruiser.AdditionalColor, Color.FromArgb(163, 163, 163));
|
||||
Brush boatBrush = new SolidBrush(EntityCruiser.AdditionalColor);
|
||||
|
||||
//ãðàíèöû êðóèñåðà
|
||||
|
||||
g.DrawLine(pen, _startPosX.Value, _startPosY.Value, _startPosX.Value + 105, _startPosY.Value);
|
||||
g.DrawLine(pen, _startPosX.Value + 105, _startPosY.Value, _startPosX.Value + 147, _startPosY.Value + 24);
|
||||
|
||||
g.DrawLine(pen, _startPosX.Value, _startPosY.Value + 49, _startPosX.Value + 105, _startPosY.Value + 49);
|
||||
g.DrawLine(pen, _startPosX.Value + 105, _startPosY.Value + 49, _startPosX.Value + 147, _startPosY.Value + 24);
|
||||
|
||||
g.DrawLine(pen, _startPosX.Value, _startPosY.Value, _startPosX.Value, _startPosY.Value + 49);
|
||||
|
||||
//âíóòðåííîñòè êðóèñåðà
|
||||
g.DrawEllipse(pen, _startPosX.Value + 94, _startPosY.Value + 14, 19, 19);
|
||||
|
||||
g.DrawRectangle(pen, _startPosX.Value + 63, _startPosY.Value + 11, 21, 28);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 17, 28, 14);
|
||||
|
||||
//çàä
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value - 3, _startPosY.Value + 7, 3, 14);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value - 3, _startPosY.Value + 26, 3, 14);
|
||||
|
||||
if (EntityCruiser.HelicopterArea)
|
||||
{
|
||||
g.FillEllipse(helicopterAreaBrush, _startPosX.Value + 5, _startPosY.Value + 9, 25, 30);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 5, _startPosY.Value + 9, 25, 30);
|
||||
}
|
||||
|
||||
if (EntityCruiser.Boat)
|
||||
{
|
||||
g.DrawEllipse(pen, _startPosX.Value + 34, _startPosY.Value + 2, 30, 7);
|
||||
g.FillEllipse(boatBrush, _startPosX.Value + 34, _startPosY.Value + 2, 30, 7);
|
||||
|
||||
g.DrawEllipse(pen, _startPosX.Value + 34, _startPosY.Value + 39, 30, 7);
|
||||
g.FillEllipse(boatBrush, _startPosX.Value + 34, _startPosY.Value + 39, 30, 7);
|
||||
}
|
||||
|
||||
if (EntityCruiser.Weapon)
|
||||
{
|
||||
g.DrawEllipse(pen, _startPosX.Value + 97, _startPosY.Value + 36, 10, 10);
|
||||
g.FillEllipse(weaponBrush2, _startPosX.Value + 97, _startPosY.Value + 36, 10, 10);
|
||||
|
||||
|
||||
g.FillRectangle(weaponBrush, _startPosX.Value + 107, _startPosY.Value + 40, 15, 5);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
61
ProjectCruiser/EntityCruiser.cs
Normal file
61
ProjectCruiser/EntityCruiser.cs
Normal file
@ -0,0 +1,61 @@
|
||||
namespace ProjectCruiser;
|
||||
/// <summary>
|
||||
/// Класс-сущность "крейсер"
|
||||
/// </summary>
|
||||
public class EntityCruiser
|
||||
{
|
||||
/// <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 HelicopterArea { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличие шлюпок
|
||||
/// </summary>
|
||||
|
||||
public bool Boat { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличие тц
|
||||
/// </summary>
|
||||
public bool Weapon { 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="helicopterArea">вертолетная площадка</param>
|
||||
/// <param name="boat">шлюпки</param>
|
||||
/// <param name="wepon">наличие тц</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool helicopterArea, bool boat, bool wepon)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
HelicopterArea = helicopterArea;
|
||||
Boat = boat;
|
||||
Weapon = wepon;
|
||||
}
|
||||
}
|
39
ProjectCruiser/Form1.Designer.cs
generated
39
ProjectCruiser/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
||||
namespace ProjectCruiser
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Text = "Form1";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace ProjectCruiser
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
138
ProjectCruiser/FormCruiser.Designer.cs
generated
Normal file
138
ProjectCruiser/FormCruiser.Designer.cs
generated
Normal file
@ -0,0 +1,138 @@
|
||||
namespace ProjectCruiser
|
||||
{
|
||||
partial class FormCruiser
|
||||
{
|
||||
/// <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(FormCruiser));
|
||||
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.Name = "pictureBox1";
|
||||
pictureBox1.Size = new Size(800, 450);
|
||||
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
pictureBox1.TabIndex = 0;
|
||||
pictureBox1.TabStop = false;
|
||||
//
|
||||
// button1
|
||||
//
|
||||
button1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
button1.Location = new Point(12, 409);
|
||||
button1.Name = "button1";
|
||||
button1.Size = new Size(94, 29);
|
||||
button1.TabIndex = 1;
|
||||
button1.Text = "создать";
|
||||
button1.UseVisualStyleBackColor = true;
|
||||
button1.Click += ButtonCreateCruiser_Click;
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage");
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonUp.Location = new Point(722, 373);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(30, 30);
|
||||
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(722, 409);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(30, 30);
|
||||
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(758, 409);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(30, 30);
|
||||
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(686, 409);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(30, 30);
|
||||
buttonLeft.TabIndex = 5;
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += ButtonMove_Click;
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(button1);
|
||||
Controls.Add(pictureBox1);
|
||||
Name = "Form1";
|
||||
Text = "FormCruiser";
|
||||
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;
|
||||
}
|
||||
}
|
100
ProjectCruiser/FormCruiser.cs
Normal file
100
ProjectCruiser/FormCruiser.cs
Normal file
@ -0,0 +1,100 @@
|
||||
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 ProjectCruiser
|
||||
{
|
||||
public partial class FormCruiser : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningCruiser? _drawningCruiser;
|
||||
public FormCruiser()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Метод прорисовки машины
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningCruiser == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBox1.Width,
|
||||
pictureBox1.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningCruiser.DrawTransport(gr);
|
||||
pictureBox1.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateCruiser_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningCruiser = new DrawningCruiser();
|
||||
_drawningCruiser.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)));
|
||||
_drawningCruiser.SetPictureSize(pictureBox1.Width,
|
||||
pictureBox1.Height);
|
||||
_drawningCruiser.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 (_drawningCruiser == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
bool result = false;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result =
|
||||
_drawningCruiser.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result =
|
||||
_drawningCruiser.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result =
|
||||
_drawningCruiser.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result =
|
||||
_drawningCruiser.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
{
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
1540
ProjectCruiser/FormCruiser.resx
Normal file
1540
ProjectCruiser/FormCruiser.resx
Normal file
File diff suppressed because it is too large
Load Diff
@ -11,7 +11,7 @@ namespace ProjectCruiser
|
||||
// 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 FormCruiser());
|
||||
}
|
||||
}
|
||||
}
|
@ -8,4 +8,19 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
63
ProjectCruiser/Properties/Resources.Designer.cs
generated
Normal file
63
ProjectCruiser/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,63 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// Этот код создан программой.
|
||||
// Исполняемая версия:4.0.30319.42000
|
||||
//
|
||||
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||
// повторной генерации кода.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ProjectCruiser.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
|
||||
/// </summary>
|
||||
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
|
||||
// с помощью такого средства, как ResGen или Visual Studio.
|
||||
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
|
||||
// с параметром /str или перестройте свой проект VS.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ProjectCruiser.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
|
||||
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user