diff --git a/Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs b/Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs
index f2c0173..5a03eed 100644
--- a/Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs
+++ b/Lab1ContainersShip/Lab1ContainersShip/DrawingShip.cs
@@ -157,8 +157,9 @@ namespace Lab1ContainersShip.DrawingObjects
Pen pen = new Pen(Color.Black);
//Brush adbrush = new SolidBrush(EntityShip.AdditionalColor);
Brush brBlue = new SolidBrush(Color.Blue);
+ Brush brBody = new SolidBrush(EntityShip.BodyColor);
// заполнение борта
- g.FillPolygon(brBlue, new PointF[]
+ g.FillPolygon(brBody, new PointF[]
{
new PointF(_startPosX, _startPosY+45),
new PointF(_startPosX+20, _startPosY+65),
diff --git a/Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.Designer.cs b/Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.Designer.cs
index 767edb8..2a11900 100644
--- a/Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.Designer.cs
+++ b/Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.Designer.cs
@@ -37,6 +37,7 @@
this.buttonStep = new System.Windows.Forms.Button();
this.buttonCreateContainerShip = new System.Windows.Forms.Button();
this.buttonCreateShip = new System.Windows.Forms.Button();
+ this.ButtonSelectCar = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
@@ -140,11 +141,22 @@
this.buttonCreateShip.UseVisualStyleBackColor = true;
this.buttonCreateShip.Click += new System.EventHandler(this.buttonCreateShip_Click);
//
- // Form1
+ // ButtonSelectCar
+ //
+ this.ButtonSelectCar.Location = new System.Drawing.Point(335, 418);
+ this.ButtonSelectCar.Name = "ButtonSelectCar";
+ this.ButtonSelectCar.Size = new System.Drawing.Size(75, 23);
+ this.ButtonSelectCar.TabIndex = 10;
+ this.ButtonSelectCar.Text = "выбрать";
+ this.ButtonSelectCar.UseVisualStyleBackColor = true;
+ this.ButtonSelectCar.Click += new System.EventHandler(this.ButtonSelectCar_Click);
+ //
+ // FormContainerShip
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(884, 461);
+ this.Controls.Add(this.ButtonSelectCar);
this.Controls.Add(this.buttonCreateShip);
this.Controls.Add(this.buttonCreateContainerShip);
this.Controls.Add(this.buttonStep);
@@ -154,7 +166,7 @@
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.pictureBox1);
- this.Name = "Form1";
+ this.Name = "FormContainerShip";
this.Text = "контейнеровоз";
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
@@ -173,6 +185,7 @@
private System.Windows.Forms.Button buttonStep;
private System.Windows.Forms.Button buttonCreateContainerShip;
private System.Windows.Forms.Button buttonCreateShip;
+ private System.Windows.Forms.Button ButtonSelectCar;
}
}
diff --git a/Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.cs b/Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.cs
index 1c4c918..3c793eb 100644
--- a/Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.cs
+++ b/Lab1ContainersShip/Lab1ContainersShip/FormContainerShip.cs
@@ -18,13 +18,16 @@ namespace Lab1ContainersShip
private AbstractStrategy _abstractStrategy;
-
+ public DrawingShip SelectedShip { get; private set; }
public FormContainerShip()
{
InitializeComponent();
+ _abstractStrategy = null;
+ SelectedShip = null;
+
}
-
+
private void Draw()
{
@@ -120,12 +123,23 @@ namespace Lab1ContainersShip
private void buttonCreateContainerShip_Click(object sender, EventArgs e)
{
Random random = new Random();
+ Color color = Color.FromArgb(random.Next(0, 256),
+random.Next(0, 256), random.Next(0, 256));
+ ColorDialog dialog = new ColorDialog();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ }
+ Color dopColor = Color.FromArgb(random.Next(0, 256),
+random.Next(0, 256), random.Next(0, 256));
+ ColorDialog dopdialog = new ColorDialog();
+ if (dopdialog.ShowDialog() == DialogResult.OK)
+ {
+ dopColor = dopdialog.Color;
+ }
_drawingShip = new DrawingContainerShip(random.Next(100, 300),
random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
- random.Next(0, 256)),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
- random.Next(0, 256)),
+ color, dopColor,
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)),
pictureBox1.Width, pictureBox1.Height);
@@ -137,15 +151,25 @@ namespace Lab1ContainersShip
private void buttonCreateShip_Click(object sender, EventArgs e)
{
Random random = new Random();
- _drawingShip = new DrawingShip(random.Next(100, 300),
- random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
- random.Next(0, 256)),
+ Color color = Color.FromArgb(random.Next(0, 256),
+random.Next(0, 256), random.Next(0, 256));
+ ColorDialog dialog = new ColorDialog();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ }
+
+ _drawingShip = new DrawingShip(random.Next(100, 300), random.Next(1000, 3000),color,
pictureBox1.Width, pictureBox1.Height);
_drawingShip.SetPosition(random.Next(10, 100), random.Next(10,
100));
Draw();
}
+ private void ButtonSelectCar_Click(object sender, EventArgs e)
+ {
+ SelectedShip = _drawingShip;
+ DialogResult = DialogResult.OK;
+ }
}
}
diff --git a/Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.Designer.cs b/Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.Designer.cs
new file mode 100644
index 0000000..16457f6
--- /dev/null
+++ b/Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.Designer.cs
@@ -0,0 +1,123 @@
+namespace Lab1ContainersShip
+{
+ partial class FormShipCollection
+ {
+ ///
+ /// 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.panel1 = new System.Windows.Forms.Panel();
+ this.ButtonAddCar = new System.Windows.Forms.Button();
+ this.ButtonRemoveCar = new System.Windows.Forms.Button();
+ this.ButtonRefreshCollection = new System.Windows.Forms.Button();
+ this.maskedTextBoxNumber = new System.Windows.Forms.TextBox();
+ this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
+ this.panel1.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
+ this.SuspendLayout();
+ //
+ // panel1
+ //
+ this.panel1.Controls.Add(this.maskedTextBoxNumber);
+ this.panel1.Controls.Add(this.ButtonRefreshCollection);
+ this.panel1.Controls.Add(this.ButtonRemoveCar);
+ this.panel1.Controls.Add(this.ButtonAddCar);
+ this.panel1.Location = new System.Drawing.Point(646, 0);
+ this.panel1.Name = "panel1";
+ this.panel1.Size = new System.Drawing.Size(157, 449);
+ this.panel1.TabIndex = 1;
+ //
+ // ButtonAddCar
+ //
+ this.ButtonAddCar.Location = new System.Drawing.Point(16, 29);
+ this.ButtonAddCar.Name = "ButtonAddCar";
+ this.ButtonAddCar.Size = new System.Drawing.Size(118, 53);
+ this.ButtonAddCar.TabIndex = 0;
+ this.ButtonAddCar.Text = "добавить";
+ this.ButtonAddCar.UseVisualStyleBackColor = true;
+ this.ButtonAddCar.Click += new System.EventHandler(this.ButtonAddCar_Click);
+ //
+ // ButtonRemoveCar
+ //
+ this.ButtonRemoveCar.Location = new System.Drawing.Point(16, 209);
+ this.ButtonRemoveCar.Name = "ButtonRemoveCar";
+ this.ButtonRemoveCar.Size = new System.Drawing.Size(118, 50);
+ this.ButtonRemoveCar.TabIndex = 1;
+ this.ButtonRemoveCar.Text = "удалить";
+ this.ButtonRemoveCar.UseVisualStyleBackColor = true;
+ this.ButtonRemoveCar.Click += new System.EventHandler(this.ButtonRemoveCar_Click);
+ //
+ // ButtonRefreshCollection
+ //
+ this.ButtonRefreshCollection.Location = new System.Drawing.Point(16, 341);
+ this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
+ this.ButtonRefreshCollection.Size = new System.Drawing.Size(118, 50);
+ this.ButtonRefreshCollection.TabIndex = 2;
+ this.ButtonRefreshCollection.Text = "обновить коллекцию";
+ this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
+ this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
+ //
+ // maskedTextBoxNumber
+ //
+ this.maskedTextBoxNumber.Location = new System.Drawing.Point(25, 183);
+ this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
+ this.maskedTextBoxNumber.Size = new System.Drawing.Size(100, 20);
+ this.maskedTextBoxNumber.TabIndex = 3;
+ //
+ // pictureBoxCollection
+ //
+ this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
+ this.pictureBoxCollection.Name = "pictureBoxCollection";
+ this.pictureBoxCollection.Size = new System.Drawing.Size(640, 449);
+ this.pictureBoxCollection.TabIndex = 0;
+ this.pictureBoxCollection.TabStop = false;
+ //
+ // FormShipCollection
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.panel1);
+ this.Controls.Add(this.pictureBoxCollection);
+ this.Name = "FormShipCollection";
+ this.Text = "FormShipCollection";
+ this.Load += new System.EventHandler(this.FormShipCollection_Load);
+ this.panel1.ResumeLayout(false);
+ this.panel1.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.PictureBox pictureBoxCollection;
+ private System.Windows.Forms.Panel panel1;
+ private System.Windows.Forms.TextBox maskedTextBoxNumber;
+ private System.Windows.Forms.Button ButtonRefreshCollection;
+ private System.Windows.Forms.Button ButtonRemoveCar;
+ private System.Windows.Forms.Button ButtonAddCar;
+ }
+}
\ No newline at end of file
diff --git a/Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.cs b/Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.cs
new file mode 100644
index 0000000..e7642bb
--- /dev/null
+++ b/Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.cs
@@ -0,0 +1,73 @@
+using Lab1ContainersShip.DrawingObjects;
+using Lab1ContainersShip.MovementStrategy;
+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 Lab1ContainersShip
+{
+ public partial class FormShipCollection : Form
+ {
+ private readonly ShipGenericCollection _ships;
+ public FormShipCollection()
+ {
+ InitializeComponent();
+ _ships = new ShipGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height);
+ }
+
+ private void FormShipCollection_Load(object sender, EventArgs e)
+ {
+
+ }
+
+ private void ButtonAddCar_Click(object sender, EventArgs e)
+ {
+ FormContainerShip form = new FormContainerShip();
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (_ships + form.SelectedShip)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBoxCollection.Image = _ships.ShowShips();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+
+ }
+
+ private void ButtonRemoveCar_Click(object sender, EventArgs e)
+ {
+ if (MessageBox.Show("Удалить объект?", "Удаление",
+MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+ int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
+ if (_ships - pos != null)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBoxCollection.Image = _ships.ShowShips();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+
+ }
+
+ private void ButtonRefreshCollection_Click(object sender, EventArgs e)
+ {
+ pictureBoxCollection.Image = _ships.ShowShips();
+ }
+ }
+}
diff --git a/Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.resx b/Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/Lab1ContainersShip/Lab1ContainersShip/FormShipCollection.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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
+
+
\ No newline at end of file
diff --git a/Lab1ContainersShip/Lab1ContainersShip/Lab1ContainersShip.csproj b/Lab1ContainersShip/Lab1ContainersShip/Lab1ContainersShip.csproj
index 7225e59..32ff75e 100644
--- a/Lab1ContainersShip/Lab1ContainersShip/Lab1ContainersShip.csproj
+++ b/Lab1ContainersShip/Lab1ContainersShip/Lab1ContainersShip.csproj
@@ -47,6 +47,12 @@
+
+ Form
+
+
+ FormShipCollection.cs
+
@@ -71,6 +77,9 @@
FormContainerShip.cs
+
+ FormShipCollection.cs
+
ResXFileCodeGenerator
Resources.Designer.cs
diff --git a/Lab1ContainersShip/Lab1ContainersShip/Program.cs b/Lab1ContainersShip/Lab1ContainersShip/Program.cs
index e6271c4..bf2ee79 100644
--- a/Lab1ContainersShip/Lab1ContainersShip/Program.cs
+++ b/Lab1ContainersShip/Lab1ContainersShip/Program.cs
@@ -16,7 +16,7 @@ namespace Lab1ContainersShip
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new FormContainerShip());
+ Application.Run(new FormShipCollection());
}
}
}
diff --git a/Lab1ContainersShip/Lab1ContainersShip/ShipGenericCollection.cs b/Lab1ContainersShip/Lab1ContainersShip/ShipGenericCollection.cs
index 9e94c34..18dbd8c 100644
--- a/Lab1ContainersShip/Lab1ContainersShip/ShipGenericCollection.cs
+++ b/Lab1ContainersShip/Lab1ContainersShip/ShipGenericCollection.cs
@@ -90,7 +90,7 @@ namespace Lab1ContainersShip
/// Вывод всего набора объектов
///
///
- public Bitmap ShowCShips()
+ public Bitmap ShowShips()
{
Bitmap bmp = new Bitmap(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
@@ -126,9 +126,13 @@ namespace Lab1ContainersShip
{
for (int i = 0; i < _collection.Count; i++)
{
+
T t = _collection.Get(i);
- t.SetPosition((i * (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, i / (_pictureWidth / _placeSizeWidth) * _placeSizeHeight);
- t.DrawShip(g);
+ if (t != null)
+ {
+ t.SetPosition((i % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, i / (_pictureWidth / _placeSizeWidth) * _placeSizeHeight);
+ t.DrawShip(g);
+ }
// TODO получение объекта
// TODO установка позиции
// TODO прорисовка объекта