Compare commits
3 Commits
803043d6b8
...
82c3809904
Author | SHA1 | Date | |
---|---|---|---|
82c3809904 | |||
93d33965fe | |||
29e4a164f8 |
@ -38,9 +38,8 @@ namespace ProjectTank.MovementStrategy
|
||||
/// <param name="moveableObject">Перемещаемый объект</param>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
public void SetData(IMoveableObject moveableObject, int width, int
|
||||
height)
|
||||
{
|
||||
public void SetData(IMoveableObject moveableObject, int width,
|
||||
int height){
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = Status.NotInit;
|
||||
|
142
ProjectTank/ProjectTank/ArmoredTransportCollectionForm.Designer.cs
generated
Normal file
142
ProjectTank/ProjectTank/ArmoredTransportCollectionForm.Designer.cs
generated
Normal file
@ -0,0 +1,142 @@
|
||||
namespace ProjectTank
|
||||
{
|
||||
partial class ArmoredTransportCollectionForm
|
||||
{
|
||||
/// <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.components = new System.ComponentModel.Container();
|
||||
this.ArmoredTransportCollectionFormToolsGroup = new System.Windows.Forms.GroupBox();
|
||||
this.ButtonRefreshCollection = new System.Windows.Forms.Button();
|
||||
this.ButtonRemoveArmoredTransport = new System.Windows.Forms.Button();
|
||||
this.maskedTextBoxNumber = new System.Windows.Forms.TextBox();
|
||||
this.ButtonAddArmoredTransport = new System.Windows.Forms.Button();
|
||||
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
|
||||
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||
this.ArmoredTransportCollectionFormToolsGroup.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// ArmoredTransportCollectionFormToolsGroup
|
||||
//
|
||||
this.ArmoredTransportCollectionFormToolsGroup.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.ArmoredTransportCollectionFormToolsGroup.Controls.Add(this.ButtonRefreshCollection);
|
||||
this.ArmoredTransportCollectionFormToolsGroup.Controls.Add(this.ButtonRemoveArmoredTransport);
|
||||
this.ArmoredTransportCollectionFormToolsGroup.Controls.Add(this.maskedTextBoxNumber);
|
||||
this.ArmoredTransportCollectionFormToolsGroup.Controls.Add(this.ButtonAddArmoredTransport);
|
||||
this.ArmoredTransportCollectionFormToolsGroup.Location = new System.Drawing.Point(1057, -4);
|
||||
this.ArmoredTransportCollectionFormToolsGroup.Name = "ArmoredTransportCollectionFormToolsGroup";
|
||||
this.ArmoredTransportCollectionFormToolsGroup.Size = new System.Drawing.Size(431, 865);
|
||||
this.ArmoredTransportCollectionFormToolsGroup.TabIndex = 0;
|
||||
this.ArmoredTransportCollectionFormToolsGroup.TabStop = false;
|
||||
this.ArmoredTransportCollectionFormToolsGroup.Text = "Инструменты";
|
||||
//
|
||||
// ButtonRefreshCollection
|
||||
//
|
||||
this.ButtonRefreshCollection.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.ButtonRefreshCollection.Location = new System.Drawing.Point(22, 394);
|
||||
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||
this.ButtonRefreshCollection.Size = new System.Drawing.Size(391, 47);
|
||||
this.ButtonRefreshCollection.TabIndex = 3;
|
||||
this.ButtonRefreshCollection.Text = "Обновить коллекцию";
|
||||
this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
|
||||
//
|
||||
// ButtonRemoveArmoredTransport
|
||||
//
|
||||
this.ButtonRemoveArmoredTransport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.ButtonRemoveArmoredTransport.Location = new System.Drawing.Point(22, 251);
|
||||
this.ButtonRemoveArmoredTransport.Name = "ButtonRemoveArmoredTransport";
|
||||
this.ButtonRemoveArmoredTransport.Size = new System.Drawing.Size(391, 82);
|
||||
this.ButtonRemoveArmoredTransport.TabIndex = 2;
|
||||
this.ButtonRemoveArmoredTransport.Text = "Удалить бронированный транспорт";
|
||||
this.ButtonRemoveArmoredTransport.UseVisualStyleBackColor = true;
|
||||
this.ButtonRemoveArmoredTransport.Click += new System.EventHandler(this.ButtonRemoveArmoredTransport_Click);
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
this.maskedTextBoxNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(71, 188);
|
||||
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
this.maskedTextBoxNumber.Size = new System.Drawing.Size(275, 39);
|
||||
this.maskedTextBoxNumber.TabIndex = 1;
|
||||
//
|
||||
// ButtonAddArmoredTransport
|
||||
//
|
||||
this.ButtonAddArmoredTransport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.ButtonAddArmoredTransport.Location = new System.Drawing.Point(22, 88);
|
||||
this.ButtonAddArmoredTransport.Name = "ButtonAddArmoredTransport";
|
||||
this.ButtonAddArmoredTransport.Size = new System.Drawing.Size(391, 82);
|
||||
this.ButtonAddArmoredTransport.TabIndex = 0;
|
||||
this.ButtonAddArmoredTransport.Text = "Добавить бронированный транспорт";
|
||||
this.ButtonAddArmoredTransport.UseVisualStyleBackColor = true;
|
||||
this.ButtonAddArmoredTransport.Click += new System.EventHandler(this.ButtonAddArmoredTransport_Click);
|
||||
//
|
||||
// contextMenuStrip1
|
||||
//
|
||||
this.contextMenuStrip1.ImageScalingSize = new System.Drawing.Size(32, 32);
|
||||
this.contextMenuStrip1.Name = "contextMenuStrip1";
|
||||
this.contextMenuStrip1.Size = new System.Drawing.Size(61, 4);
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
this.pictureBoxCollection.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
this.pictureBoxCollection.Size = new System.Drawing.Size(1492, 873);
|
||||
this.pictureBoxCollection.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBoxCollection.TabIndex = 2;
|
||||
this.pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// ArmoredTransportCollectionForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1492, 873);
|
||||
this.Controls.Add(this.ArmoredTransportCollectionFormToolsGroup);
|
||||
this.Controls.Add(this.pictureBoxCollection);
|
||||
this.Name = "ArmoredTransportCollectionForm";
|
||||
this.Text = "ArmoredTransportCollectionForm";
|
||||
this.ArmoredTransportCollectionFormToolsGroup.ResumeLayout(false);
|
||||
this.ArmoredTransportCollectionFormToolsGroup.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox ArmoredTransportCollectionFormToolsGroup;
|
||||
private Button ButtonRefreshCollection;
|
||||
private Button ButtonRemoveArmoredTransport;
|
||||
private TextBox maskedTextBoxNumber;
|
||||
private Button ButtonAddArmoredTransport;
|
||||
private ContextMenuStrip contextMenuStrip1;
|
||||
private PictureBox pictureBoxCollection;
|
||||
}
|
||||
}
|
88
ProjectTank/ProjectTank/ArmoredTransportCollectionForm.cs
Normal file
88
ProjectTank/ProjectTank/ArmoredTransportCollectionForm.cs
Normal file
@ -0,0 +1,88 @@
|
||||
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 ProjectTank.DrawningObjects;
|
||||
using ProjectTank.Generics;
|
||||
using ProjectTank.MovementStrategy;
|
||||
|
||||
namespace ProjectTank
|
||||
{
|
||||
/// <summary>
|
||||
/// Форма для работы с набором объектов класса DrawningCar
|
||||
/// </summary>
|
||||
public partial class ArmoredTransportCollectionForm : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly ArmoredTransportsGenericCollection<DrawningArmoredTransport, DrawningObjectArmoredTransport> _armoredTransports;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public ArmoredTransportCollectionForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
_armoredTransports = new ArmoredTransportsGenericCollection<DrawningArmoredTransport,DrawningObjectArmoredTransport>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddArmoredTransport_Click(object sender, EventArgs e)
|
||||
{
|
||||
TankForm form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_armoredTransports + form.SelectedArmoredTransport != null)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = _armoredTransports.ShowArmoredTransports();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveArmoredTransport_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
if (_armoredTransports - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = _armoredTransports.ShowArmoredTransports();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Обновление рисунка по набору
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs
|
||||
e)
|
||||
{
|
||||
pictureBoxCollection.Image = _armoredTransports.ShowArmoredTransports();
|
||||
}
|
||||
}
|
||||
}
|
63
ProjectTank/ProjectTank/ArmoredTransportCollectionForm.resx
Normal file
63
ProjectTank/ProjectTank/ArmoredTransportCollectionForm.resx
Normal file
@ -0,0 +1,63 @@
|
||||
<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>
|
||||
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
146
ProjectTank/ProjectTank/ArmoredTransportsGenericCollection.cs
Normal file
146
ProjectTank/ProjectTank/ArmoredTransportsGenericCollection.cs
Normal file
@ -0,0 +1,146 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectTank.DrawningObjects;
|
||||
using ProjectTank.MovementStrategy;
|
||||
|
||||
namespace ProjectTank.Generics
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметризованный класс для набора объектов DrawningArmoredTransport
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="U"></typeparam>
|
||||
internal class ArmoredTransportsGenericCollection<T, U>
|
||||
where T : DrawningArmoredTransport
|
||||
where U : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Ширина окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (ширина)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeWidth = 200;
|
||||
/// <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 ArmoredTransportsGenericCollection(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 +(ArmoredTransportsGenericCollection<T, U> collect, T? obj)
|
||||
{
|
||||
if (obj == null || collect == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return collect._collection.Insert(obj);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator -(ArmoredTransportsGenericCollection<T, U> collect, int pos)
|
||||
{
|
||||
T? obj = collect?._collection.Get(pos);
|
||||
if (obj != null && collect != null)
|
||||
{
|
||||
return collect._collection.Remove(pos);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/// <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 ShowArmoredTransports()
|
||||
{
|
||||
Bitmap bmp = new(_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(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.DrawString("P", new Font("Courier New", 30.0F), new SolidBrush(Color.Blue),
|
||||
new Point(i * _placeSizeWidth, (j-1) * _placeSizeHeight));
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth,
|
||||
_pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки объектов
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int width = (_pictureWidth / _placeSizeWidth);
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
DrawningArmoredTransport? armoredTransport = _collection.Get(i);
|
||||
if (armoredTransport != null)
|
||||
{
|
||||
int row = height - 1 - (i / width);
|
||||
int col = width - 1 - (i % width);
|
||||
armoredTransport.SetPosition(col * _placeSizeWidth, row * _placeSizeHeight);
|
||||
armoredTransport.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectTank.Entities;
|
||||
using ProjectTank.MovementStrategy;
|
||||
|
||||
namespace ProjectTank.DrawningObjects
|
||||
{
|
||||
@ -57,6 +58,10 @@ namespace ProjectTank.DrawningObjects
|
||||
/// </summary>
|
||||
public int GetHeight => _transportHeight;
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject из объекта DrawningArmoredTransport
|
||||
/// </summary>
|
||||
public IMoveableObject GetMoveableObject => new DrawningObjectArmoredTransport(this);
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
|
@ -8,7 +8,7 @@ using ProjectTank.DrawningObjects;
|
||||
namespace ProjectTank.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Реализация интерфейса IDrawningObject для работы с объектом DrawningCar(паттерн Adapter)
|
||||
/// Реализация интерфейса IDrawningObject для работы с объектом DrawningArmoredTransport(паттерн Adapter)
|
||||
/// </summary>
|
||||
public class DrawningObjectArmoredTransport : IMoveableObject
|
||||
{
|
||||
|
@ -10,8 +10,10 @@ namespace ProjectTank
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new TankForm());
|
||||
Application.Run(new ArmoredTransportCollectionForm());
|
||||
}
|
||||
}
|
||||
}
|
99
ProjectTank/ProjectTank/SetGeneric.cs
Normal file
99
ProjectTank/ProjectTank/SetGeneric.cs
Normal file
@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectTank.Generics
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal 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="armoredTransport">Добавляемый автомобиль</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T armoredTransport)
|
||||
{
|
||||
if (_places[Count - 1] != null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Insert(armoredTransport,0);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="car">Добавляемый автомобиль</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T armoredTransport, int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count))
|
||||
return -1;
|
||||
if (_places[position] != null)
|
||||
{
|
||||
int ind = position;
|
||||
while (ind < Count && _places[ind] != null)
|
||||
ind++;
|
||||
if (ind == Count)
|
||||
return -1;
|
||||
for (int i = ind - 1; i >= position; i--)
|
||||
_places[i + 1] = _places[i];
|
||||
}
|
||||
_places[position] = armoredTransport;
|
||||
return position;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count) || _places[position] == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
}
|
||||
}
|
15
ProjectTank/ProjectTank/TankForm.Designer.cs
generated
15
ProjectTank/ProjectTank/TankForm.Designer.cs
generated
@ -38,6 +38,7 @@
|
||||
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
|
||||
this.ButtonCreateArmoredTransport = new System.Windows.Forms.Button();
|
||||
this.ButtonStep = new System.Windows.Forms.Button();
|
||||
this.ButtonSelectArmoredTransport = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTanks)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@ -162,11 +163,24 @@
|
||||
this.ButtonStep.UseVisualStyleBackColor = true;
|
||||
this.ButtonStep.Click += new System.EventHandler(this.ButtonStep_Click);
|
||||
//
|
||||
// ButtonSelectArmoredTransport
|
||||
//
|
||||
this.ButtonSelectArmoredTransport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.ButtonSelectArmoredTransport.Location = new System.Drawing.Point(664, 806);
|
||||
this.ButtonSelectArmoredTransport.Margin = new System.Windows.Forms.Padding(6);
|
||||
this.ButtonSelectArmoredTransport.Name = "ButtonSelectArmoredTransport";
|
||||
this.ButtonSelectArmoredTransport.Size = new System.Drawing.Size(227, 49);
|
||||
this.ButtonSelectArmoredTransport.TabIndex = 10;
|
||||
this.ButtonSelectArmoredTransport.Text = "Выбор";
|
||||
this.ButtonSelectArmoredTransport.UseVisualStyleBackColor = true;
|
||||
this.ButtonSelectArmoredTransport.Click += new System.EventHandler(this.ButtonSelectArmoredTransport_Click);
|
||||
//
|
||||
// TankForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(13F, 32F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1445, 881);
|
||||
this.Controls.Add(this.ButtonSelectArmoredTransport);
|
||||
this.Controls.Add(this.ButtonStep);
|
||||
this.Controls.Add(this.ButtonCreateArmoredTransport);
|
||||
this.Controls.Add(this.comboBoxStrategy);
|
||||
@ -197,5 +211,6 @@
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button ButtonCreateArmoredTransport;
|
||||
private Button ButtonStep;
|
||||
private Button ButtonSelectArmoredTransport;
|
||||
}
|
||||
}
|
@ -18,11 +18,17 @@ namespace ProjectTank
|
||||
/// </summary>
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
/// <summary>
|
||||
/// Âűáđŕííűé ŕâňîěîáčëü
|
||||
/// </summary>
|
||||
public DrawningArmoredTransport? SelectedArmoredTransport { get; private set; }
|
||||
/// <summary>
|
||||
/// Èíèöèàëèçàöèÿ ôîðìû
|
||||
/// </summary>
|
||||
public TankForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractStrategy = null;
|
||||
SelectedArmoredTransport = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Ìåòîä ïðîðèñîâêè ìàøèíû
|
||||
@ -46,10 +52,21 @@ namespace ProjectTank
|
||||
private void ButtonCreateTank_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 dialogMain = new();
|
||||
if (dialogMain.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialogMain.Color;
|
||||
}
|
||||
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialogDop = new();
|
||||
if (dialogDop.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopColor = dialogDop.Color;
|
||||
}
|
||||
_drawningArmoredTransport = new DrawningTank(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)),
|
||||
color, dopColor,Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
pictureBoxTanks.Width, pictureBoxTanks.Height);
|
||||
_drawningArmoredTransport.SetPosition(random.Next(0, 100), random.Next(0, 100));
|
||||
Draw();
|
||||
@ -62,9 +79,14 @@ namespace ProjectTank
|
||||
private void ButtonCreateArmoredTransport_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningArmoredTransport = new DrawningArmoredTransport(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));
|
||||
//TODO âűáîđ îńíîâíîăî öâĺňŕ
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
_drawningArmoredTransport = new DrawningArmoredTransport(random.Next(100, 300),random.Next(1000, 3000), color,
|
||||
pictureBoxTanks.Width, pictureBoxTanks.Height);
|
||||
_drawningArmoredTransport.SetPosition(random.Next(10, 100), random.Next(10,100));
|
||||
Draw();
|
||||
@ -122,14 +144,14 @@ namespace ProjectTank
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new DrawningObjectArmoredTransport(_drawningArmoredTransport),
|
||||
_abstractStrategy.SetData(_drawningArmoredTransport.GetMoveableObject,
|
||||
pictureBoxTanks.Width, pictureBoxTanks.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_abstractStrategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
@ -138,5 +160,15 @@ namespace ProjectTank
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Âűáîđ ŕâňîěîáčë˙
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonSelectArmoredTransport_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedArmoredTransport = _drawningArmoredTransport;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user