PIbd22_NikiforovaMV_lab3
This commit is contained in:
parent
5a3b9d61d8
commit
0a9220bf86
@ -30,7 +30,7 @@ namespace ContainerShip.DrawningObjects
|
||||
SolidBrush(containerShip.AdditionalColor);
|
||||
if (containerShip.Load)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX + 100, _startPosY + 32, 30, 20); //большой прямоугольник
|
||||
g.FillRectangle(additionalBrush, _startPosX + 100, _startPosY + 32, 30, 20);
|
||||
}
|
||||
base.DrawTransport(g);
|
||||
if (containerShip.Crane)
|
||||
|
@ -9,24 +9,24 @@ namespace ContainerShip.MovementStrategy
|
||||
{
|
||||
public class DrawingObjectShip : IMoveableObject
|
||||
{
|
||||
private readonly DrawningShip? _drawingBus = null;
|
||||
public DrawingObjectShip(DrawningShip drawingBus)
|
||||
private readonly DrawningShip? _drawingShip = null;
|
||||
public DrawingObjectShip(DrawningShip drawingShip)
|
||||
{
|
||||
_drawingBus = drawingBus;
|
||||
_drawingShip = drawingShip;
|
||||
}
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_drawingBus == null || _drawingBus.EntityShip == null)
|
||||
if (_drawingShip == null || _drawingShip.EntityShip == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawingBus.GetPosX, _drawingBus.GetPosY, _drawingBus.GetWidth, _drawingBus.GetHeight);
|
||||
return new ObjectParameters(_drawingShip.GetPosX, _drawingShip.GetPosY, _drawingShip.GetWidth, _drawingShip.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_drawingBus?.EntityShip?.Step ?? 0);
|
||||
public bool CheckCanMove(DirectionType direction) => _drawingBus?.CanMove(direction) ?? false;
|
||||
public void MoveObject(DirectionType direction) => _drawingBus?.MoveTransport(direction);
|
||||
public int GetStep => (int)(_drawingShip?.EntityShip?.Step ?? 0);
|
||||
public bool CheckCanMove(DirectionType direction) => _drawingShip?.CanMove(direction) ?? false;
|
||||
public void MoveObject(DirectionType direction) => _drawingShip?.MoveTransport(direction);
|
||||
}
|
||||
}
|
||||
|
@ -5,32 +5,26 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using ContainerShip.Entities;
|
||||
using ContainerShip.MovementStrategy;
|
||||
|
||||
namespace ContainerShip.DrawningObjects
|
||||
{
|
||||
|
||||
public class DrawningShip
|
||||
{
|
||||
public EntityShip? EntityShip { get; protected set; }
|
||||
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
protected int _startPosX;
|
||||
|
||||
protected int _startPosY;
|
||||
|
||||
protected readonly int _busWidth = 150;
|
||||
|
||||
protected readonly int _busHeight = 65;
|
||||
|
||||
protected readonly int _shipWidth = 150;
|
||||
protected readonly int _shipHeight = 65;
|
||||
public int GetPosX => _startPosX;
|
||||
public int GetPosY => _startPosY;
|
||||
public int GetWidth => _busWidth;
|
||||
public int GetHeight => _busHeight;
|
||||
|
||||
public int GetWidth => _shipWidth;
|
||||
public int GetHeight => _shipHeight;
|
||||
public DrawningShip(int speed, double weight, Color bodyColor, int width, int height)
|
||||
{
|
||||
if (width < _busWidth || height < _busHeight)
|
||||
if (width < _shipWidth || height < _shipHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -38,16 +32,16 @@ namespace ContainerShip.DrawningObjects
|
||||
_pictureHeight = height;
|
||||
EntityShip = new EntityShip(speed, weight, bodyColor);
|
||||
}
|
||||
protected DrawningShip(int speed, double weight, Color bodyColor, int width, int height, int busWidth, int busHeight)
|
||||
protected DrawningShip(int speed, double weight, Color bodyColor, int width, int height, int shipWidth, int shipHeight)
|
||||
{
|
||||
if (width < _busWidth || height < _busHeight)
|
||||
if (width < _shipWidth || height < _shipHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_busWidth = busWidth;
|
||||
_busHeight = busHeight;
|
||||
_shipWidth = shipWidth;
|
||||
_shipHeight = shipHeight;
|
||||
EntityShip = new EntityShip(speed, weight, bodyColor);
|
||||
}
|
||||
public void SetPosition(int x, int y)
|
||||
@ -67,37 +61,32 @@ namespace ContainerShip.DrawningObjects
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
|
||||
case DirectionType.Left:
|
||||
if (_startPosX - EntityShip.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityShip.Step;
|
||||
}
|
||||
break;
|
||||
|
||||
case DirectionType.Up:
|
||||
if (_startPosY - EntityShip.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityShip.Step;
|
||||
}
|
||||
break;
|
||||
|
||||
case DirectionType.Right:
|
||||
if (_startPosX + _busWidth + EntityShip.Step < _pictureWidth)
|
||||
if (_startPosX + _shipWidth + EntityShip.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityShip.Step;
|
||||
}
|
||||
break;
|
||||
|
||||
case DirectionType.Down:
|
||||
if (_startPosY + _busHeight + EntityShip.Step < _pictureHeight)
|
||||
if (_startPosY + _shipHeight + EntityShip.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityShip.Step;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black);
|
||||
@ -109,11 +98,10 @@ namespace ContainerShip.DrawningObjects
|
||||
|
||||
Point[] p = { point1, point2, point3, point4 };
|
||||
|
||||
g.FillPolygon(bodyBrush, p);
|
||||
g.FillPolygon(bodyBrush, p);
|
||||
|
||||
g.FillRectangle(bodyBrush, _startPosX + 15, _startPosY + 32, 80, 20);
|
||||
}
|
||||
|
||||
public bool CanMove(DirectionType direction)
|
||||
{
|
||||
if (EntityShip == null)
|
||||
@ -124,10 +112,12 @@ namespace ContainerShip.DrawningObjects
|
||||
{
|
||||
DirectionType.Left => _startPosX - EntityShip.Step > 0,
|
||||
DirectionType.Up => _startPosY - EntityShip.Step > 0,
|
||||
DirectionType.Right => _startPosX + _busWidth + EntityShip.Step < _pictureWidth,
|
||||
DirectionType.Down => _startPosY + _busHeight + EntityShip.Step < _pictureHeight,
|
||||
DirectionType.Right => _startPosX + _shipWidth + EntityShip.Step < _pictureWidth,
|
||||
DirectionType.Down => _startPosY + _shipHeight + EntityShip.Step < _pictureHeight,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
public IMoveableObject GetMoveableObject => new DrawingObjectShip(this);
|
||||
|
||||
}
|
||||
}
|
||||
|
127
ContainerShip/FormShipCollection.Designer.cs
generated
Normal file
127
ContainerShip/FormShipCollection.Designer.cs
generated
Normal file
@ -0,0 +1,127 @@
|
||||
namespace ContainerShip
|
||||
{
|
||||
partial class FormShipCollection
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
buttonAdd = new Button();
|
||||
buttonDelete = new Button();
|
||||
buttonUpdate = new Button();
|
||||
label1 = new Label();
|
||||
maskedTextBoxNumber = new TextBox();
|
||||
pictureBoxCollection = new PictureBox();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
buttonAdd.Location = new Point(736, 80);
|
||||
buttonAdd.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(165, 32);
|
||||
buttonAdd.TabIndex = 0;
|
||||
buttonAdd.Text = "Добавить корабль";
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
buttonAdd.Click += buttonAdd_Click;
|
||||
//
|
||||
// buttonDelete
|
||||
//
|
||||
buttonDelete.Location = new Point(738, 217);
|
||||
buttonDelete.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonDelete.Name = "buttonDelete";
|
||||
buttonDelete.Size = new Size(163, 32);
|
||||
buttonDelete.TabIndex = 1;
|
||||
buttonDelete.Text = "Удалить корабль";
|
||||
buttonDelete.UseVisualStyleBackColor = true;
|
||||
buttonDelete.Click += buttonDelete_Click;
|
||||
//
|
||||
// buttonUpdate
|
||||
//
|
||||
buttonUpdate.Location = new Point(738, 292);
|
||||
buttonUpdate.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonUpdate.Name = "buttonUpdate";
|
||||
buttonUpdate.Size = new Size(163, 32);
|
||||
buttonUpdate.TabIndex = 2;
|
||||
buttonUpdate.Text = "Обновить коллекцию";
|
||||
buttonUpdate.UseVisualStyleBackColor = true;
|
||||
buttonUpdate.Click += buttonUpdate_Click;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(774, 12);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(103, 20);
|
||||
label1.TabIndex = 3;
|
||||
label1.Text = "Инструменты";
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Location = new Point(738, 149);
|
||||
maskedTextBoxNumber.Margin = new Padding(3, 4, 3, 4);
|
||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size = new Size(162, 27);
|
||||
maskedTextBoxNumber.TabIndex = 4;
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
pictureBoxCollection.Location = new Point(0, 0);
|
||||
pictureBoxCollection.Margin = new Padding(3, 4, 3, 4);
|
||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
pictureBoxCollection.Size = new Size(731, 531);
|
||||
pictureBoxCollection.TabIndex = 5;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// FormShipCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(914, 529);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
Controls.Add(maskedTextBoxNumber);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(buttonUpdate);
|
||||
Controls.Add(buttonDelete);
|
||||
Controls.Add(buttonAdd);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormShipCollection";
|
||||
Text = "Набор кораблей";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonAdd;
|
||||
private Button buttonDelete;
|
||||
private Button buttonUpdate;
|
||||
private Label label1;
|
||||
private TextBox maskedTextBoxNumber;
|
||||
private PictureBox pictureBoxCollection;
|
||||
}
|
||||
}
|
72
ContainerShip/FormShipCollection.cs
Normal file
72
ContainerShip/FormShipCollection.cs
Normal file
@ -0,0 +1,72 @@
|
||||
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 ContainerShip.MovementStrategy;
|
||||
using ContainerShip.DrawningObjects;
|
||||
using ContainerShip.Generic;
|
||||
|
||||
namespace ContainerShip
|
||||
{
|
||||
public partial class FormShipCollection : Form
|
||||
{
|
||||
private readonly ShipsGenericCollection<DrawningShip, DrawingObjectShip> _ship;
|
||||
|
||||
public FormShipCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_ship = new ShipsGenericCollection<DrawningShip, DrawingObjectShip>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
}
|
||||
private void buttonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
FormShips form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_ship + form.SelectedShip != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = _ship.ShowShips();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
private void buttonDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = 0;
|
||||
try
|
||||
{
|
||||
pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show("Ошибка ввода данных");
|
||||
return;
|
||||
}
|
||||
if (_ship - pos)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = _ship.ShowShips();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
private void buttonUpdate_Click(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _ship.ShowShips();
|
||||
}
|
||||
}
|
||||
}
|
120
ContainerShip/FormShipCollection.resx
Normal file
120
ContainerShip/FormShipCollection.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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>
|
96
ContainerShip/FormShips.Designer.cs
generated
96
ContainerShip/FormShips.Designer.cs
generated
@ -31,13 +31,14 @@
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormShips));
|
||||
pictureBoxShips = new PictureBox();
|
||||
buttonCreateContainerShip = new Button();
|
||||
buttonCreateShip = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonCreateShip = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStep = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
button1 = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxShips).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -45,8 +46,9 @@
|
||||
//
|
||||
pictureBoxShips.Dock = DockStyle.Fill;
|
||||
pictureBoxShips.Location = new Point(0, 0);
|
||||
pictureBoxShips.Margin = new Padding(3, 2, 3, 2);
|
||||
pictureBoxShips.Name = "pictureBoxShips";
|
||||
pictureBoxShips.Size = new Size(882, 453);
|
||||
pictureBoxShips.Size = new Size(772, 340);
|
||||
pictureBoxShips.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
pictureBoxShips.TabIndex = 0;
|
||||
pictureBoxShips.TabStop = false;
|
||||
@ -54,22 +56,36 @@
|
||||
// buttonCreateContainerShip
|
||||
//
|
||||
buttonCreateContainerShip.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateContainerShip.Location = new Point(12, 364);
|
||||
buttonCreateContainerShip.Location = new Point(10, 273);
|
||||
buttonCreateContainerShip.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonCreateContainerShip.Name = "buttonCreateContainerShip";
|
||||
buttonCreateContainerShip.Size = new Size(131, 77);
|
||||
buttonCreateContainerShip.Size = new Size(115, 58);
|
||||
buttonCreateContainerShip.TabIndex = 1;
|
||||
buttonCreateContainerShip.Text = "Создать контейнеровоз";
|
||||
buttonCreateContainerShip.UseVisualStyleBackColor = true;
|
||||
buttonCreateContainerShip.Click += ButtonCreateContainerShip_Click;
|
||||
//
|
||||
// buttonCreateShip
|
||||
//
|
||||
buttonCreateShip.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateShip.Location = new Point(130, 273);
|
||||
buttonCreateShip.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonCreateShip.Name = "buttonCreateShip";
|
||||
buttonCreateShip.Size = new Size(115, 58);
|
||||
buttonCreateShip.TabIndex = 6;
|
||||
buttonCreateShip.Text = "Создать корабль";
|
||||
buttonCreateShip.UseVisualStyleBackColor = true;
|
||||
buttonCreateShip.Click += ButtonCreateShip_Click;
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage");
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonRight.Location = new Point(840, 411);
|
||||
buttonRight.Location = new Point(735, 308);
|
||||
buttonRight.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(30, 30);
|
||||
buttonRight.Size = new Size(26, 22);
|
||||
buttonRight.TabIndex = 2;
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += buttonMove_Click;
|
||||
@ -79,9 +95,10 @@
|
||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage");
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonDown.Location = new Point(804, 411);
|
||||
buttonDown.Location = new Point(704, 308);
|
||||
buttonDown.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(30, 30);
|
||||
buttonDown.Size = new Size(26, 22);
|
||||
buttonDown.TabIndex = 3;
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += buttonMove_Click;
|
||||
@ -91,9 +108,10 @@
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage");
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonLeft.Location = new Point(768, 411);
|
||||
buttonLeft.Location = new Point(672, 308);
|
||||
buttonLeft.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(30, 30);
|
||||
buttonLeft.Size = new Size(26, 22);
|
||||
buttonLeft.TabIndex = 4;
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += buttonMove_Click;
|
||||
@ -103,48 +121,54 @@
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage");
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonUp.Location = new Point(804, 375);
|
||||
buttonUp.Location = new Point(704, 281);
|
||||
buttonUp.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(30, 30);
|
||||
buttonUp.Size = new Size(26, 22);
|
||||
buttonUp.TabIndex = 5;
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += buttonMove_Click;
|
||||
//
|
||||
// buttonCreateShip
|
||||
// buttonStep
|
||||
//
|
||||
buttonCreateShip.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateShip.Location = new Point(149, 364);
|
||||
buttonCreateShip.Name = "buttonCreateShip";
|
||||
buttonCreateShip.Size = new Size(131, 77);
|
||||
buttonCreateShip.TabIndex = 6;
|
||||
buttonCreateShip.Text = "Создать корабль";
|
||||
buttonCreateShip.UseVisualStyleBackColor = true;
|
||||
buttonStep.Location = new Point(638, 34);
|
||||
buttonStep.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonStep.Name = "buttonStep";
|
||||
buttonStep.Size = new Size(112, 23);
|
||||
buttonStep.TabIndex = 8;
|
||||
buttonStep.Text = "Шаг";
|
||||
buttonStep.UseVisualStyleBackColor = true;
|
||||
buttonStep.Click += ButtonStep_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К правому нижнему краю" });
|
||||
comboBoxStrategy.Location = new Point(711, 12);
|
||||
comboBoxStrategy.Location = new Point(622, 9);
|
||||
comboBoxStrategy.Margin = new Padding(3, 2, 3, 2);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(159, 28);
|
||||
comboBoxStrategy.Size = new Size(140, 23);
|
||||
comboBoxStrategy.TabIndex = 7;
|
||||
//
|
||||
// buttonStep
|
||||
// button1
|
||||
//
|
||||
buttonStep.Location = new Point(729, 46);
|
||||
buttonStep.Name = "buttonStep";
|
||||
buttonStep.Size = new Size(128, 31);
|
||||
buttonStep.TabIndex = 8;
|
||||
buttonStep.Text = "Шаг";
|
||||
buttonStep.UseVisualStyleBackColor = true;
|
||||
buttonStep.Click += ButtonStep_Click;
|
||||
button1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
button1.Location = new Point(251, 273);
|
||||
button1.Margin = new Padding(3, 2, 3, 2);
|
||||
button1.Name = "button1";
|
||||
button1.Size = new Size(115, 58);
|
||||
button1.TabIndex = 9;
|
||||
button1.Text = "Выбрать корабль";
|
||||
button1.UseVisualStyleBackColor = true;
|
||||
button1.Click += buttonSelectedContainerShip_Click;
|
||||
//
|
||||
// FormShips
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(882, 453);
|
||||
ClientSize = new Size(772, 340);
|
||||
Controls.Add(button1);
|
||||
Controls.Add(buttonStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonCreateShip);
|
||||
@ -154,6 +178,7 @@
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonCreateContainerShip);
|
||||
Controls.Add(pictureBoxShips);
|
||||
Margin = new Padding(3, 2, 3, 2);
|
||||
Name = "FormShips";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "ContainerShip";
|
||||
@ -166,12 +191,13 @@
|
||||
|
||||
private PictureBox pictureBoxShips;
|
||||
private Button buttonCreateContainerShip;
|
||||
private Button buttonCreateShip;
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
private Button buttonCreateShip;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStep;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button button1;
|
||||
}
|
||||
}
|
@ -6,12 +6,14 @@ namespace ContainerShip
|
||||
public partial class FormShips : Form
|
||||
{
|
||||
private DrawningShip? _drawningShip;
|
||||
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
public DrawningShip? SelectedShip { get; private set; }
|
||||
|
||||
public FormShips()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractStrategy = null;
|
||||
SelectedShip = null;
|
||||
}
|
||||
private void Draw()
|
||||
{
|
||||
@ -25,34 +27,42 @@ namespace ContainerShip
|
||||
_drawningShip.DrawTransport(gr);
|
||||
pictureBoxShips.Image = bmp;
|
||||
}
|
||||
|
||||
private void ButtonCreateContainerShip_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningShip = 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)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
pictureBoxShips.Width, pictureBoxShips.Height);
|
||||
_drawningShip.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
Random random = new Random();
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
|
||||
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopColor = dialog.Color;
|
||||
}
|
||||
|
||||
_drawningShip = new DrawingContainerShip(random.Next(200, 400), random.Next(1000, 3000),
|
||||
color, dopColor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
||||
pictureBoxShips.Width, pictureBoxShips.Height);
|
||||
|
||||
_drawningShip.SetPosition(random.Next(10, 200), random.Next(10, 200));
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonCreateShip_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
_drawningShip = new DrawningShip(random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
||||
random.Next(0, 256)),
|
||||
random.Next(1000, 3000), color,
|
||||
pictureBoxShips.Width, pictureBoxShips.Height);
|
||||
_drawningShip.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
_drawningShip.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
@ -80,7 +90,6 @@ namespace ContainerShip
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
|
||||
private void ButtonStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningShip == null)
|
||||
@ -117,6 +126,13 @@ namespace ContainerShip
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSelectedContainerShip_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedShip = _drawningShip;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
|
@ -9,12 +9,11 @@ namespace ContainerShip.MovementStrategy
|
||||
{
|
||||
public interface IMoveableObject
|
||||
{
|
||||
|
||||
ObjectParameters? GetObjectPosition { get; }
|
||||
|
||||
int GetStep { get; }
|
||||
|
||||
bool CheckCanMove(DirectionType direction);
|
||||
|
||||
void MoveObject(DirectionType direction);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace ContainerShip.MovementStrategy
|
||||
{
|
||||
|
||||
public class ObjectParameters
|
||||
{
|
||||
private readonly int _x;
|
||||
@ -13,17 +14,11 @@ namespace ContainerShip.MovementStrategy
|
||||
private readonly int _width;
|
||||
private readonly int _height;
|
||||
public int LeftBorder => _x;
|
||||
|
||||
public int TopBorder => _y;
|
||||
|
||||
public int RightBorder => _x + _width;
|
||||
|
||||
public int DownBorder => _y + _height;
|
||||
|
||||
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||
|
||||
public int ObjectMiddleVertical => _y + _height / 2;
|
||||
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
|
@ -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 FormShips());
|
||||
Application.Run(new FormShipCollection());
|
||||
}
|
||||
}
|
||||
}
|
85
ContainerShip/SetGeneric.cs
Normal file
85
ContainerShip/SetGeneric.cs
Normal file
@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ContainerShip.Generic
|
||||
{
|
||||
internal class SetGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
private readonly T?[] _places;
|
||||
public int Count => _places.Length - 1;
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_places = new T?[count];
|
||||
}
|
||||
public int Insert(T ship)
|
||||
{
|
||||
int pos = Count - 1;
|
||||
if (_places[Count] != null)
|
||||
{
|
||||
|
||||
for (int i = pos; i >= 0; --i)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
pos = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int i = pos + 1; i <= Count; ++i)
|
||||
{
|
||||
_places[i - 1] = _places[i];
|
||||
}
|
||||
}
|
||||
_places[Count] = ship;
|
||||
return pos;
|
||||
}
|
||||
|
||||
public bool Insert(T ship, int position)
|
||||
{
|
||||
if (position < 0 || position > Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_places[Count] != null)
|
||||
{
|
||||
int pos = Count;
|
||||
for (int i = Count; i > 0; --i)
|
||||
{
|
||||
|
||||
if (_places[i] == null)
|
||||
{
|
||||
pos = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int i = Count; i >= pos; --i)
|
||||
{
|
||||
_places[i - 1] = _places[i];
|
||||
}
|
||||
}
|
||||
_places[Count] = ship;
|
||||
return true;
|
||||
}
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position < 0 || position > Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (position < 0 || position > Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
}
|
||||
}
|
103
ContainerShip/ShipsGenericCollection.cs
Normal file
103
ContainerShip/ShipsGenericCollection.cs
Normal file
@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ContainerShip.Generic;
|
||||
using ContainerShip.MovementStrategy;
|
||||
using ContainerShip.DrawningObjects;
|
||||
|
||||
namespace ContainerShip.Generic
|
||||
{
|
||||
internal class ShipsGenericCollection<T, U>
|
||||
where T : DrawningShip
|
||||
where U : IMoveableObject
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
private readonly int _placeSizeWidth = 210;
|
||||
private readonly int _placeSizeHeight = 90;
|
||||
private readonly SetGeneric<T> _collection;
|
||||
public ShipsGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
public static int operator +(ShipsGenericCollection<T, U> collect, T? obj)
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
return collect._collection.Insert(obj);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public static bool operator -(ShipsGenericCollection<T, U> collect, int pos)
|
||||
{
|
||||
if (collect._collection.Get(pos) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return collect?._collection.Remove(pos) ?? false;
|
||||
}
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||
}
|
||||
public Bitmap ShowShips()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawObjects(gr);
|
||||
return bmp;
|
||||
}
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||
{//линия разметки места
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j *
|
||||
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
|
||||
_placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
||||
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
int index = -1;
|
||||
for (int i = 0; i <= _collection.Count; ++i)
|
||||
{
|
||||
DrawningShip _ship = _collection.Get(i);
|
||||
x = 0;
|
||||
y = _pictureHeight / _placeSizeHeight - 1;
|
||||
if (_ship != null)
|
||||
{
|
||||
index = _collection.Count - i;
|
||||
while ((index - _pictureWidth / _placeSizeWidth) >= 0)
|
||||
{
|
||||
y--;
|
||||
index -= _pictureWidth / _placeSizeWidth;
|
||||
}
|
||||
if (index > 0)
|
||||
{
|
||||
x += index;
|
||||
}
|
||||
x = _pictureWidth / _placeSizeWidth - 1 - x;
|
||||
_ship.SetPosition(_placeSizeWidth * x, _placeSizeHeight * y);
|
||||
|
||||
_ship.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user