Compare commits

...

6 Commits

Author SHA1 Message Date
974fa03ade последние изменения 2023-10-20 17:27:53 +04:00
146d39f5f0 переопределение 2023-10-14 20:02:54 +04:00
b576a536db изма 2023-10-08 21:34:51 +04:00
6fd602ceb6 лаба3 2023-10-06 22:06:51 +04:00
64b5568fe3 промежуточный 2023-10-06 20:36:36 +04:00
138eb45634 промежуточный 2023-10-06 20:34:43 +04:00
13 changed files with 819 additions and 37 deletions

View File

@ -5,6 +5,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Lab1ContainersShip.Entities;
using Lab1ContainersShip.MovementStrategy;
namespace Lab1ContainersShip.DrawingObjects
{
@ -52,6 +53,11 @@ namespace Lab1ContainersShip.DrawingObjects
/// Высота объекта
/// </summary>
public int GetHeight => _shipHeight;
/// <summary>
/// Получение объекта IMoveableObject из объекта DrawningCar
/// </summary>
public IMoveableObject GetMoveableObject => new
DrawningObjectShip(this);
public bool CanMove(Direction direction)
{
if(EntityShip == null) return false;
@ -149,10 +155,11 @@ namespace Lab1ContainersShip.DrawingObjects
return;
}
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),

View File

@ -21,20 +21,7 @@ namespace Lab1ContainersShip.Entities
/// Основной цвет
/// </summary>
public Color BodyColor { get; private set; }
/// <summary>
/// Дополнительный цвет (для опциональных элементов)
/// </summary>
//public Color AdditionalColor { get; private set; }
/// <summary>
/// Признак (опция) наличия крана
/// </summary>
//public bool Crane { get; private set; }
/// <summary>
/// Признак (опция) наличия контейнеров
/// </summary>
//public bool Conteiners { get; private set; }
public double Step => (double)Speed * 100 / Weight;
public EntityShip(int speed, double weight, Color bodyColor)
{

View File

@ -1,6 +1,6 @@
namespace Lab1ContainersShip
{
partial class Form1
partial class FormContainerShip
{
/// <summary>
/// Обязательная переменная конструктора.
@ -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;
}
}

View File

@ -12,17 +12,20 @@ using Lab1ContainersShip.MovementStrategy;
namespace Lab1ContainersShip
{
public partial class Form1 : Form
public partial class FormContainerShip : Form
{
private DrawingShip _drawingShip;
private AbstractStrategy _abstractStrategy;
public DrawingShip SelectedShip { get; private set; }
public Form1()
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;
}
}
}

View File

@ -0,0 +1,123 @@
namespace Lab1ContainersShip
{
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()
{
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;
}
}

View File

@ -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<DrawingShip, DrawningObjectShip> _ships;
public FormShipCollection()
{
InitializeComponent();
_ships = new ShipGenericCollection<DrawingShip,
DrawningObjectShip>(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 != -1)
{
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();
}
}
}

View 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>

View File

@ -47,17 +47,24 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AbstractStrategy.cs" />
<Compile Include="FormShipCollection.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="FormShipCollection.Designer.cs">
<DependentUpon>FormShipCollection.cs</DependentUpon>
</Compile>
<Compile Include="ShipGenericCollection.cs" />
<Compile Include="Direction.cs" />
<Compile Include="DrawingContainerShip.cs" />
<Compile Include="DrawingShip.cs" />
<Compile Include="DrawningObjectShip.cs" />
<Compile Include="EntityContainerShip.cs" />
<Compile Include="EntityShip.cs" />
<Compile Include="Form1.cs">
<Compile Include="FormContainerShip.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
<Compile Include="FormContainerShip.Designer.cs">
<DependentUpon>FormContainerShip.cs</DependentUpon>
</Compile>
<Compile Include="IMoveableObject.cs" />
<Compile Include="MoveToBorder.cs" />
@ -65,9 +72,13 @@
<Compile Include="ObjectParameters.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SetGeneric.cs" />
<Compile Include="Status.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
<EmbeddedResource Include="FormContainerShip.resx">
<DependentUpon>FormContainerShip.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="FormShipCollection.resx">
<DependentUpon>FormShipCollection.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>

View File

@ -16,7 +16,7 @@ namespace Lab1ContainersShip
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Application.Run(new FormShipCollection());
}
}
}

View File

@ -0,0 +1,161 @@
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab1ContainersShip
{
public class SetGeneric<T>
where T : class
{
// <summary>
/// Массив объектов, которые храним
/// </summary>
private readonly T[] _places;
/// <summary>
/// Количество объектов в массиве
/// </summary>
public int Count => _places.Length;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="count"></param>
public SetGeneric(int count)
{
_places = new T[count];
}
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="car">Добавляемый автомобиль</param>
/// <returns></returns>
public int Insert(T ship)
{
// TODO вставка в начало набора
int temp = 0;
int k = 0;
for(int j = 0; j < _places.Length; j++) {
if (_places[j] != null)
{
k++;
}
}
if (k == _places.Length)
{
return -1;
}
else
{
for (int i = 0; i < _places.Length; i++)
{
if (_places[i] == null)
{
temp = i;
break;
}
}
for (int i = temp; i > 0; i--)
{
_places[i] = _places[i -1];
}
_places[0] = ship;
return 0;
}
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
/// </summary>
/// <param name="car">Добавляемый автомобиль</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public bool Insert(T ship, int position)
{
// TODO проверка позиции
// TODO проверка, что элемент массива по этой позиции пустой,
//если нет, то
// проверка, что после вставляемого элемента в
//массиве есть пустой элемент
// сдвиг всех объектов, находящихся справа от
//позиции до первого пустого элемента
// TODO вставка по позиции
int temp = 0;
int k = 0;
for (int j = position; j < _places.Length; j++)
{
if (_places[j] != null)
{
k++;
}
}
if (position < _places.Length && k < _places.Length-position)
{
for (int i = position; i < _places.Length; i++)
{
if (_places[i] == null)
{
temp = i;
break;
}
}
for (int i = temp; i > position; i--)
{
_places[i] = _places[i - 1];
}
_places[position] = ship;
return true;
}
else
{
return false;
}
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public bool Remove(int position)
{
// TODO проверка позиции
// TODO удаление объекта из массива, присвоив элементу массива
//значение null
if(position < _places.Length)
{
_places[position] = null;
return true;
}
else
{
return false;
}
}
/// <summary>
/// Получение объекта из набора по позиции
/// </summary>
/// <param name="position"></param>
/// <returns></returns>
public T Get(int position)
{
// TODO проверка позиции
if(position < _places.Length)
{
return _places[position];
}
else
{
return null;
}
}
}
}

View 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>

View File

@ -0,0 +1,143 @@
using Lab1ContainersShip.DrawingObjects;
using Lab1ContainersShip.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab1ContainersShip
{
public class ShipGenericCollection <T, U>
where T : DrawingShip
where U : IMoveableObject
{
/// <summary>
/// Ширина окна прорисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна прорисовки
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Размер занимаемого объектом места (ширина)
/// </summary>
private readonly int _placeSizeWidth = 210;
/// <summary>
/// Размер занимаемого объектом места (высота)
/// </summary>
private readonly int _placeSizeHeight = 90;
/// <summary>
/// Набор объектов
/// </summary>
private readonly SetGeneric<T> _collection;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
public ShipGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = new SetGeneric<T>(width * height);
}
/// <summary>
/// Перегрузка оператора сложения
/// </summary>
/// <param name="collect"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static int operator +(ShipGenericCollection<T, U> collect, T
obj)
{
if (obj == null)
{
return -1;
}
return collect?._collection.Insert(obj) ?? -1;
}
/// <summary>
/// Перегрузка оператора вычитания
/// </summary>
/// <param name="collect"></param>
/// <param name="pos"></param>
/// <returns></returns>
public static T operator -(ShipGenericCollection<T, U> collect, int
pos)
{
T obj = collect._collection.Get(pos);
if (obj != null)
{
collect._collection.Remove(pos);
}
return obj;
}
/// <summary>
/// Получение объекта IMoveableObject
/// </summary>
/// <param name="pos"></param>
/// <returns></returns>
public U GetU(int pos)
{
return (U)_collection.Get(pos)?.GetMoveableObject;
}
/// <summary>
/// Вывод всего набора объектов
/// </summary>
/// <returns></returns>
public Bitmap ShowShips()
{
Bitmap bmp = new Bitmap(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawObjects(gr);
return bmp;
}
/// <summary>
/// Метод отрисовки фона
/// </summary>
/// <param name="g"></param>
private void DrawBackground(Graphics g)
{
Pen pen = new Pen(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);
}
}
/// <summary>
/// Метод прорисовки объектов
/// </summary>
/// <param name="g"></param>
private void DrawObjects(Graphics g)
{
for (int i = 0; i < _collection.Count; i++)
{
T t = _collection.Get(i);
if (t != null)
{
t.SetPosition(((_collection.Count -i - 1) % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, (_collection.Count - i-1) / (_pictureWidth / _placeSizeWidth) * _placeSizeHeight);
t.DrawShip(g);
}
// TODO получение объекта
// TODO установка позиции
// TODO прорисовка объекта
}
}
}
}