Potapov N.S. LabWork01 #3
@ -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>
|
19
Boats/Boats/Direction.cs
Normal file
19
Boats/Boats/Direction.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Boats
|
||||
|
||||
{
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
internal enum Direction
|
||||
{
|
||||
Up = 1,
|
||||
Down = 2,
|
||||
Left = 3,
|
||||
Right = 4
|
||||
}
|
||||
}
|
169
Boats/Boats/DrawingBoat.cs
Normal file
169
Boats/Boats/DrawingBoat.cs
Normal file
@ -0,0 +1,169 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Boats
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
internal class DrawingBoat
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityBoat Boat { private set; get; }
|
||||
/// <summary>
|
||||
/// Левая координата отрисовки лодки
|
||||
/// </summary>
|
||||
private float _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната отрисовки лодки
|
||||
/// </summary>
|
||||
private float _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private int? _pictureWidth = null;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private int? _pictureHeight = null;
|
||||
/// <summary>
|
||||
/// Ширина отрисовки лодки
|
||||
/// </summary>
|
||||
private readonly int _boatWidth = 100;
|
||||
/// <summary>
|
||||
/// Высота отрисовки лодки
|
||||
/// </summary>
|
||||
private readonly int _boatHeight = 40;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес лодки</param>
|
||||
/// <param name="bodyColor">Цвет корпуса</param>
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Boat = new EntityBoat();
|
||||
Boat.Init(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции лодки
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
{
|
||||
// Проверки, что новая позиция и размеры валидны
|
||||
if (x > 0 && x < width - _boatWidth && y > 0 && y < height - _boatHeight)
|
||||
{
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
public void MoveTransport(Direction direction)
|
||||
{
|
||||
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
// вправо
|
||||
case Direction.Right:
|
||||
if (_startPosX + _boatWidth + Boat.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += Boat.Step;
|
||||
}
|
||||
break;
|
||||
//влево
|
||||
case Direction.Left:
|
||||
if (_startPosX - Boat.Step > 0)
|
||||
{
|
||||
_startPosX -= Boat.Step;
|
||||
}
|
||||
break;
|
||||
//вверх
|
||||
case Direction.Up:
|
||||
if (_startPosY - Boat.Step > 0)
|
||||
{
|
||||
_startPosY -= Boat.Step;
|
||||
}
|
||||
break;
|
||||
//вниз
|
||||
case Direction.Down:
|
||||
if (_startPosY + _boatHeight + Boat.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += Boat.Step;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Отрисовка лодки
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (_startPosX < 0 || _startPosY < 0
|
||||
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SolidBrush brush = new SolidBrush(Boat.BodyColor);
|
||||
|
||||
PointF[] bodyPoints = new PointF[5];
|
||||
bodyPoints[0] = new PointF(_startPosX, _startPosY);
|
||||
bodyPoints[1] = new PointF(_startPosX + _boatWidth - _boatWidth / 4, _startPosY);
|
||||
bodyPoints[2] = new PointF(_startPosX + _boatWidth, _startPosY + _boatHeight / 2);
|
||||
bodyPoints[3] = new PointF(_startPosX + _boatWidth - _boatWidth / 4, _startPosY + _boatHeight);
|
||||
bodyPoints[4] = new PointF(_startPosX, _startPosY + _boatHeight);
|
||||
|
||||
// Отрисовка корпуса лодки
|
||||
g.FillPolygon(brush, bodyPoints);
|
||||
g.DrawPolygon(Pens.Black, bodyPoints);
|
||||
|
||||
// Отрисовка головы лодки
|
||||
g.FillEllipse(Brushes.White, _startPosX + _boatWidth / 8, _startPosY + _boatHeight / 8,
|
||||
_boatWidth / 2, _boatHeight - _boatHeight / 4);
|
||||
g.DrawEllipse(Pens.Black, _startPosX + _boatWidth / 8, _startPosY + _boatHeight / 8,
|
||||
_boatWidth / 2, _boatHeight - _boatHeight / 4);
|
||||
}
|
||||
/// <summary>
|
||||
/// Смена границ формы отрисовки
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
public void ChangeBorders(int width, int height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_pictureWidth <= _boatWidth || _pictureHeight <= _boatHeight)
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
return;
|
||||
}
|
||||
if (_startPosX + _boatWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth.Value - _boatWidth;
|
||||
}
|
||||
if (_startPosY + _boatHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight.Value - _boatHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
45
Boats/Boats/EntityBoat.cs
Normal file
45
Boats/Boats/EntityBoat.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Boats
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность "Лодка"
|
||||
/// </summary>
|
||||
internal class EntityBoat
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public float Weight { get; private set; }
|
||||
/// <summary>
|
||||
/// Цвет корпуса
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Шаг перемещения лодки
|
||||
/// </summary>
|
||||
public float Step => Speed * 100 / Weight;
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса лодки
|
||||
/// </summary>
|
||||
/// <param name="speed"></param>
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
/// <returns></returns>
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Random rnd = new();
|
||||
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
||||
Weight = weight <= 0 ? rnd.Next(40, 70) : weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
||||
}
|
39
Boats/Boats/Form1.Designer.cs
generated
39
Boats/Boats/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
||||
namespace Boats
|
||||
{
|
||||
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 Boats
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
181
Boats/Boats/FormBoat.Designer.cs
generated
Normal file
181
Boats/Boats/FormBoat.Designer.cs
generated
Normal file
@ -0,0 +1,181 @@
|
||||
namespace Boats
|
||||
{
|
||||
partial class FormBoat
|
||||
{
|
||||
/// <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.pictureBoxBoat = new System.Windows.Forms.PictureBox();
|
||||
this.statusStrip = new System.Windows.Forms.StatusStrip();
|
||||
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.ButtonCreate = new System.Windows.Forms.Button();
|
||||
this.ButtonUp = new System.Windows.Forms.Button();
|
||||
this.ButtonLeft = new System.Windows.Forms.Button();
|
||||
this.ButtonRight = new System.Windows.Forms.Button();
|
||||
this.ButtonDown = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBoat)).BeginInit();
|
||||
this.statusStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// pictureBoxBoat
|
||||
//
|
||||
this.pictureBoxBoat.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxBoat.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxBoat.Name = "pictureBoxBoat";
|
||||
this.pictureBoxBoat.Size = new System.Drawing.Size(800, 424);
|
||||
this.pictureBoxBoat.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBoxBoat.TabIndex = 0;
|
||||
this.pictureBoxBoat.TabStop = false;
|
||||
this.pictureBoxBoat.Resize += new System.EventHandler(this.PictureBoxBoat_Resize);
|
||||
//
|
||||
// statusStrip
|
||||
//
|
||||
this.statusStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||
this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.toolStripStatusLabelSpeed,
|
||||
this.toolStripStatusLabelWeight,
|
||||
this.toolStripStatusLabelBodyColor});
|
||||
this.statusStrip.Location = new System.Drawing.Point(0, 424);
|
||||
this.statusStrip.Name = "statusStrip";
|
||||
this.statusStrip.Size = new System.Drawing.Size(800, 26);
|
||||
this.statusStrip.TabIndex = 1;
|
||||
this.statusStrip.Text = "statusStrip1";
|
||||
//
|
||||
// toolStripStatusLabelSpeed
|
||||
//
|
||||
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
|
||||
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(76, 20);
|
||||
this.toolStripStatusLabelSpeed.Text = "Скорость:";
|
||||
//
|
||||
// toolStripStatusLabelWeight
|
||||
//
|
||||
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
|
||||
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(36, 20);
|
||||
this.toolStripStatusLabelWeight.Text = "Вес:";
|
||||
//
|
||||
// toolStripStatusLabelBodyColor
|
||||
//
|
||||
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
|
||||
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(45, 20);
|
||||
this.toolStripStatusLabelBodyColor.Text = "Цвет:";
|
||||
//
|
||||
// ButtonCreate
|
||||
//
|
||||
this.ButtonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.ButtonCreate.Location = new System.Drawing.Point(12, 381);
|
||||
this.ButtonCreate.Name = "ButtonCreate";
|
||||
this.ButtonCreate.Size = new System.Drawing.Size(94, 29);
|
||||
this.ButtonCreate.TabIndex = 2;
|
||||
this.ButtonCreate.Text = "Создать";
|
||||
this.ButtonCreate.UseVisualStyleBackColor = true;
|
||||
this.ButtonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
|
||||
//
|
||||
// ButtonUp
|
||||
//
|
||||
this.ButtonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.ButtonUp.BackgroundImage = global::Boats.Properties.Resources.arrow_up;
|
||||
this.ButtonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.ButtonUp.Location = new System.Drawing.Point(710, 344);
|
||||
this.ButtonUp.Name = "ButtonUp";
|
||||
this.ButtonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.ButtonUp.TabIndex = 3;
|
||||
this.ButtonUp.UseVisualStyleBackColor = true;
|
||||
this.ButtonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// ButtonLeft
|
||||
//
|
||||
this.ButtonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.ButtonLeft.BackgroundImage = global::Boats.Properties.Resources.arrow_left;
|
||||
this.ButtonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.ButtonLeft.Location = new System.Drawing.Point(674, 380);
|
||||
this.ButtonLeft.Name = "ButtonLeft";
|
||||
this.ButtonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.ButtonLeft.TabIndex = 4;
|
||||
this.ButtonLeft.UseVisualStyleBackColor = true;
|
||||
this.ButtonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// ButtonRight
|
||||
//
|
||||
this.ButtonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.ButtonRight.BackgroundImage = global::Boats.Properties.Resources.arrow_right;
|
||||
this.ButtonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.ButtonRight.Location = new System.Drawing.Point(746, 380);
|
||||
this.ButtonRight.Name = "ButtonRight";
|
||||
this.ButtonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.ButtonRight.TabIndex = 5;
|
||||
this.ButtonRight.UseVisualStyleBackColor = true;
|
||||
this.ButtonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// ButtonDown
|
||||
//
|
||||
this.ButtonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.ButtonDown.BackgroundImage = global::Boats.Properties.Resources.arrow_down;
|
||||
this.ButtonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.ButtonDown.Location = new System.Drawing.Point(710, 380);
|
||||
this.ButtonDown.Name = "ButtonDown";
|
||||
this.ButtonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.ButtonDown.TabIndex = 6;
|
||||
this.ButtonDown.UseVisualStyleBackColor = true;
|
||||
this.ButtonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// FormBoat
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.ButtonDown);
|
||||
this.Controls.Add(this.ButtonRight);
|
||||
this.Controls.Add(this.ButtonLeft);
|
||||
this.Controls.Add(this.ButtonUp);
|
||||
this.Controls.Add(this.ButtonCreate);
|
||||
this.Controls.Add(this.pictureBoxBoat);
|
||||
this.Controls.Add(this.statusStrip);
|
||||
this.Name = "FormBoat";
|
||||
this.Text = "Лодка";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBoat)).EndInit();
|
||||
this.statusStrip.ResumeLayout(false);
|
||||
this.statusStrip.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxBoat;
|
||||
private StatusStrip statusStrip;
|
||||
private ToolStripStatusLabel toolStripStatusLabelSpeed;
|
||||
private ToolStripStatusLabel toolStripStatusLabelWeight;
|
||||
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
|
||||
private Button ButtonCreate;
|
||||
private Button ButtonUp;
|
||||
private Button ButtonLeft;
|
||||
private Button ButtonRight;
|
||||
private Button ButtonDown;
|
||||
}
|
||||
}
|
93
Boats/Boats/FormBoat.cs
Normal file
93
Boats/Boats/FormBoat.cs
Normal file
@ -0,0 +1,93 @@
|
||||
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 Boats
|
||||
{
|
||||
public partial class FormBoat : Form
|
||||
{
|
||||
private DrawingBoat _boat;
|
||||
public FormBoat()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки лодки
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
Bitmap bmp = new(pictureBoxBoat.Width, pictureBoxBoat.Height);
|
||||
Graphics g = Graphics.FromImage(bmp);
|
||||
_boat?.DrawTransport(g);
|
||||
pictureBoxBoat.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_boat = new DrawingBoat();
|
||||
_boat.Init(
|
||||
rnd.Next(100, 300),
|
||||
rnd.Next(1000, 2000),
|
||||
Color.FromArgb(rnd.Next(0, 256),
|
||||
rnd.Next(0, 256), rnd.Next(0, 256))
|
||||
);
|
||||
_boat.SetPosition(
|
||||
rnd.Next(10, 100),
|
||||
rnd.Next(10, 100),
|
||||
pictureBoxBoat.Width,
|
||||
pictureBoxBoat.Height
|
||||
);
|
||||
toolStripStatusLabelSpeed.Text = $"Скорость: {_boat.Boat.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Вес: {_boat.Boat.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Цвет: {_boat.Boat.BodyColor.Name}";
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение размеров формы
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
//получаем имя кнопки
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
switch (name)
|
||||
{
|
||||
case "ButtonUp":
|
||||
_boat?.MoveTransport(Direction.Up);
|
||||
break;
|
||||
case "ButtonDown":
|
||||
_boat?.MoveTransport(Direction.Down);
|
||||
break;
|
||||
case "ButtonLeft":
|
||||
_boat?.MoveTransport(Direction.Left);
|
||||
break;
|
||||
case "ButtonRight":
|
||||
_boat?.MoveTransport(Direction.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение размеров формы
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void PictureBoxBoat_Resize(object sender, EventArgs e)
|
||||
{
|
||||
_boat?.ChangeBorders(pictureBoxBoat.Width, pictureBoxBoat.Height);
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
}
|
63
Boats/Boats/FormBoat.resx
Normal file
63
Boats/Boats/FormBoat.resx
Normal file
@ -0,0 +1,63 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="statusStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
@ -11,7 +11,7 @@ namespace Boats
|
||||
// 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 FormBoat());
|
||||
}
|
||||
}
|
||||
}
|
103
Boats/Boats/Properties/Resources.Designer.cs
generated
Normal file
103
Boats/Boats/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,103 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Boats.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[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>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </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("Boats.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap arrow_down {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("arrow_down", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap arrow_left {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("arrow_left", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap arrow_right {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("arrow_right", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap arrow_up {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("arrow_up", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -117,4 +117,17 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="arrow_down" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\arrow_down.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="arrow_left" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\arrow_left.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="arrow_right" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\arrow_right.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="arrow_up" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\arrow_up.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
</root>
|
BIN
Boats/Boats/Resources/arrow_down.png
Normal file
BIN
Boats/Boats/Resources/arrow_down.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 363 B |
BIN
Boats/Boats/Resources/arrow_left.png
Normal file
BIN
Boats/Boats/Resources/arrow_left.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 392 B |
BIN
Boats/Boats/Resources/arrow_right.png
Normal file
BIN
Boats/Boats/Resources/arrow_right.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 380 B |
BIN
Boats/Boats/Resources/arrow_up.png
Normal file
BIN
Boats/Boats/Resources/arrow_up.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 433 B |
Loading…
Reference in New Issue
Block a user
Название проекта не соответствует указаному в задании