12 Commits

10 changed files with 830 additions and 122 deletions

View File

@@ -8,7 +8,7 @@ namespace Liner
{
internal class EntityLiner : EntityShip
{
public Color DopColor { get; private set; }
public Color DopColor { get; set; }
public bool DopDeck { get; private set; }

View File

@@ -12,7 +12,7 @@ namespace Liner
public float Weight { get; private set; }
public Color BodyColor { get; private set; }
public Color BodyColor { get; set; }
public float Step => Speed * 100 / Weight;

View File

@@ -29,6 +29,12 @@
private void InitializeComponent()
{
this.groupBox = new System.Windows.Forms.GroupBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.ButtonDeleteMap = new System.Windows.Forms.Button();
this.ListBoxMaps = new System.Windows.Forms.ListBox();
this.ButtonAddMap = new System.Windows.Forms.Button();
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
this.ComboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
@@ -38,14 +44,15 @@
this.ButtonRemoveShip = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.ButtonAddShip = new System.Windows.Forms.Button();
this.ComboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBox.SuspendLayout();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
//
// groupBox
//
this.groupBox.Controls.Add(this.groupBox1);
this.groupBox.Controls.Add(this.buttonRight);
this.groupBox.Controls.Add(this.buttonDown);
this.groupBox.Controls.Add(this.buttonUp);
@@ -55,21 +62,84 @@
this.groupBox.Controls.Add(this.ButtonRemoveShip);
this.groupBox.Controls.Add(this.maskedTextBoxPosition);
this.groupBox.Controls.Add(this.ButtonAddShip);
this.groupBox.Controls.Add(this.ComboBoxSelectorMap);
this.groupBox.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBox.Location = new System.Drawing.Point(627, 0);
this.groupBox.Location = new System.Drawing.Point(696, 0);
this.groupBox.Name = "groupBox";
this.groupBox.Size = new System.Drawing.Size(250, 450);
this.groupBox.Size = new System.Drawing.Size(279, 668);
this.groupBox.TabIndex = 0;
this.groupBox.TabStop = false;
this.groupBox.Text = "Инструменты";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.ButtonDeleteMap);
this.groupBox1.Controls.Add(this.ListBoxMaps);
this.groupBox1.Controls.Add(this.ButtonAddMap);
this.groupBox1.Controls.Add(this.textBoxNewMapName);
this.groupBox1.Controls.Add(this.ComboBoxSelectorMap);
this.groupBox1.Location = new System.Drawing.Point(6, 26);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(250, 300);
this.groupBox1.TabIndex = 18;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Карты";
//
// ButtonDeleteMap
//
this.ButtonDeleteMap.Location = new System.Drawing.Point(10, 255);
this.ButtonDeleteMap.Name = "ButtonDeleteMap";
this.ButtonDeleteMap.Size = new System.Drawing.Size(222, 29);
this.ButtonDeleteMap.TabIndex = 13;
this.ButtonDeleteMap.Text = "Удалить карту";
this.ButtonDeleteMap.UseVisualStyleBackColor = true;
this.ButtonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click);
//
// ListBoxMaps
//
this.ListBoxMaps.FormattingEnabled = true;
this.ListBoxMaps.ItemHeight = 20;
this.ListBoxMaps.Location = new System.Drawing.Point(10, 136);
this.ListBoxMaps.Name = "ListBoxMaps";
this.ListBoxMaps.Size = new System.Drawing.Size(222, 104);
this.ListBoxMaps.TabIndex = 12;
this.ListBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
//
// ButtonAddMap
//
this.ButtonAddMap.Location = new System.Drawing.Point(10, 101);
this.ButtonAddMap.Name = "ButtonAddMap";
this.ButtonAddMap.Size = new System.Drawing.Size(222, 29);
this.ButtonAddMap.TabIndex = 11;
this.ButtonAddMap.Text = "Добавить карту";
this.ButtonAddMap.UseVisualStyleBackColor = true;
this.ButtonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
//
// textBoxNewMapName
//
this.textBoxNewMapName.Location = new System.Drawing.Point(10, 34);
this.textBoxNewMapName.Name = "textBoxNewMapName";
this.textBoxNewMapName.Size = new System.Drawing.Size(222, 27);
this.textBoxNewMapName.TabIndex = 10;
//
// 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(10, 67);
this.ComboBoxSelectorMap.Name = "ComboBoxSelectorMap";
this.ComboBoxSelectorMap.Size = new System.Drawing.Size(222, 28);
this.ComboBoxSelectorMap.TabIndex = 9;
//
// buttonRight
//
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::Liner.Properties.Resources._3;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(204, 408);
this.buttonRight.Location = new System.Drawing.Point(233, 626);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 17;
@@ -81,7 +151,7 @@
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::Liner.Properties.Resources._2;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(168, 408);
this.buttonDown.Location = new System.Drawing.Point(197, 626);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 16;
@@ -93,7 +163,7 @@
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::Liner.Properties.Resources._4;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(168, 372);
this.buttonUp.Location = new System.Drawing.Point(197, 590);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 15;
@@ -105,7 +175,7 @@
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::Liner.Properties.Resources._1;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(132, 408);
this.buttonLeft.Location = new System.Drawing.Point(161, 626);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 14;
@@ -114,9 +184,9 @@
//
// ButtonShowOnMap
//
this.ButtonShowOnMap.Location = new System.Drawing.Point(28, 323);
this.ButtonShowOnMap.Location = new System.Drawing.Point(16, 558);
this.ButtonShowOnMap.Name = "ButtonShowOnMap";
this.ButtonShowOnMap.Size = new System.Drawing.Size(200, 29);
this.ButtonShowOnMap.Size = new System.Drawing.Size(222, 29);
this.ButtonShowOnMap.TabIndex = 13;
this.ButtonShowOnMap.Text = "Посмотреть карту";
this.ButtonShowOnMap.UseVisualStyleBackColor = true;
@@ -124,9 +194,9 @@
//
// ButtonShowStorage
//
this.ButtonShowStorage.Location = new System.Drawing.Point(28, 258);
this.ButtonShowStorage.Location = new System.Drawing.Point(16, 505);
this.ButtonShowStorage.Name = "ButtonShowStorage";
this.ButtonShowStorage.Size = new System.Drawing.Size(200, 29);
this.ButtonShowStorage.Size = new System.Drawing.Size(222, 29);
this.ButtonShowStorage.TabIndex = 12;
this.ButtonShowStorage.Text = "Посмотреть хранилище";
this.ButtonShowStorage.UseVisualStyleBackColor = true;
@@ -134,9 +204,9 @@
//
// ButtonRemoveShip
//
this.ButtonRemoveShip.Location = new System.Drawing.Point(28, 191);
this.ButtonRemoveShip.Location = new System.Drawing.Point(16, 452);
this.ButtonRemoveShip.Name = "ButtonRemoveShip";
this.ButtonRemoveShip.Size = new System.Drawing.Size(200, 29);
this.ButtonRemoveShip.Size = new System.Drawing.Size(222, 29);
this.ButtonRemoveShip.TabIndex = 11;
this.ButtonRemoveShip.Text = "Удалить корабль";
this.ButtonRemoveShip.UseVisualStyleBackColor = true;
@@ -144,42 +214,28 @@
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(28, 158);
this.maskedTextBoxPosition.Location = new System.Drawing.Point(16, 419);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(200, 27);
this.maskedTextBoxPosition.Size = new System.Drawing.Size(222, 27);
this.maskedTextBoxPosition.TabIndex = 10;
//
// ButtonAddShip
//
this.ButtonAddShip.Location = new System.Drawing.Point(28, 110);
this.ButtonAddShip.Location = new System.Drawing.Point(16, 368);
this.ButtonAddShip.Name = "ButtonAddShip";
this.ButtonAddShip.Size = new System.Drawing.Size(200, 29);
this.ButtonAddShip.Size = new System.Drawing.Size(222, 29);
this.ButtonAddShip.TabIndex = 2;
this.ButtonAddShip.Text = "Добавить корабль";
this.ButtonAddShip.UseVisualStyleBackColor = true;
this.ButtonAddShip.Click += new System.EventHandler(this.ButtonAddShip_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(28, 38);
this.ComboBoxSelectorMap.Name = "ComboBoxSelectorMap";
this.ComboBoxSelectorMap.Size = new System.Drawing.Size(200, 28);
this.ComboBoxSelectorMap.TabIndex = 9;
this.ComboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// 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(627, 450);
this.pictureBox.Size = new System.Drawing.Size(696, 668);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
@@ -187,13 +243,15 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(877, 450);
this.ClientSize = new System.Drawing.Size(975, 668);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBox);
this.Name = "FormMapWithSetShips";
this.Text = "FormMapWithSetShips";
this.groupBox.ResumeLayout(false);
this.groupBox.PerformLayout();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false);
@@ -213,5 +271,10 @@
private Button buttonDown;
private Button buttonUp;
private Button buttonLeft;
private GroupBox groupBox1;
private Button ButtonDeleteMap;
private ListBox ListBoxMaps;
private Button ButtonAddMap;
private TextBox textBoxNewMapName;
}
}

View File

@@ -13,59 +13,71 @@ namespace Liner
{
public partial class FormMapWithSetShips : Form
{
private MapWithSetShipsGeneric<DrawingObjectShip, AbstractMap> _mapShipsCollectionGeneric;
private readonly Dictionary<string, AbstractMap> _mapDict = new()
{
{"Простая карта", new SimpleMap() },
{"Море и айсберги", new SeaMap() },
{"Болото",new SwampMap() }
};
private readonly MapsCollection _mapsCollection;
public FormMapWithSetShips()
{
InitializeComponent();
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
ComboBoxSelectorMap.Items.Clear();
foreach (var elem in _mapDict)
{
ComboBoxSelectorMap.Items.Add(elem.Key);
}
}
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
private void ReloadMaps()
{
AbstractMap map = null;
switch (ComboBoxSelectorMap.Text)
int index = ListBoxMaps.SelectedIndex;
ListBoxMaps.Items.Clear();
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
{
case "Простая карта":
map = new SimpleMap();
break;
case "Море и айсберги":
map = new SeaMap();
break;
case "Болото":
map = new SwampMap();
break;
ListBoxMaps.Items.Add(_mapsCollection.Keys[i]);
}
if (map != null)
if (ListBoxMaps.Items.Count > 0 && (index == -1 || index >= ListBoxMaps.Items.Count))
{
_mapShipsCollectionGeneric = new MapWithSetShipsGeneric<DrawingObjectShip, AbstractMap>(
pictureBox.Width, pictureBox.Height, map);
ListBoxMaps.SelectedIndex = 0;
}
else
else if (ListBoxMaps.Items.Count > 0 && index > -1 && index < ListBoxMaps.Items.Count)
{
_mapShipsCollectionGeneric = null;
ListBoxMaps.SelectedIndex = index;
}
}
private void ButtonAddShip_Click(object sender, EventArgs e)
{
if (_mapShipsCollectionGeneric == null)
var formShipConfig = new FormShipConfig();
formShipConfig.AddEvent(AddShip);
formShipConfig.Show();
}
private void AddShip(DrawingShip ship)
{
if (ListBoxMaps.SelectedIndex == -1)
{
return;
}
FormShip form = new();
if (form.ShowDialog() == DialogResult.OK)
if (_mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawingObjectShip(ship) != -1)
{
DrawingObjectShip ship = new(form.SelectedShip);
if (_mapShipsCollectionGeneric + ship != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapShipsCollectionGeneric.ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
private void ButtonRemoveShip_Click(object sender, EventArgs e)
{
if (ListBoxMaps.SelectedIndex == -1)
{
return;
}
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{
return;
@@ -75,10 +87,10 @@ namespace Liner
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapShipsCollectionGeneric - pos != null)
if (_mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapShipsCollectionGeneric.ShowSet();
pictureBox.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
@@ -87,23 +99,23 @@ namespace Liner
}
private void ButtonShowStorage_Click(object sender, EventArgs e)
{
if (_mapShipsCollectionGeneric == null)
if (ListBoxMaps.SelectedIndex == -1)
{
return;
}
pictureBox.Image = _mapShipsCollectionGeneric.ShowSet();
pictureBox.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
private void ButtonShowOnMap_Click(object sender, EventArgs e)
{
if (_mapShipsCollectionGeneric == null)
if (ListBoxMaps.SelectedIndex == -1)
{
return;
}
pictureBox.Image = _mapShipsCollectionGeneric.ShowOnMap();
pictureBox.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_mapShipsCollectionGeneric == null)
if (ListBoxMaps.SelectedIndex == -1)
{
return;
}
@@ -124,7 +136,38 @@ namespace Liner
dir = Direction.Right;
break;
}
pictureBox.Image = _mapShipsCollectionGeneric.MoveObject(dir);
pictureBox.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
}
private void ButtonAddMap_Click(object sender, EventArgs e)
{
if (ComboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!_mapDict.ContainsKey(ComboBoxSelectorMap.Text))
{
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapDict[ComboBoxSelectorMap.Text]);
ReloadMaps();
}
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBox.Image = _mapsCollection[ListBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
private void ButtonDeleteMap_Click(object sender, EventArgs e)
{
if (ListBoxMaps.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Удалить карту {ListBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_mapsCollection.DelMap(ListBoxMaps.SelectedItem?.ToString() ?? string.Empty);
ReloadMaps();
}
}
}
}

381
Liner/Liner/FormShipConfig.Designer.cs generated Normal file
View File

@@ -0,0 +1,381 @@
namespace Liner
{
partial class FormShipConfig
{
/// <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.groupBoxConfig = new System.Windows.Forms.GroupBox();
this.labelModifObject = new System.Windows.Forms.Label();
this.labelSimpleObject = new System.Windows.Forms.Label();
this.groupBoxColors = new System.Windows.Forms.GroupBox();
this.panelBlack = new System.Windows.Forms.Panel();
this.panelPurple = new System.Windows.Forms.Panel();
this.panelCyan = new System.Windows.Forms.Panel();
this.panelWhite = new System.Windows.Forms.Panel();
this.panelBlue = new System.Windows.Forms.Panel();
this.panelGreen = new System.Windows.Forms.Panel();
this.panelYellow = new System.Windows.Forms.Panel();
this.panelRed = new System.Windows.Forms.Panel();
this.checkBoxDopDeck = new System.Windows.Forms.CheckBox();
this.checkBoxPool = new System.Windows.Forms.CheckBox();
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
this.labelWeight = new System.Windows.Forms.Label();
this.labelSpeed = new System.Windows.Forms.Label();
this.panelObject = new System.Windows.Forms.Panel();
this.LabelDopColor = new System.Windows.Forms.Label();
this.LabelBaseColor = new System.Windows.Forms.Label();
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
this.buttonAdd = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.groupBoxConfig.SuspendLayout();
this.groupBoxColors.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
this.panelObject.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
this.SuspendLayout();
//
// groupBoxConfig
//
this.groupBoxConfig.Controls.Add(this.labelModifObject);
this.groupBoxConfig.Controls.Add(this.labelSimpleObject);
this.groupBoxConfig.Controls.Add(this.groupBoxColors);
this.groupBoxConfig.Controls.Add(this.checkBoxDopDeck);
this.groupBoxConfig.Controls.Add(this.checkBoxPool);
this.groupBoxConfig.Controls.Add(this.numericUpDownWeight);
this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed);
this.groupBoxConfig.Controls.Add(this.labelWeight);
this.groupBoxConfig.Controls.Add(this.labelSpeed);
this.groupBoxConfig.Location = new System.Drawing.Point(12, 12);
this.groupBoxConfig.Name = "groupBoxConfig";
this.groupBoxConfig.Size = new System.Drawing.Size(492, 243);
this.groupBoxConfig.TabIndex = 0;
this.groupBoxConfig.TabStop = false;
this.groupBoxConfig.Text = "Параметры";
//
// labelModifObject
//
this.labelModifObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelModifObject.Location = new System.Drawing.Point(366, 159);
this.labelModifObject.Name = "labelModifObject";
this.labelModifObject.Size = new System.Drawing.Size(115, 46);
this.labelModifObject.TabIndex = 8;
this.labelModifObject.Text = "Продвинутый";
this.labelModifObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelModifObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// labelSimpleObject
//
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelSimpleObject.Location = new System.Drawing.Point(258, 159);
this.labelSimpleObject.Name = "labelSimpleObject";
this.labelSimpleObject.Size = new System.Drawing.Size(102, 46);
this.labelSimpleObject.TabIndex = 7;
this.labelSimpleObject.Text = "Простой";
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// groupBoxColors
//
this.groupBoxColors.Controls.Add(this.panelBlack);
this.groupBoxColors.Controls.Add(this.panelPurple);
this.groupBoxColors.Controls.Add(this.panelCyan);
this.groupBoxColors.Controls.Add(this.panelWhite);
this.groupBoxColors.Controls.Add(this.panelBlue);
this.groupBoxColors.Controls.Add(this.panelGreen);
this.groupBoxColors.Controls.Add(this.panelYellow);
this.groupBoxColors.Controls.Add(this.panelRed);
this.groupBoxColors.Location = new System.Drawing.Point(258, 23);
this.groupBoxColors.Name = "groupBoxColors";
this.groupBoxColors.Size = new System.Drawing.Size(223, 134);
this.groupBoxColors.TabIndex = 6;
this.groupBoxColors.TabStop = false;
this.groupBoxColors.Text = "Цвета";
//
// panelBlack
//
this.panelBlack.BackColor = System.Drawing.Color.Black;
this.panelBlack.Location = new System.Drawing.Point(172, 75);
this.panelBlack.Name = "panelBlack";
this.panelBlack.Size = new System.Drawing.Size(45, 45);
this.panelBlack.TabIndex = 1;
//
// panelPurple
//
this.panelPurple.BackColor = System.Drawing.Color.Purple;
this.panelPurple.Location = new System.Drawing.Point(121, 77);
this.panelPurple.Name = "panelPurple";
this.panelPurple.Size = new System.Drawing.Size(45, 45);
this.panelPurple.TabIndex = 1;
//
// panelCyan
//
this.panelCyan.BackColor = System.Drawing.Color.Cyan;
this.panelCyan.Location = new System.Drawing.Point(57, 77);
this.panelCyan.Name = "panelCyan";
this.panelCyan.Size = new System.Drawing.Size(45, 45);
this.panelCyan.TabIndex = 1;
//
// panelWhite
//
this.panelWhite.BackColor = System.Drawing.Color.White;
this.panelWhite.Location = new System.Drawing.Point(6, 76);
this.panelWhite.Name = "panelWhite";
this.panelWhite.Size = new System.Drawing.Size(45, 45);
this.panelWhite.TabIndex = 1;
//
// panelBlue
//
this.panelBlue.BackColor = System.Drawing.Color.Blue;
this.panelBlue.Location = new System.Drawing.Point(172, 25);
this.panelBlue.Name = "panelBlue";
this.panelBlue.Size = new System.Drawing.Size(45, 45);
this.panelBlue.TabIndex = 2;
//
// panelGreen
//
this.panelGreen.BackColor = System.Drawing.Color.Green;
this.panelGreen.Location = new System.Drawing.Point(121, 25);
this.panelGreen.Name = "panelGreen";
this.panelGreen.Size = new System.Drawing.Size(45, 45);
this.panelGreen.TabIndex = 1;
//
// panelYellow
//
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
this.panelYellow.Location = new System.Drawing.Point(57, 26);
this.panelYellow.Name = "panelYellow";
this.panelYellow.Size = new System.Drawing.Size(45, 45);
this.panelYellow.TabIndex = 1;
//
// panelRed
//
this.panelRed.BackColor = System.Drawing.Color.Red;
this.panelRed.Location = new System.Drawing.Point(6, 25);
this.panelRed.Name = "panelRed";
this.panelRed.Size = new System.Drawing.Size(45, 45);
this.panelRed.TabIndex = 0;
//
// checkBoxDopDeck
//
this.checkBoxDopDeck.AutoSize = true;
this.checkBoxDopDeck.Location = new System.Drawing.Point(6, 159);
this.checkBoxDopDeck.Name = "checkBoxDopDeck";
this.checkBoxDopDeck.Size = new System.Drawing.Size(243, 24);
this.checkBoxDopDeck.TabIndex = 5;
this.checkBoxDopDeck.Text = "Признак наличия доп. палубы";
this.checkBoxDopDeck.UseVisualStyleBackColor = true;
//
// checkBoxPool
//
this.checkBoxPool.AutoSize = true;
this.checkBoxPool.Location = new System.Drawing.Point(6, 119);
this.checkBoxPool.Name = "checkBoxPool";
this.checkBoxPool.Size = new System.Drawing.Size(223, 24);
this.checkBoxPool.TabIndex = 4;
this.checkBoxPool.Text = "Признак наличия бассейна";
this.checkBoxPool.UseVisualStyleBackColor = true;
//
// numericUpDownWeight
//
this.numericUpDownWeight.Location = new System.Drawing.Point(88, 66);
this.numericUpDownWeight.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.numericUpDownWeight.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDownWeight.Name = "numericUpDownWeight";
this.numericUpDownWeight.Size = new System.Drawing.Size(150, 27);
this.numericUpDownWeight.TabIndex = 3;
this.numericUpDownWeight.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// numericUpDownSpeed
//
this.numericUpDownSpeed.Location = new System.Drawing.Point(88, 33);
this.numericUpDownSpeed.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.numericUpDownSpeed.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
this.numericUpDownSpeed.Size = new System.Drawing.Size(150, 27);
this.numericUpDownSpeed.TabIndex = 2;
this.numericUpDownSpeed.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// labelWeight
//
this.labelWeight.AutoSize = true;
this.labelWeight.Location = new System.Drawing.Point(6, 73);
this.labelWeight.Name = "labelWeight";
this.labelWeight.Size = new System.Drawing.Size(36, 20);
this.labelWeight.TabIndex = 1;
this.labelWeight.Text = "Вес:";
//
// labelSpeed
//
this.labelSpeed.AutoSize = true;
this.labelSpeed.Location = new System.Drawing.Point(0, 40);
this.labelSpeed.Name = "labelSpeed";
this.labelSpeed.Size = new System.Drawing.Size(76, 20);
this.labelSpeed.TabIndex = 0;
this.labelSpeed.Text = "Скорость:";
//
// panelObject
//
this.panelObject.AllowDrop = true;
this.panelObject.Controls.Add(this.LabelDopColor);
this.panelObject.Controls.Add(this.LabelBaseColor);
this.panelObject.Controls.Add(this.pictureBoxObject);
this.panelObject.Location = new System.Drawing.Point(510, 21);
this.panelObject.Name = "panelObject";
this.panelObject.Size = new System.Drawing.Size(250, 204);
this.panelObject.TabIndex = 1;
this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
//
// LabelDopColor
//
this.LabelDopColor.AllowDrop = true;
this.LabelDopColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.LabelDopColor.Location = new System.Drawing.Point(130, 8);
this.LabelDopColor.Name = "LabelDopColor";
this.LabelDopColor.Size = new System.Drawing.Size(117, 46);
this.LabelDopColor.TabIndex = 8;
this.LabelDopColor.Text = "Доп. цвет";
this.LabelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.LabelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragDrop);
this.LabelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
//
// LabelBaseColor
//
this.LabelBaseColor.AllowDrop = true;
this.LabelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.LabelBaseColor.Location = new System.Drawing.Point(3, 8);
this.LabelBaseColor.Name = "LabelBaseColor";
this.LabelBaseColor.Size = new System.Drawing.Size(117, 46);
this.LabelBaseColor.TabIndex = 8;
this.LabelBaseColor.Text = "Цвет";
this.LabelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.LabelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop);
this.LabelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelColor_DragEnter);
//
// pictureBoxObject
//
this.pictureBoxObject.Location = new System.Drawing.Point(3, 57);
this.pictureBoxObject.Name = "pictureBoxObject";
this.pictureBoxObject.Size = new System.Drawing.Size(244, 144);
this.pictureBoxObject.TabIndex = 0;
this.pictureBoxObject.TabStop = false;
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(513, 231);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(94, 29);
this.buttonAdd.TabIndex = 2;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(663, 231);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
this.buttonCancel.TabIndex = 3;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// FormShipConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(770, 267);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.panelObject);
this.Controls.Add(this.groupBoxConfig);
this.Name = "FormShipConfig";
this.Text = "Создание объекта";
this.groupBoxConfig.ResumeLayout(false);
this.groupBoxConfig.PerformLayout();
this.groupBoxColors.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
this.panelObject.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBoxConfig;
private Label labelModifObject;
private Label labelSimpleObject;
private GroupBox groupBoxColors;
private Panel panelBlack;
private Panel panelPurple;
private Panel panelCyan;
private Panel panelWhite;
private Panel panelBlue;
private Panel panelGreen;
private Panel panelYellow;
private Panel panelRed;
private CheckBox checkBoxDopDeck;
private CheckBox checkBoxPool;
private NumericUpDown numericUpDownWeight;
private NumericUpDown numericUpDownSpeed;
private Label labelWeight;
private Label labelSpeed;
private Panel panelObject;
private Label LabelDopColor;
private Label LabelBaseColor;
private PictureBox pictureBoxObject;
private Button buttonAdd;
private Button buttonCancel;
}
}

View File

@@ -0,0 +1,118 @@
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 Liner
{
public partial class FormShipConfig : Form
{
DrawingShip _ship=null;
private event Action<DrawingShip> EventAddShip;
public FormShipConfig()
{
InitializeComponent();
panelBlack.MouseDown += PanelColor_MouseDown;
panelPurple.MouseDown += PanelColor_MouseDown;
panelCyan.MouseDown += PanelColor_MouseDown;
panelGreen.MouseDown += PanelColor_MouseDown;
panelRed.MouseDown += PanelColor_MouseDown;
panelWhite.MouseDown += PanelColor_MouseDown;
panelYellow.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown;
buttonCancel.Click += (s, a) => Close();
}
public void DrawShip()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_ship?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height);
_ship?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
public void AddEvent(Action<DrawingShip> ev)
{
if (EventAddShip == null)
{
EventAddShip = new Action<DrawingShip>(ev);
}
else
{
EventAddShip += ev;
}
}
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy);
}
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void PanelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data.GetData(DataFormats.Text).ToString())
{
case "labelSimpleObject":
_ship = new DrawingShip((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White);
break;
case "labelModifObject":
_ship = new DrawningLiner((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black,
checkBoxDopDeck.Checked, checkBoxPool.Checked);
break;
}
DrawShip();
}
private void LabelColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
{
if (_ship == null)
{
return;
}
_ship.Ship.BodyColor=(Color)e.Data.GetData(typeof(Color));
DrawShip();
}
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
{
if (_ship == null || _ship.Ship is not EntityLiner liner)
{
return;
}
liner.DopColor=(Color)e.Data.GetData(typeof(Color));
DrawShip();
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
EventAddShip?.Invoke(_ship);
Close();
}
}
}

View File

@@ -0,0 +1,60 @@
<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>
</root>

View File

@@ -44,13 +44,9 @@ namespace Liner
public Bitmap ShowOnMap()
{
Shaking();
for (int i = 0; i < _setShips.Count; i++)
foreach (var ship in _setShips.GetShips())
{
var ship = _setShips.Get(i);
if (ship != null)
{
return _map.CreateMap(_pictureWidth, _pictureHeight, ship);
}
return _map.CreateMap(_pictureWidth, _pictureHeight, ship);
}
return new(_pictureWidth, _pictureHeight);
}
@@ -67,11 +63,11 @@ namespace Liner
int j = _setShips.Count - 1;
for (int i = 0; i < _setShips.Count; i++)
{
if (_setShips.Get(i) == null)
if (_setShips[i] == null)
{
for (; j > i; j--)
{
var ship = _setShips.Get(j);
var ship = _setShips[j];
if (ship != null)
{
_setShips.Insert(ship, i);
@@ -107,11 +103,11 @@ namespace Liner
int heightEl = _pictureHeight / _placeSizeHeight;
int curWidth = 1;
int curHeight = 0;
for (int i = 0; i < _setShips.Count; i++)
foreach (var ship in _setShips.GetShips())
{
_setShips.Get(i)?.SetObject(_pictureWidth - _placeSizeWidth * curWidth - (_pictureWidth / 7),
ship?.SetObject(_pictureWidth - _placeSizeWidth * curWidth - 10,
curHeight * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
_setShips.Get(i)?.DrawningObject(g);
ship?.DrawningObject(g);
if (curWidth < widthEl)
curWidth++;

View File

@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Liner
{
internal class MapsCollection
{
readonly Dictionary<string, MapWithSetShipsGeneric<DrawingObjectShip, AbstractMap>> _mapStorages;
public List<string> Keys => _mapStorages.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
public MapsCollection(int pictureWidth, int pictureHeight)
{
_mapStorages = new Dictionary<string, MapWithSetShipsGeneric<DrawingObjectShip, AbstractMap>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
public void AddMap(string name, AbstractMap map)
{
if (!_mapStorages.ContainsKey(name))
{
_mapStorages.Add(name, new MapWithSetShipsGeneric<DrawingObjectShip, AbstractMap>(_pictureWidth, _pictureHeight, map));
}
}
public void DelMap(string name)
{
if (_mapStorages.ContainsKey(name)) _mapStorages.Remove(name);
}
public MapWithSetShipsGeneric<DrawingObjectShip, AbstractMap> this[string ind]
{
get
{
if (_mapStorages.ContainsKey(ind))
{
return _mapStorages[ind];
}
return null;
}
}
}
}

View File

@@ -9,11 +9,13 @@ namespace Liner
internal class SetShipsGeneric<T>
where T : class
{
private readonly T[] _places;
public int Count => _places.Length;
private readonly List<T> _places;
public int Count => _places.Count;
private readonly int _maxCount;
public SetShipsGeneric(int count)
{
_places = new T[count];
_maxCount = count;
_places = new List<T>();
}
public int Insert(T ship)
{
@@ -21,52 +23,53 @@ namespace Liner
}
public int Insert(T ship, int position)
{
if (position >= _places.Length || position < 0)
{
return -1;
}
if (_places[position] == null)
{
_places[position] = ship;
return position;
}
int emptyIndex = -1;
for (int i = position + 1; i < Count; i++)
{
if (_places[i] == null)
{
emptyIndex = i;
break;
}
}
if (emptyIndex < 0)
{
return -1;
}
for (int i = emptyIndex; i > position; i--)
{
_places[i] = _places[i - 1];
}
_places[position] = ship;
if (position < 0 || position > Count || _maxCount == Count) return -1;
_places.Insert(position, ship);
return position;
}
public T Remove(int position)
{
if (position >= _places.Length || position < 0)
if (position >= Count || position < 0)
{
return null;
}
T ship = _places[position];
_places[position] = null;
_places.RemoveAt(position);
return ship;
}
public T Get(int position)
public T this[int position]
{
if (position >= _places.Length || position < 0)
get
{
return null;
if (position >= Count || position < 0)
{
return null;
}
return _places[position];
}
set
{
if (position >= Count || position < 0)
{
return;
}
Insert(value, position);
}
}
public IEnumerable<T> GetShips()
{
foreach (var ship in _places)
{
if (ship != null)
{
yield return ship;
}
else
{
yield break;
}
}
return _places[position];
}
}
}