From c7a89353edce6eab12314cc8852f7c4aa173b61f Mon Sep 17 00:00:00 2001 From: "A.Novopoltsev" Date: Mon, 21 Nov 2022 19:45:57 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=B0=D1=8F=20=D0=BB?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Warship/Warship/Direction.cs | 1 + Warship/Warship/DrawningShip.cs | 34 ++++- Warship/Warship/EntityShip.cs | 2 +- Warship/Warship/FormMap.Designer.cs | 218 ++++++++++++++++++++++++++++ Warship/Warship/FormMap.cs | 89 ++++++++++++ Warship/Warship/FormMap.resx | 63 ++++++++ Warship/Warship/FormWarship.cs | 85 +++++++++++ Warship/Warship/Program.cs | 2 +- Warship/Warship/Warship.Designer.cs | 193 ++++++++++++++++++++++++ Warship/Warship/Warship.cs | 76 ++++++++++ Warship/Warship/Warship.resx | 63 ++++++++ 11 files changed, 816 insertions(+), 10 deletions(-) create mode 100644 Warship/Warship/FormMap.Designer.cs create mode 100644 Warship/Warship/FormMap.cs create mode 100644 Warship/Warship/FormMap.resx create mode 100644 Warship/Warship/FormWarship.cs create mode 100644 Warship/Warship/Warship.Designer.cs create mode 100644 Warship/Warship/Warship.cs create mode 100644 Warship/Warship/Warship.resx diff --git a/Warship/Warship/Direction.cs b/Warship/Warship/Direction.cs index caf3172..36fe5c4 100644 --- a/Warship/Warship/Direction.cs +++ b/Warship/Warship/Direction.cs @@ -8,6 +8,7 @@ namespace Warship { internal enum Direction { + None = 0, Up = 1, Down = 2, Left = 3, diff --git a/Warship/Warship/DrawningShip.cs b/Warship/Warship/DrawningShip.cs index e20169c..8c76d13 100644 --- a/Warship/Warship/DrawningShip.cs +++ b/Warship/Warship/DrawningShip.cs @@ -12,15 +12,15 @@ namespace Warship /// /// Класс-сущность /// - public EntityShip Ship { private set; get; } + public EntityShip Ship { protected set; get; } /// /// Левая координата отрисовки лодки /// - private float _startPosX; + protected float _startPosX; /// /// Верхняя кооридната отрисовки лодки /// - private float _startPosY; + protected float _startPosY; /// /// Ширина окна отрисовки /// @@ -32,7 +32,7 @@ namespace Warship /// /// Ширина отрисовки лодки /// - private readonly int _shipWidth = 120; + private readonly int _shipWidth = 125; /// /// Высота отрисовки лодки /// @@ -43,10 +43,14 @@ namespace Warship /// Скорость /// Вес лодки /// Цвет кузова - public void Init(int speed, float weight, Color bodyColor) + public DrawningShip(int speed, float weight, Color bodyColor) { - Ship = new EntityShip(); - Ship.Init(speed, weight, bodyColor); + Ship = new EntityShip(speed, weight, bodyColor); + } + protected DrawningShip(int speed, float weight, Color bodyColor, int shipWight, int shipHeight) : this(speed, weight, bodyColor) + { + _shipWidth = shipWight; + _shipHeight = shipHeight; } /// /// Установка позиции корабля @@ -111,8 +115,17 @@ namespace Warship break; } } + + public bool DrawCheck() + { + if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) + { + return false; + } + return true; + } /// - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) @@ -165,5 +178,10 @@ namespace Warship _startPosY = _pictureHeight.Value - _shipHeight; } } + + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return (_startPosX, _startPosY, _startPosX + _shipWidth, _startPosY + _shipHeight); + } } } diff --git a/Warship/Warship/EntityShip.cs b/Warship/Warship/EntityShip.cs index ca5df94..7f4f2c4 100644 --- a/Warship/Warship/EntityShip.cs +++ b/Warship/Warship/EntityShip.cs @@ -32,7 +32,7 @@ namespace Warship /// /// /// - public void Init(int speed, float weight, Color bodyColor) + public EntityShip(int speed, float weight, Color bodyColor) { Random rnd = new(); Speed = speed <= 0 ? rnd.Next(50, 150) : speed; diff --git a/Warship/Warship/FormMap.Designer.cs b/Warship/Warship/FormMap.Designer.cs new file mode 100644 index 0000000..5e1dfd1 --- /dev/null +++ b/Warship/Warship/FormMap.Designer.cs @@ -0,0 +1,218 @@ +namespace Warship +{ + partial class FormMap + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.pictureBoxShip = new System.Windows.Forms.PictureBox(); + 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(); + this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); + this.statusStrip1 = new System.Windows.Forms.StatusStrip(); + this.buttonCreateModif = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit(); + this.statusStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // pictureBoxShip + // + 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(884, 439); + this.pictureBoxShip.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBoxShip.TabIndex = 1; + this.pictureBoxShip.TabStop = false; + this.pictureBoxShip.UseWaitCursor = true; + // + // 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, 406); + this.buttonCreate.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(75, 30); + this.buttonCreate.TabIndex = 2; + this.buttonCreate.Text = "Создать"; + this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.UseWaitCursor = 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::Warship.Properties.Resources.arrowUp; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonUp.Location = new System.Drawing.Point(809, 370); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(30, 30); + this.buttonUp.TabIndex = 3; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.UseWaitCursor = 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::Warship.Properties.Resources.arrowLeft; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonLeft.Location = new System.Drawing.Point(773, 406); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(30, 30); + this.buttonLeft.TabIndex = 4; + this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.UseWaitCursor = 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::Warship.Properties.Resources.arrowRight; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonRight.Location = new System.Drawing.Point(845, 406); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(30, 30); + this.buttonRight.TabIndex = 5; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.UseWaitCursor = 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::Warship.Properties.Resources.arrowDown; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonDown.Location = new System.Drawing.Point(809, 406); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(30, 30); + this.buttonDown.TabIndex = 6; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.UseWaitCursor = true; + this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); + // + // toolStripStatusLabelSpeed + // + this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; + this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(62, 17); + this.toolStripStatusLabelSpeed.Text = "Скорость:"; + // + // toolStripStatusLabelWeight + // + this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; + this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(29, 17); + this.toolStripStatusLabelWeight.Text = "Вес:"; + // + // toolStripStatusLabelBodyColor + // + this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; + this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17); + this.toolStripStatusLabelBodyColor.Text = "Цвет:"; + // + // statusStrip1 + // + this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripStatusLabelSpeed, + this.toolStripStatusLabelWeight, + this.toolStripStatusLabelBodyColor}); + this.statusStrip1.Location = new System.Drawing.Point(0, 439); + this.statusStrip1.Name = "statusStrip1"; + this.statusStrip1.Size = new System.Drawing.Size(884, 22); + this.statusStrip1.TabIndex = 0; + this.statusStrip1.Text = "statusStrip1"; + this.statusStrip1.UseWaitCursor = true; + // + // buttonCreateModif + // + this.buttonCreateModif.Location = new System.Drawing.Point(93, 406); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(75, 30); + this.buttonCreateModif.TabIndex = 7; + this.buttonCreateModif.Text = "Модификация"; + this.buttonCreateModif.UseVisualStyleBackColor = true; + this.buttonCreateModif.UseWaitCursor = true; + this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click); + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Простая карта", + "Океан"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23); + this.comboBoxSelectorMap.TabIndex = 8; + this.comboBoxSelectorMap.UseWaitCursor = true; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged); + // + // FormMap + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(884, 461); + this.Controls.Add(this.comboBoxSelectorMap); + this.Controls.Add(this.buttonCreateModif); + 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.pictureBoxShip); + this.Controls.Add(this.statusStrip1); + this.Name = "FormMap"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Form1"; + this.UseWaitCursor = true; + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).EndInit(); + this.statusStrip1.ResumeLayout(false); + this.statusStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private PictureBox pictureBoxShip; + private Button buttonCreate; + private Button buttonUp; + private Button buttonLeft; + private Button buttonRight; + private Button buttonDown; + private ToolStripStatusLabel toolStripStatusLabelSpeed; + private ToolStripStatusLabel toolStripStatusLabelWeight; + private ToolStripStatusLabel toolStripStatusLabelBodyColor; + private StatusStrip statusStrip1; + private Button buttonCreateModif; + private ComboBox comboBoxSelectorMap; + } +} \ No newline at end of file diff --git a/Warship/Warship/FormMap.cs b/Warship/Warship/FormMap.cs new file mode 100644 index 0000000..8816497 --- /dev/null +++ b/Warship/Warship/FormMap.cs @@ -0,0 +1,89 @@ +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 Warship +{ + public partial class FormMap : Form + { + private AbstractMap _abstractMap; + public FormMap() + { + InitializeComponent(); + _abstractMap = new SimpleMap(); + } + + private void SetData(DrawningShip ship) + { + toolStripStatusLabelSpeed.Text = $"Скорость: {ship.Ship.Speed}"; + toolStripStatusLabelWeight.Text = $"Вес: {ship.Ship.Weight}"; + toolStripStatusLabelBodyColor.Text = $"Цвет: {ship.Ship.BodyColor.Name}"; + pictureBoxShip.Image = _abstractMap.CreateMap(pictureBoxShip.Width, pictureBoxShip.Height, new DrawningObjectLinkor(ship)); + } + /// + /// Обработка нажатия кнопки "Создать" + /// + /// + /// + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random rnd = new(); + var ship = new DrawningShip(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + SetData(ship); + } + + private void ButtonMove_Click(object sender, EventArgs e) + { + //получаем имя кнопки + string name = ((Button)sender)?.Name ?? string.Empty; + Direction dir = Direction.None; + switch (name) + { + case "buttonUp": + dir = Direction.Up; + break; + case "buttonDown": + dir = Direction.Down; + break; + case "buttonLeft": + dir = Direction.Left; + break; + case "buttonRight": + dir = Direction.Right; + break; + } + pictureBoxShip.Image = _abstractMap.MoveObject(dir); + } + /// + /// Изменение размеров формы + /// + /// + /// + + private void buttonCreateModif_Click(object sender, EventArgs e) + { + Random rnd = new(); + var ship = new DrawningLinkor(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + SetData(ship); + } + + private void comboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + _abstractMap = new SimpleMap(); + break; + case "Океан": + _abstractMap = new Ocean(); + break; + } + } + } +} diff --git a/Warship/Warship/FormMap.resx b/Warship/Warship/FormMap.resx new file mode 100644 index 0000000..5cb320f --- /dev/null +++ b/Warship/Warship/FormMap.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Warship/Warship/FormWarship.cs b/Warship/Warship/FormWarship.cs new file mode 100644 index 0000000..ed99fa6 --- /dev/null +++ b/Warship/Warship/FormWarship.cs @@ -0,0 +1,85 @@ +namespace Warship +{ + public partial class FormWarship : Form + + { + private DrawningShip _ship; + public FormWarship() + { + InitializeComponent(); + } + + private void Draw() + { + Bitmap bmp = new(pictureBoxShip.Width, pictureBoxShip.Height); + Graphics gr = Graphics.FromImage(bmp); + _ship?.DrawTransport(gr); + pictureBoxShip.Image = bmp; + } + + private void SetData() + { + toolStripStatusLabelSpeed.Text = $": {_ship.Ship.Speed}"; + toolStripStatusLabelWeight.Text = $": {_ship.Ship.Weight}"; + toolStripStatusLabelBodyColor.Text = $":" + $"{_ship.Ship.BodyColor.Name}"; + } + /// + /// "" + /// + /// + /// + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random rnd = new(); + _ship = new DrawningShip(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); + SetData(); + 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(); + } + /// + /// + /// + /// + /// + private void PictureBoxCar_Resize(object sender, EventArgs e) + { + _ship?.ChangeBorders(pictureBoxShip.Width, pictureBoxShip.Height); + Draw(); + } + + private void buttonCreateModif_Click(object sender, EventArgs e) + { + Random rnd = new(); + _ship = new DrawningLinkor(rnd.Next(100, 300), rnd.Next(1000, 2000), + Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + 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); + SetData(); + Draw(); + } + } +} \ No newline at end of file diff --git a/Warship/Warship/Program.cs b/Warship/Warship/Program.cs index 8eaf7e5..3ba6e5a 100644 --- a/Warship/Warship/Program.cs +++ b/Warship/Warship/Program.cs @@ -11,7 +11,7 @@ namespace Warship // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Warship()); + Application.Run(new FormMap()); } } } \ No newline at end of file diff --git a/Warship/Warship/Warship.Designer.cs b/Warship/Warship/Warship.Designer.cs new file mode 100644 index 0000000..0222461 --- /dev/null +++ b/Warship/Warship/Warship.Designer.cs @@ -0,0 +1,193 @@ +namespace Warship +{ + partial class Warship + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.pictureBoxShip = new System.Windows.Forms.PictureBox(); + this.button1 = 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(); + this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); + this.statusStrip1 = new System.Windows.Forms.StatusStrip(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit(); + this.statusStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // pictureBoxShip + // + 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(884, 439); + this.pictureBoxShip.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBoxShip.TabIndex = 1; + this.pictureBoxShip.TabStop = false; + this.pictureBoxShip.UseWaitCursor = true; + + this.pictureBoxShip.Resize += new System.EventHandler(this.ButtonMove_Click); + // + // button1 + // + this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.button1.Location = new System.Drawing.Point(0, 413); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 30); + this.button1.TabIndex = 2; + this.button1.Text = "Создать"; + this.button1.UseVisualStyleBackColor = true; + this.button1.UseWaitCursor = true; + this.button1.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::Warship.Properties.Resources.arrowUp; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonUp.Location = new System.Drawing.Point(806, 370); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(30, 30); + this.buttonUp.TabIndex = 3; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.UseWaitCursor = 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::Warship.Properties.Resources.arrowLeft; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonLeft.Location = new System.Drawing.Point(770, 406); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(30, 30); + this.buttonLeft.TabIndex = 4; + this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.UseWaitCursor = 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::Warship.Properties.Resources.arrowRight; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonRight.Location = new System.Drawing.Point(842, 406); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(30, 30); + this.buttonRight.TabIndex = 5; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.UseWaitCursor = 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::Warship.Properties.Resources.arrowDown; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonDown.Location = new System.Drawing.Point(806, 406); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(30, 30); + this.buttonDown.TabIndex = 6; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.UseWaitCursor = true; + this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); + // + // toolStripStatusLabelSpeed + // + this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; + this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(62, 17); + this.toolStripStatusLabelSpeed.Text = "Скорость:"; + + // + // toolStripStatusLabelWeight + // + this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; + this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(29, 17); + this.toolStripStatusLabelWeight.Text = "Вес:"; + // + // toolStripStatusLabelBodyColor + // + this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; + this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17); + this.toolStripStatusLabelBodyColor.Text = "Цвет:"; + + // + // statusStrip1 + // + this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripStatusLabelSpeed, + this.toolStripStatusLabelWeight, + this.toolStripStatusLabelBodyColor}); + this.statusStrip1.Location = new System.Drawing.Point(0, 439); + this.statusStrip1.Name = "statusStrip1"; + this.statusStrip1.Size = new System.Drawing.Size(884, 22); + this.statusStrip1.TabIndex = 0; + this.statusStrip1.Text = "statusStrip1"; + this.statusStrip1.UseWaitCursor = true; + + // + // Warship + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(884, 461); + this.Controls.Add(this.buttonDown); + this.Controls.Add(this.buttonRight); + this.Controls.Add(this.buttonLeft); + this.Controls.Add(this.buttonUp); + this.Controls.Add(this.button1); + this.Controls.Add(this.pictureBoxShip); + this.Controls.Add(this.statusStrip1); + this.Name = "Warship"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Form1"; + this.UseWaitCursor = true; + + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).EndInit(); + this.statusStrip1.ResumeLayout(false); + this.statusStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private PictureBox pictureBoxShip; + private Button button1; + private Button buttonUp; + private Button buttonLeft; + private Button buttonRight; + private Button buttonDown; + private ToolStripStatusLabel toolStripStatusLabelSpeed; + private ToolStripStatusLabel toolStripStatusLabelWeight; + private ToolStripStatusLabel toolStripStatusLabelBodyColor; + private StatusStrip statusStrip1; + } +} \ No newline at end of file diff --git a/Warship/Warship/Warship.cs b/Warship/Warship/Warship.cs new file mode 100644 index 0000000..40665e3 --- /dev/null +++ b/Warship/Warship/Warship.cs @@ -0,0 +1,76 @@ +namespace Warship +{ + public partial class Warship : Form + + { + private DrawningShip _ship; + public Warship() + { + 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); + toolStripStatusLabelSpeed.Text = $": {_ship.Ship.Speed}"; + toolStripStatusLabelWeight.Text = $": {_ship.Ship.Weight}"; + toolStripStatusLabelBodyColor.Text = $":" + + $"{_ship.Ship.BodyColor.Name}"; + + 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(); + } + /// + /// + /// + /// + /// + private void PictureBoxCar_Resize(object sender, EventArgs e) + { + _ship?.ChangeBorders(pictureBoxShip.Width, pictureBoxShip.Height); + Draw(); + } + + + } +} \ No newline at end of file diff --git a/Warship/Warship/Warship.resx b/Warship/Warship/Warship.resx new file mode 100644 index 0000000..e9e4f2e --- /dev/null +++ b/Warship/Warship/Warship.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 37, 11 + + \ No newline at end of file