Nevaeva K. A. LabWork03 #3

Merged
eegov merged 3 commits from Lab_3 into Lab_2 2022-11-07 10:55:09 +04:00
12 changed files with 403 additions and 325 deletions
Showing only changes of commit 55300032aa - Show all commits

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace ContainerShip
{
internal enum Direction
public enum Direction
{
None = 0,
Up = 1,

View File

@ -7,7 +7,7 @@ using static ContainerShip.EntityShip;
namespace ContainerShip
{
internal class DrawingShip
public class DrawingShip
{
public EntityShip Ship { protected set; get; }
protected float _startPosX;

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace ContainerShip
{
internal class EntityShip
public class EntityShip
{
/// <summary>
/// Скорость

View File

@ -1,212 +0,0 @@
namespace ContainerShip
{
partial class FormMap
{
/// <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.statusStrip1 = 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.buttonRight = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.pictureBoxShip = new System.Windows.Forms.PictureBox();
this.ButtonCreate = new System.Windows.Forms.Button();
this.ButtonCreateModif = new System.Windows.Forms.Button();
this.ComboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.statusStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit();
this.SuspendLayout();
//
// statusStrip1
//
this.statusStrip1.ImageScalingSize = new System.Drawing.Size(24, 24);
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabelSpeed,
this.toolStripStatusLabelWeight,
this.toolStripStatusLabelBodyColor});
this.statusStrip1.Location = new System.Drawing.Point(0, 418);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(800, 32);
this.statusStrip1.TabIndex = 0;
this.statusStrip1.Text = "statusStrip1";
//
// toolStripStatusLabelSpeed
//
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(93, 25);
this.toolStripStatusLabelSpeed.Text = "Скорость:";
//
// toolStripStatusLabelWeight
//
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(43, 25);
this.toolStripStatusLabelWeight.Text = "Вес:";
//
// toolStripStatusLabelBodyColor
//
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(55, 25);
this.toolStripStatusLabelBodyColor.Text = "Цвет:";
//
// buttonRight
//
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::ContainerShip.Properties.Resources.LeftArrow;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(738, 353);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(50, 50);
this.buttonRight.TabIndex = 2;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.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::ContainerShip.Properties.Resources.upArrow;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(682, 306);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(50, 50);
this.buttonUp.TabIndex = 3;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.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::ContainerShip.Properties.Resources.DownArrow;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(682, 352);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(50, 50);
this.buttonDown.TabIndex = 4;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.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::ContainerShip.Properties.Resources.RightArrow;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(626, 353);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(50, 50);
this.buttonLeft.TabIndex = 5;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
// 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(800, 418);
this.pictureBoxShip.TabIndex = 7;
this.pictureBoxShip.TabStop = false;
//
// ButtonCreate
//
this.ButtonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.ButtonCreate.BackColor = System.Drawing.SystemColors.Window;
this.ButtonCreate.Location = new System.Drawing.Point(12, 381);
this.ButtonCreate.Name = "ButtonCreate";
this.ButtonCreate.Size = new System.Drawing.Size(112, 34);
this.ButtonCreate.TabIndex = 8;
this.ButtonCreate.Text = "Создать";
this.ButtonCreate.UseVisualStyleBackColor = false;
this.ButtonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
//
// ButtonCreateModif
//
this.ButtonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.ButtonCreateModif.BackColor = System.Drawing.SystemColors.Window;
this.ButtonCreateModif.Location = new System.Drawing.Point(130, 381);
this.ButtonCreateModif.Name = "ButtonCreateModif";
this.ButtonCreateModif.Size = new System.Drawing.Size(143, 34);
this.ButtonCreateModif.TabIndex = 9;
this.ButtonCreateModif.Text = "Модификация";
this.ButtonCreateModif.UseVisualStyleBackColor = false;
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(279, 385);
this.ComboBoxSelectorMap.Name = "ComboBoxSelectorMap";
this.ComboBoxSelectorMap.Size = new System.Drawing.Size(182, 33);
this.ComboBoxSelectorMap.TabIndex = 10;
this.ComboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged_1);
//
// FormMap
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.ComboBoxSelectorMap);
this.Controls.Add(this.ButtonCreateModif);
this.Controls.Add(this.ButtonCreate);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.pictureBoxShip);
this.Controls.Add(this.statusStrip1);
this.Name = "FormMap";
this.Text = "Карта";
this.Click += new System.EventHandler(this.ButtonMove_Click);
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private StatusStrip statusStrip1;
private Button buttonRight;
private Button buttonUp;
private Button buttonDown;
private Button buttonLeft;
private ToolStripStatusLabel toolStripStatusLabelSpeed;
private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
private PictureBox pictureBoxShip;
private Button ButtonCreate;
private Button ButtonCreateModif;
private ComboBox ComboBoxSelectorMap;
}
}

View File

@ -1,102 +0,0 @@
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 ContainerShip
{
public partial class FormMap : Form
{
private DrawingShip _ship;
private AbstractMap _abstractMap;
public FormMap()
{
InitializeComponent();
_abstractMap = new SimpleMap();
}
/// <summary>
/// Изменение размеров формы
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SetData(DrawingShip 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 DrawingObjectShip(ship));
}
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
var ship = new DrawingShip(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
SetData(ship);
}
/// <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;
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);
}
/// <summary>
/// Обработка нажатия кнопки "Модификация"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new();
var ship = new DrawingContainerShip(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)),
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData(ship);
}
/// <summary>
/// Смена карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxSelectorMap_SelectedIndexChanged_1(object sender, EventArgs e)
{
switch (ComboBoxSelectorMap.Text)
{
case "Простая карта":
_abstractMap = new SimpleMap();
break;
case "Модифицированная карта":
_abstractMap = new ModifyMap();
break;
}
}
}
}

View File

@ -0,0 +1,206 @@
namespace ContainerShip
{
partial class FormMapWithSetShips
{
/// <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.groupBox1 = new System.Windows.Forms.GroupBox();
this.ButtonAddShip = new System.Windows.Forms.Button();
this.ComboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.ButtonShowStorage = new System.Windows.Forms.Button();
this.ButtonRemoveShip = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.ButtonAddShip);
this.groupBox1.Controls.Add(this.ComboBoxSelectorMap);
this.groupBox1.Controls.Add(this.buttonUp);
this.groupBox1.Controls.Add(this.buttonRight);
this.groupBox1.Controls.Add(this.buttonDown);
this.groupBox1.Controls.Add(this.buttonLeft);
this.groupBox1.Controls.Add(this.button3);
this.groupBox1.Controls.Add(this.ButtonShowStorage);
this.groupBox1.Controls.Add(this.ButtonRemoveShip);
this.groupBox1.Controls.Add(this.maskedTextBoxPosition);
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBox1.Location = new System.Drawing.Point(553, 0);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(300, 508);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Инструменты";
//
// ButtonAddShip
//
this.ButtonAddShip.Location = new System.Drawing.Point(6, 74);
this.ButtonAddShip.Name = "ButtonAddShip";
this.ButtonAddShip.Size = new System.Drawing.Size(288, 34);
this.ButtonAddShip.TabIndex = 11;
this.ButtonAddShip.Text = "Добавить корабль";
this.ButtonAddShip.UseVisualStyleBackColor = true;
//
// ComboBoxSelectorMap
//
this.ComboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.ComboBoxSelectorMap.Items.AddRange(new object[] {
"Простая карта",
"Модифицированная карта"});
this.ComboBoxSelectorMap.Location = new System.Drawing.Point(6, 35);
this.ComboBoxSelectorMap.Name = "ComboBoxSelectorMap";
this.ComboBoxSelectorMap.Size = new System.Drawing.Size(288, 33);
this.ComboBoxSelectorMap.TabIndex = 10;
//
// buttonUp
//
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::ContainerShip.Properties.Resources.upArrow;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(131, 390);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(50, 50);
this.buttonUp.TabIndex = 9;
this.buttonUp.UseVisualStyleBackColor = true;
//
// buttonRight
//
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::ContainerShip.Properties.Resources.LeftArrow;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(187, 446);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(50, 50);
this.buttonRight.TabIndex = 8;
this.buttonRight.UseVisualStyleBackColor = true;
//
// buttonDown
//
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::ContainerShip.Properties.Resources.DownArrow;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(131, 446);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(50, 50);
this.buttonDown.TabIndex = 7;
this.buttonDown.UseVisualStyleBackColor = true;
//
// buttonLeft
//
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::ContainerShip.Properties.Resources.RightArrow;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(75, 446);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(50, 50);
this.buttonLeft.TabIndex = 6;
this.buttonLeft.UseVisualStyleBackColor = true;
//
// button3
//
this.button3.Location = new System.Drawing.Point(8, 292);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(286, 34);
this.button3.TabIndex = 3;
this.button3.Text = "Посмотреть карту";
this.button3.UseVisualStyleBackColor = true;
//
// ButtonShowStorage
//
this.ButtonShowStorage.Location = new System.Drawing.Point(6, 243);
this.ButtonShowStorage.Name = "ButtonShowStorage";
this.ButtonShowStorage.Size = new System.Drawing.Size(288, 34);
this.ButtonShowStorage.TabIndex = 2;
this.ButtonShowStorage.Text = "Просмотреть хранилище";
this.ButtonShowStorage.UseVisualStyleBackColor = true;
//
// ButtonRemoveShip
//
this.ButtonRemoveShip.Location = new System.Drawing.Point(6, 162);
this.ButtonRemoveShip.Name = "ButtonRemoveShip";
this.ButtonRemoveShip.Size = new System.Drawing.Size(288, 41);
this.ButtonRemoveShip.TabIndex = 1;
this.ButtonRemoveShip.Text = "Удалить корабль";
this.ButtonRemoveShip.UseVisualStyleBackColor = true;
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 125);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(288, 31);
this.maskedTextBoxPosition.TabIndex = 0;
//
// pictureBox
//
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 0);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(553, 508);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
// FormMapWithSetShips
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(853, 508);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBox1);
this.Name = "FormMapWithSetShips";
this.Text = "Карта с набором объектов";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBox1;
private Button button3;
private Button ButtonShowStorage;
private Button ButtonRemoveShip;
private MaskedTextBox maskedTextBoxPosition;
private PictureBox pictureBox;
private Button buttonLeft;
private Button buttonDown;
private Button buttonUp;
private Button buttonRight;
private Button ButtonAddShip;
private ComboBox ComboBoxSelectorMap;
}
}

View File

@ -0,0 +1,164 @@
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;
using static System.Windows.Forms.DataFormats;
namespace ContainerShip
{
public partial class FormMapWithSetShips : Form
{
/// <summary>
/// Объект от класса карты с набором объектов
/// </summary>
private MapWithSetShipsGeneric<DrawingObjectShip, AbstractMap> _mapShipsCollectionGeneric;
/// <summary>
/// Конструктор
/// </summary>
public FormMapWithSetShips()
{
InitializeComponent();
}
/// <summary>
/// Выбор карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
AbstractMap map = null;
switch (ComboBoxSelectorMap.Text)
{
case "Простая карта":
map = new SimpleMap();
break;
case "Модифицированная карта":
map = new ModifyMap();
break;
}
if (map != null)
{
_mapShipsCollectionGeneric = new MapWithSetShipsGeneric<DrawingObjectShip, AbstractMap>(
pictureBox.Width, pictureBox.Height, map);
}
else
{
_mapShipsCollectionGeneric = null;
}
}
/// <summary>
/// Добавление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddShip_Click(object sender, EventArgs e)
{
if (_mapShipsCollectionGeneric == null)
{
return;
}
FormShip form = new();
if (form.ShowDialog() == DialogResult.OK)
{
DrawingObjectShip car = new(form.SelectedShip);
if (_mapShipsCollectionGeneric + car)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapShipsCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveShip_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapShipsCollectionGeneric - pos)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapShipsCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Вывод набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowStorage_Click(object sender, EventArgs e)
{
if (_mapShipsCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapShipsCollectionGeneric.ShowSet();
}
/// <summary>
/// Вывод карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonShowOnMap_Click(object sender, EventArgs e)
{
if (_mapShipsCollectionGeneric == null)
{
return;
}
pictureBox.Image = _mapShipsCollectionGeneric.ShowOnMap();
}
/// <summary>
/// Перемещение
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_mapShipsCollectionGeneric == null)
{
return;
}
//получаем имя кнопки
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;
}
pictureBox.Image = _mapShipsCollectionGeneric.MoveObject(dir);
}
}
}

View File

@ -57,7 +57,4 @@
<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">
<value>17, 17</value>
</metadata>
</root>

View File

@ -39,6 +39,7 @@
this.pictureBoxShip = new System.Windows.Forms.PictureBox();
this.ButtonCreate = new System.Windows.Forms.Button();
this.ButtonCreateModif = new System.Windows.Forms.Button();
this.ButtonSelectShip = new System.Windows.Forms.Button();
this.statusStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit();
this.SuspendLayout();
@ -79,7 +80,7 @@
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::ContainerShip.Properties.Resources.LeftArrow;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(738, 353);
this.buttonRight.Location = new System.Drawing.Point(738, 362);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(50, 50);
this.buttonRight.TabIndex = 2;
@ -103,7 +104,7 @@
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::ContainerShip.Properties.Resources.DownArrow;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(682, 352);
this.buttonDown.Location = new System.Drawing.Point(682, 362);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(50, 50);
this.buttonDown.TabIndex = 4;
@ -115,7 +116,7 @@
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::ContainerShip.Properties.Resources.RightArrow;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(626, 353);
this.buttonLeft.Location = new System.Drawing.Point(626, 362);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(50, 50);
this.buttonLeft.TabIndex = 5;
@ -155,11 +156,24 @@
this.ButtonCreateModif.UseVisualStyleBackColor = false;
this.ButtonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
//
// ButtonSelectShip
//
this.ButtonSelectShip.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.ButtonSelectShip.BackColor = System.Drawing.SystemColors.Window;
this.ButtonSelectShip.Location = new System.Drawing.Point(479, 381);
this.ButtonSelectShip.Name = "ButtonSelectShip";
this.ButtonSelectShip.Size = new System.Drawing.Size(112, 34);
this.ButtonSelectShip.TabIndex = 10;
this.ButtonSelectShip.Text = "Выбрать";
this.ButtonSelectShip.UseVisualStyleBackColor = false;
this.ButtonSelectShip.Click += new System.EventHandler(this.ButtonSelectShip_Click);
//
// FormShip
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.ButtonSelectShip);
this.Controls.Add(this.ButtonCreateModif);
this.Controls.Add(this.ButtonCreate);
this.Controls.Add(this.buttonLeft);
@ -192,5 +206,6 @@
private PictureBox pictureBoxShip;
private Button ButtonCreate;
private Button ButtonCreateModif;
private Button ButtonSelectShip;
}
}

View File

@ -3,6 +3,10 @@ namespace ContainerShip
public partial class FormShip : Form
{
private DrawingShip _ship;
/// <summary>
/// âûáðàííûé îáõåêò
/// </summary>
public DrawingShip SelectedShip { get; private set; }
public FormShip()
{
InitializeComponent();
@ -91,5 +95,10 @@ namespace ContainerShip
Draw();
}
private void ButtonSelectShip_Click(object sender, EventArgs e)
{
SelectedShip = _ship;
DialogResult = DialogResult.OK;
}
}
}

View File

@ -163,7 +163,8 @@ namespace ContainerShip
{
for (int i = 0; i < _setShips.Count; i++)
{
//TODO установка позиции
//TODO установка позиции
_setShips.Get(i)?.DrawingObject(g);
}
}
}

View File

@ -11,7 +11,7 @@ namespace ContainerShip
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormMap());
Application.Run(new FormMapWithSetShips());
}
}
}