Compare commits

..

10 Commits

12 changed files with 127 additions and 138 deletions

View File

@ -6,70 +6,114 @@ using System.Threading.Tasks;
namespace AircraftCarrier
{
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
internal class DrawingWarship
{
/// <summary>
/// Класс-сущность
/// </summary>
public EntityWarship Warship { get; private set; }
/// <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 _warshipWidth = 94;
/// <summary>
/// Высота отрисовки военного корабля
/// </summary>
private readonly int _warshipHeight = 40;
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес военного корабля</param>
/// <param name="bodyColor">Цвет главной палубы</param>
public void Init(int speed, float weight, Color bodyColor)
{
Warship = new EntityWarship();
Warship.Init(speed, weight, bodyColor);
}
/// <summary>
/// Установка позиции военного корабля
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="width"></param>
/// <param name="height"></param>
public void SetPosition(int x, int y, int width, int height)
{
_startPosX = x; _startPosY = y;
_pictureWidth = width; _pictureHeight = height;
if (width >= x + _warshipWidth && height >= y + _warshipHeight && x >= 0 && y >= 0)
{
_startPosX = x;
_startPosY = y;
_pictureWidth = width;
_pictureHeight = height;
}
}
/// <summary>
/// Изменение направления пермещения
/// </summary>
/// <param name="direction">Направление</param>
public void MoveTransport(Direction direction)
{
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
{
return;
}
switch (direction)
{
// вправо
case Direction.Right:
if (_startPosX + _warshipWidth + Warship.Step < _pictureWidth)
{
_startPosX += Warship.Step;
}
break;
//влево
case Direction.Left:
if (_startPosX > 0)
if(_startPosX - Warship.Step > 0)
{
_startPosX -= Warship.Step;
}
break;
//вверх
case Direction.Up:
if (_startPosY > 0)
if (_startPosY - Warship.Step > 0)
{
_startPosY -= Warship.Step;
}
break;
//вниз
case Direction.Down:
if (_startPosY + _warshipHeight + Warship.Step < _pictureHeight)
{
_startPosY += Warship.Step;
}
break;
}
}
/// <summary>
/// Отрисовка военного корабля
/// </summary>
/// <param name="g"></param>
public void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0
@ -102,9 +146,9 @@ namespace AircraftCarrier
//границы мачты
g.DrawEllipse(pen, _startPosX + 59, _startPosY + 13, 15, 15);
//палуба
g.FillRectangle(brWhite, _startPosX + 44, _startPosY + 10, 10,20);
g.FillRectangle(brWhite, _startPosX + 44, _startPosY + 10, 10, 20);
g.FillRectangle(brWhite, _startPosX + 24, _startPosY + 15, 20, 10);
//границы палуба
@ -113,14 +157,15 @@ namespace AircraftCarrier
//двигатели
Brush brBlack = new SolidBrush(Color.Black);
g.FillRectangle(brBlack, _startPosX, _startPosY + 5, 4,10);
g.FillRectangle(brBlack, _startPosX, _startPosY + 5, 4, 10);
g.FillRectangle(brBlack, _startPosX, _startPosY + 23, 4, 10);
}
/// <summary>
/// Смена границ формы отрисовки
/// </summary>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
public void ChangeBorders(int width, int height)
{
_pictureWidth = width;
@ -140,5 +185,6 @@ namespace AircraftCarrier
_startPosY = _pictureHeight.Value - _warshipHeight;
}
}
}
}

View File

@ -40,7 +40,5 @@ namespace AircraftCarrier
Weight = weight <= 0 ? rnd.Next(40, 70) : weight;
BodyColor = bodyColor;
}
}
}

View File

@ -29,17 +29,17 @@
private void InitializeComponent()
{
this.pictureBoxWarship = new System.Windows.Forms.PictureBox();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
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.buttonDown = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonDawn = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarship)).BeginInit();
this.statusStrip1.SuspendLayout();
this.statusStrip.SuspendLayout();
this.SuspendLayout();
//
// pictureBoxWarship
@ -47,23 +47,22 @@
this.pictureBoxWarship.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxWarship.Location = new System.Drawing.Point(0, 0);
this.pictureBoxWarship.Name = "pictureBoxWarship";
this.pictureBoxWarship.Size = new System.Drawing.Size(855, 501);
this.pictureBoxWarship.Size = new System.Drawing.Size(510, 426);
this.pictureBoxWarship.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxWarship.TabIndex = 0;
this.pictureBoxWarship.TabStop = false;
this.pictureBoxWarship.Resize += new System.EventHandler(this.pictureBoxWarship_Resize);
this.pictureBoxWarship.Resize += new System.EventHandler(this.PictureBoxWarship_Resize);
//
// statusStrip1
// statusStrip
//
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabelSpeed,
this.toolStripStatusLabelWeight,
this.toolStripStatusLabelBodyColor});
this.statusStrip1.Location = new System.Drawing.Point(0, 501);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(855, 22);
this.statusStrip1.TabIndex = 1;
this.statusStrip1.Text = "statusStrip1";
this.statusStrip.Location = new System.Drawing.Point(0, 426);
this.statusStrip.Name = "statusStrip";
this.statusStrip.Size = new System.Drawing.Size(510, 22);
this.statusStrip.TabIndex = 1;
//
// toolStripStatusLabelSpeed
//
@ -86,23 +85,36 @@
// 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, 475);
this.buttonCreate.Location = new System.Drawing.Point(12, 393);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(75, 23);
this.buttonCreate.TabIndex = 2;
this.buttonCreate.Text = "Create";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::AircraftCarrier.Properties.Resources.ArrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(428, 386);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 3;
this.buttonDown.Text = " ";
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonUp
//
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::AircraftCarrier.Properties.Resources.ArrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(777, 432);
this.buttonUp.Location = new System.Drawing.Point(428, 350);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 3;
this.buttonUp.TabIndex = 4;
this.buttonUp.Text = " ";
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
@ -112,33 +124,20 @@
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::AircraftCarrier.Properties.Resources.ArrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(741, 468);
this.buttonLeft.Location = new System.Drawing.Point(392, 386);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 4;
this.buttonLeft.TabIndex = 5;
this.buttonLeft.Text = " ";
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonDawn
//
this.buttonDawn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDawn.BackgroundImage = global::AircraftCarrier.Properties.Resources.AarrowDown;
this.buttonDawn.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDawn.Location = new System.Drawing.Point(777, 468);
this.buttonDawn.Name = "buttonDawn";
this.buttonDawn.Size = new System.Drawing.Size(30, 30);
this.buttonDawn.TabIndex = 5;
this.buttonDawn.Text = " ";
this.buttonDawn.UseVisualStyleBackColor = true;
this.buttonDawn.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::AircraftCarrier.Properties.Resources.ArrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(813, 468);
this.buttonRight.Location = new System.Drawing.Point(464, 386);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 6;
@ -150,19 +149,19 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(855, 523);
this.ClientSize = new System.Drawing.Size(510, 448);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonDawn);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.pictureBoxWarship);
this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.statusStrip);
this.Name = "FormWarship";
this.Text = " Warship";
this.Text = "Warship";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarship)).EndInit();
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.statusStrip.ResumeLayout(false);
this.statusStrip.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
@ -171,14 +170,14 @@
#endregion
private PictureBox pictureBoxWarship;
private StatusStrip statusStrip1;
private StatusStrip statusStrip;
private ToolStripStatusLabel toolStripStatusLabelSpeed;
private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
private Button buttonCreate;
private Button buttonDown;
private Button buttonUp;
private Button buttonLeft;
private Button buttonDawn;
private Button buttonRight;
}
}

View File

@ -3,15 +3,13 @@ namespace AircraftCarrier
public partial class FormWarship : Form
{
private DrawingWarship _warship;
public FormWarship()
{
InitializeComponent();
}
/// <summary>
/// Ìåòîä ïðîðèñîâêè ìàøèíû
/// </summary>
///
/// Ìåòîä ïðîðèñîâêè âîåííîãî êîðàáëÿ
/// </summary>
private void Draw()
{
Bitmap bmp = new(pictureBoxWarship.Width, pictureBoxWarship.Height);
@ -19,9 +17,13 @@ namespace AircraftCarrier
_warship?.DrawTransport(gr);
pictureBoxWarship.Image = bmp;
}
private void buttonCreate_Click(object sender, EventArgs e)
{
/// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Create"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
_warship = new DrawingWarship();
_warship.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
@ -31,15 +33,9 @@ namespace AircraftCarrier
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_warship.Warship.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)
{
@ -58,7 +54,6 @@ namespace AircraftCarrier
}
Draw();
}
/// <summary>
/// Èçìåíåíèå ðàçìåðîâ ôîðìû
/// </summary>
@ -66,7 +61,7 @@ namespace AircraftCarrier
/// <param name="e"></param>
private void PictureBoxWarship_Resize(object sender, EventArgs e)
{
_warship?.ChangeBorders(pictureBoxWarship.Width, pictureBoxWarship.Height);
_warship?.ChangeBorders(pictureBoxWarship.Width,pictureBoxWarship.Height);
Draw();
}
}

View File

@ -57,7 +57,10 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="statusStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>59</value>
</metadata>
</root>

View File

@ -63,9 +63,9 @@ namespace AircraftCarrier.Properties {
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap AarrowDown {
internal static System.Drawing.Bitmap ArrowDown {
get {
object obj = ResourceManager.GetObject("AarrowDown", resourceCulture);
object obj = ResourceManager.GetObject("ArrowDown", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
@ -99,45 +99,5 @@ namespace AircraftCarrier.Properties {
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap down {
get {
object obj = ResourceManager.GetObject("down", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap left {
get {
object obj = ResourceManager.GetObject("left", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap right {
get {
object obj = ResourceManager.GetObject("right", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap up {
get {
object obj = ResourceManager.GetObject("up", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -118,20 +118,8 @@
<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="left" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\left.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="right" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\right.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="down" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\down.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="up" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\up.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="AarrowDown" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\AarrowDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="ArrowDown" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ArrowDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ArrowLeft" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ArrowLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>

View File

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB