diff --git a/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs b/WarmlyShip/WarmlyShip/DrawningShip.cs
similarity index 71%
rename from WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs
rename to WarmlyShip/WarmlyShip/DrawningShip.cs
index d456864..4c37785 100644
--- a/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs
+++ b/WarmlyShip/WarmlyShip/DrawningShip.cs
@@ -3,23 +3,23 @@
///
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
///
- internal class DrawningWarmlyShip
+ internal class DrawningShip
{
- public EntityWarmlyShip WarmlyShip { get; private set; }
+ public EntityShip Ship { get; private set; }
private float _startPosX;
private float _startPosY;
private int? _pictureWidth = null;
private int? _pictureHeight = null;
- private readonly int _WarmlyShipWidth = 80;
- private readonly int _WarmlyShipHeight = 50;
+ private readonly int _shipWidth = 80;
+ private readonly int _shipHeight = 50;
public void Init(int speed, float weight, Color сolor)
{
- WarmlyShip = new EntityWarmlyShip();
- WarmlyShip.Init(speed, weight, сolor);
+ Ship = new EntityShip();
+ Ship.Init(speed, weight, сolor);
}
public void SetPosition(int x, int y, int width, int height)
{
- if (x + _WarmlyShipWidth <= width && y + _WarmlyShipHeight <= height && x >= 0 && y >= 0)
+ if (x + _shipWidth <= width && y + _shipHeight <= height && x >= 0 && y >= 0)
{
_startPosX = x;
_startPosY = y;
@@ -37,30 +37,30 @@
{
// вправо
case Direction.Right:
- if (_startPosX + _WarmlyShipWidth + WarmlyShip.Step + 60 < _pictureWidth)
+ if (_startPosX + _shipWidth + Ship.Step + 60 < _pictureWidth)
{
- _startPosX += WarmlyShip.Step;
+ _startPosX += Ship.Step;
}
break;
//влево
case Direction.Left:
- if (_startPosX - WarmlyShip.Step > 0)
+ if (_startPosX - Ship.Step > 0)
{
- _startPosX -= WarmlyShip.Step;
+ _startPosX -= Ship.Step;
}
break;
//вверх
case Direction.Up:
- if (_startPosY - WarmlyShip.Step > 0)
+ if (_startPosY - Ship.Step > 0)
{
- _startPosY -= WarmlyShip.Step;
+ _startPosY -= Ship.Step;
}
break;
//вниз
case Direction.Down:
- if (_startPosY + _WarmlyShipHeight + WarmlyShip.Step + 40 < _pictureHeight)
+ if (_startPosY + _shipHeight + Ship.Step + 40 < _pictureHeight)
{
- _startPosY += WarmlyShip.Step;
+ _startPosY += Ship.Step;
}
break;
}
@@ -76,7 +76,7 @@
//выделяем рамкой крышу
- Brush br = new SolidBrush(WarmlyShip?.BodyColor ?? Color.Black);
+ Brush br = new SolidBrush(Ship?.BodyColor ?? Color.Black);
g.FillRectangle(br, _startPosX + 29, _startPosY + 5, 80, 20);
g.DrawRectangle(pen, _startPosX + 29, _startPosY + 5, 80, 20);
//g.DrawLine(pen, _startPosX, _startPosY + 25, _startPosX + 135, _startPosY + 25);
@@ -106,19 +106,19 @@
{
_pictureWidth = width;
_pictureHeight = height;
- if (_pictureWidth <= _WarmlyShipWidth || _pictureHeight <= _WarmlyShipHeight)
+ if (_pictureWidth <= _shipWidth || _pictureHeight <= _shipHeight)
{
_pictureWidth = null;
_pictureHeight = null;
return;
}
- if (_startPosX + _WarmlyShipWidth > _pictureWidth)
+ if (_startPosX + _shipWidth > _pictureWidth)
{
- _startPosX = _pictureWidth.Value - _WarmlyShipWidth;
+ _startPosX = _pictureWidth.Value - _shipWidth;
}
- if (_startPosY + _WarmlyShipHeight > _pictureHeight)
+ if (_startPosY + _shipHeight > _pictureHeight)
{
- _startPosY = _pictureHeight.Value - _WarmlyShipHeight;
+ _startPosY = _pictureHeight.Value - _shipHeight;
}
}
}
diff --git a/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs b/WarmlyShip/WarmlyShip/EntityShip.cs
similarity index 93%
rename from WarmlyShip/WarmlyShip/EntityWarmlyShip.cs
rename to WarmlyShip/WarmlyShip/EntityShip.cs
index 67b0b9c..a4b4131 100644
--- a/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs
+++ b/WarmlyShip/WarmlyShip/EntityShip.cs
@@ -1,6 +1,6 @@
namespace WarmlyShip
{
- internal class EntityWarmlyShip
+ internal class EntityShip
{
public int Speed { get; private set; }
public float Weight { get; private set; }
diff --git a/WarmlyShip/WarmlyShip/FormWarmlyShip.Designer.cs b/WarmlyShip/WarmlyShip/FormShip.Designer.cs
similarity index 90%
rename from WarmlyShip/WarmlyShip/FormWarmlyShip.Designer.cs
rename to WarmlyShip/WarmlyShip/FormShip.Designer.cs
index ce27b26..2049688 100644
--- a/WarmlyShip/WarmlyShip/FormWarmlyShip.Designer.cs
+++ b/WarmlyShip/WarmlyShip/FormShip.Designer.cs
@@ -1,6 +1,6 @@
namespace WarmlyShip
{
- partial class FormWarmlyShip
+ partial class FormShip
{
///
/// Required designer variable.
@@ -28,7 +28,7 @@
///
private void InitializeComponent()
{
- this.pictureBoxWarmlyShip = new System.Windows.Forms.PictureBox();
+ this.pictureBoxShip = new System.Windows.Forms.PictureBox();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.toolStripStatusSpeed = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusWeight = new System.Windows.Forms.ToolStripStatusLabel();
@@ -38,18 +38,18 @@
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
- ((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarmlyShip)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
//
- // pictureBoxWarmlyShip
+ // pictureBoxShip
//
- this.pictureBoxWarmlyShip.Dock = System.Windows.Forms.DockStyle.Fill;
- this.pictureBoxWarmlyShip.Location = new System.Drawing.Point(0, 0);
- this.pictureBoxWarmlyShip.Name = "pictureBoxWarmlyShip";
- this.pictureBoxWarmlyShip.Size = new System.Drawing.Size(800, 450);
- this.pictureBoxWarmlyShip.TabIndex = 0;
- this.pictureBoxWarmlyShip.TabStop = false;
+ this.pictureBoxShip.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.pictureBoxShip.Location = new System.Drawing.Point(0, 0);
+ this.pictureBoxShip.Name = "pictureBoxShip";
+ this.pictureBoxShip.Size = new System.Drawing.Size(800, 450);
+ this.pictureBoxShip.TabIndex = 0;
+ this.pictureBoxShip.TabStop = false;
//
// statusStrip1
//
@@ -140,7 +140,7 @@
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
//
- // FormWarmlyShip
+ // FormShip
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
@@ -151,10 +151,10 @@
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.statusStrip1);
- this.Controls.Add(this.pictureBoxWarmlyShip);
- this.Name = "FormWarmlyShip";
+ this.Controls.Add(this.pictureBoxShip);
+ this.Name = "FormShip";
this.Text = "Form1";
- ((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarmlyShip)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).EndInit();
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.ResumeLayout(false);
@@ -164,7 +164,7 @@
#endregion
- private PictureBox pictureBoxWarmlyShip;
+ private PictureBox pictureBoxShip;
private StatusStrip statusStrip1;
private ToolStripStatusLabel toolStripStatusSpeed;
private ToolStripStatusLabel toolStripStatusWeight;
diff --git a/WarmlyShip/WarmlyShip/FormShip.cs b/WarmlyShip/WarmlyShip/FormShip.cs
new file mode 100644
index 0000000..5d3293d
--- /dev/null
+++ b/WarmlyShip/WarmlyShip/FormShip.cs
@@ -0,0 +1,55 @@
+namespace WarmlyShip
+{
+ public partial class FormShip : Form
+ {
+ private DrawningShip _ship;
+ public FormShip()
+ {
+ InitializeComponent();
+ }
+ private void Draw()
+ {
+ Bitmap bmp = new(pictureBoxShip.Width, pictureBoxShip.Height);
+ Graphics gr = Graphics.FromImage(bmp);
+ _ship?.DrawTransport(gr);
+ pictureBoxShip.Image = bmp;
+ }
+ private void buttonCreate_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ _ship = new DrawningShip();
+ _ship.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ _ship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxShip.Width, pictureBoxShip.Height);
+ toolStripStatusSpeed.Text = $": {_ship.Ship.Speed}";
+ toolStripStatusWeight.Text = $": {_ship.Ship.Weight}";
+ toolStripStatusColor.Text = $": {_ship.Ship.BodyColor.Name}";
+ Draw();
+ }
+ private void PictureBoxShip_Resize(object sender, EventArgs e)
+ {
+ _ship?.ChangeBorders(pictureBoxShip.Width, pictureBoxShip.Height);
+ Draw();
+ }
+ private void buttonMove_Click(object sender, EventArgs e)
+ {
+ //
+ string name = ((Button)sender)?.Name ?? string.Empty;
+ switch (name)
+ {
+ case "buttonUp":
+ _ship?.MoveTransport(Direction.Up);
+ break;
+ case "buttonDown":
+ _ship?.MoveTransport(Direction.Down);
+ break;
+ case "buttonLeft":
+ _ship?.MoveTransport(Direction.Left);
+ break;
+ case "buttonRight":
+ _ship?.MoveTransport(Direction.Right);
+ break;
+ }
+ Draw();
+ }
+ }
+}
diff --git a/WarmlyShip/WarmlyShip/FormWarmlyShip.resx b/WarmlyShip/WarmlyShip/FormShip.resx
similarity index 100%
rename from WarmlyShip/WarmlyShip/FormWarmlyShip.resx
rename to WarmlyShip/WarmlyShip/FormShip.resx
diff --git a/WarmlyShip/WarmlyShip/FormWarmlyShip.cs b/WarmlyShip/WarmlyShip/FormWarmlyShip.cs
deleted file mode 100644
index e445c8b..0000000
--- a/WarmlyShip/WarmlyShip/FormWarmlyShip.cs
+++ /dev/null
@@ -1,55 +0,0 @@
-namespace WarmlyShip
-{
- public partial class FormWarmlyShip : Form
- {
- private DrawningWarmlyShip _warmlyship;
- public FormWarmlyShip()
- {
- InitializeComponent();
- }
- private void Draw()
- {
- Bitmap bmp = new(pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
- Graphics gr = Graphics.FromImage(bmp);
- _warmlyship?.DrawTransport(gr);
- pictureBoxWarmlyShip.Image = bmp;
- }
- private void buttonCreate_Click(object sender, EventArgs e)
- {
- Random rnd = new();
- _warmlyship = new DrawningWarmlyShip();
- _warmlyship.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
- _warmlyship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
- toolStripStatusSpeed.Text = $": {_warmlyship.WarmlyShip.Speed}";
- toolStripStatusWeight.Text = $": {_warmlyship.WarmlyShip.Weight}";
- toolStripStatusColor.Text = $": {_warmlyship.WarmlyShip.BodyColor.Name}";
- Draw();
- }
- private void PictureBoxCar_Resize(object sender, EventArgs e)
- {
- _warmlyship?.ChangeBorders(pictureBoxWarmlyShip.Width, pictureBoxWarmlyShip.Height);
- Draw();
- }
- private void buttonMove_Click(object sender, EventArgs e)
- {
- //
- string name = ((Button)sender)?.Name ?? string.Empty;
- switch (name)
- {
- case "buttonUp":
- _warmlyship?.MoveTransport(Direction.Up);
- break;
- case "buttonDown":
- _warmlyship?.MoveTransport(Direction.Down);
- break;
- case "buttonLeft":
- _warmlyship?.MoveTransport(Direction.Left);
- break;
- case "buttonRight":
- _warmlyship?.MoveTransport(Direction.Right);
- break;
- }
- Draw();
- }
- }
-}
diff --git a/WarmlyShip/WarmlyShip/Program.cs b/WarmlyShip/WarmlyShip/Program.cs
index b8d8ca5..d10c21b 100644
--- a/WarmlyShip/WarmlyShip/Program.cs
+++ b/WarmlyShip/WarmlyShip/Program.cs
@@ -8,7 +8,7 @@ namespace WarmlyShip
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormWarmlyShip());
+ Application.Run(new FormShip());
}
}
}
\ No newline at end of file