ПИбд-23 Тихоненков А.Е. Лабораторная №3 #10
@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AntiAircraftGun.Enitites;
|
||||
using AntiAircraftGun.MovementStrategy;
|
||||
|
||||
namespace AntiAircraftGun.DrawingObjects
|
||||
{
|
||||
@ -43,6 +44,7 @@ namespace AntiAircraftGun.DrawingObjects
|
||||
_startPosX = 1;
|
||||
_startPosY = 1;
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Координата X объекта
|
||||
@ -81,7 +83,7 @@ namespace AntiAircraftGun.DrawingObjects
|
||||
// вправо
|
||||
DirectionType.Right =>_startPosX + AntiAirСraftGun.Step + _zenitWidth < _pictureWidth,
|
||||
//вниз
|
||||
DirectionType.Down => _startPosY + AntiAirСraftGun.Step + _zenitHeight < _pictureHeight,
|
||||
DirectionType.Down => _startPosY + AntiAirСraftGun.Step + _zenitHeight< _pictureHeight,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
@ -138,5 +140,10 @@ namespace AntiAircraftGun.DrawingObjects
|
||||
g.FillEllipse(Brushes.Black, trackRect);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject из объекта DrawningCar
|
||||
/// </summary>
|
||||
public IMoveableObject GetMoveableObject => new DrawingObjectAntiAirCraftGun(this);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,8 @@
|
||||
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
|
||||
this.CreateAntiAirCraftGun = new System.Windows.Forms.Button();
|
||||
this.Step = new System.Windows.Forms.Button();
|
||||
this.ButtonSelectZenit = new System.Windows.Forms.Button();
|
||||
this.colorDialog1 = new System.Windows.Forms.ColorDialog();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAntiAircraftGun)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@ -120,7 +122,6 @@
|
||||
this.comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
this.comboBoxStrategy.Size = new System.Drawing.Size(170, 23);
|
||||
this.comboBoxStrategy.TabIndex = 6;
|
||||
|
||||
//
|
||||
// CreateAntiAirCraftGun
|
||||
//
|
||||
@ -142,11 +143,22 @@
|
||||
this.Step.UseVisualStyleBackColor = true;
|
||||
this.Step.Click += new System.EventHandler(this.ButtonStep_Click);
|
||||
//
|
||||
// ButtonSelectZenit
|
||||
//
|
||||
this.ButtonSelectZenit.Location = new System.Drawing.Point(412, 577);
|
||||
this.ButtonSelectZenit.Name = "ButtonSelectZenit";
|
||||
this.ButtonSelectZenit.Size = new System.Drawing.Size(157, 23);
|
||||
this.ButtonSelectZenit.TabIndex = 9;
|
||||
this.ButtonSelectZenit.Text = "Выбрать объект";
|
||||
this.ButtonSelectZenit.UseVisualStyleBackColor = true;
|
||||
this.ButtonSelectZenit.Click += new System.EventHandler(this.ButtonSelectZenit_Click);
|
||||
//
|
||||
// FormAntiAirCraftGun
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1491, 628);
|
||||
this.Controls.Add(this.ButtonSelectZenit);
|
||||
this.Controls.Add(this.Step);
|
||||
this.Controls.Add(this.CreateAntiAirCraftGun);
|
||||
this.Controls.Add(this.comboBoxStrategy);
|
||||
@ -157,7 +169,7 @@
|
||||
this.Controls.Add(this.CreateAdavancedAntiAirCraftGun);
|
||||
this.Controls.Add(this.pictureBoxAntiAircraftGun);
|
||||
this.Name = "FormAntiAirCraftGun";
|
||||
this.Text = "Form1";
|
||||
this.Text = "FormAntiAirCraftGun";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAntiAircraftGun)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
@ -175,5 +187,7 @@
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button CreateAntiAirCraftGun;
|
||||
private Button Step;
|
||||
private Button ButtonSelectZenit;
|
||||
private ColorDialog colorDialog1;
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using AntiAircraftGun.DrawingObjects;
|
||||
using AntiAircraftGun.MovementStrategy;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
|
||||
|
||||
namespace AntiAircraftGun
|
||||
{
|
||||
@ -8,9 +9,13 @@ namespace AntiAircraftGun
|
||||
private BaseDrawingAntiAirCraftGun _drawingAntiAirCraftGun;
|
||||
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
|
||||
public BaseDrawingAntiAirCraftGun? SelectedZenit { get; private set; }
|
||||
public FormAntiAirCraftGun()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractStrategy = null;
|
||||
SelectedZenit = null;
|
||||
}
|
||||
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
@ -52,12 +57,18 @@ namespace AntiAircraftGun
|
||||
private void CreateAdvancedAintiAirCraftGun_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new Random();
|
||||
Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); // Îńíîâíîé öâĺň
|
||||
Color additionalColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); // Äîď. öâĺň äë˙ EntityAdvancedAntiAircraftGun
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
bodyColor = dialog.Color;
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
dopColor = dialog.Color;
|
||||
_drawingAntiAirCraftGun = new AdvancedDrawingAntiAirCraftGun(
|
||||
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.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), // Äîï. öâåò äëÿ EntityAdvancedAntiAircraftGun
|
||||
bodyColor, additionalColor, dopColor,
|
||||
Convert.ToBoolean(random.Next(2)), // Rocket
|
||||
Convert.ToBoolean(random.Next(2)),
|
||||
pictureBoxAntiAircraftGun.Width,
|
||||
@ -71,11 +82,17 @@ namespace AntiAircraftGun
|
||||
private void CreateAntiAirCraftGun_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new Random();
|
||||
Color bodyColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); // Îńíîâíîé öâĺň
|
||||
Color additionalColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); // Äîď. öâĺň
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
bodyColor = dialog.Color;
|
||||
}
|
||||
_drawingAntiAirCraftGun = new BaseDrawingAntiAirCraftGun(
|
||||
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)), // Äîï. öâåò
|
||||
bodyColor, additionalColor,
|
||||
pictureBoxAntiAircraftGun.Width,
|
||||
pictureBoxAntiAircraftGun.Height
|
||||
);
|
||||
@ -121,5 +138,12 @@ namespace AntiAircraftGun
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
private void ButtonSelectZenit_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedZenit = _drawingAntiAirCraftGun;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -57,4 +57,7 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="colorDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
123
AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGunCollection.Designer.cs
generated
Normal file
123
AntiAirCraftGun/AntiAirCraftGun/FormAntiAirCraftGunCollection.Designer.cs
generated
Normal file
@ -0,0 +1,123 @@
|
||||
namespace AntiAircraftGun
|
||||
{
|
||||
partial class FormAntiAirCraftGunCollection
|
||||
{
|
||||
/// <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.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||
this.panelTools = new System.Windows.Forms.Panel();
|
||||
this.textBox = new System.Windows.Forms.TextBox();
|
||||
this.buttonUpdateColletion = new System.Windows.Forms.Button();
|
||||
this.buttonDeleteZenit = new System.Windows.Forms.Button();
|
||||
this.buttonAddZenit = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||
this.panelTools.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
this.pictureBoxCollection.Location = new System.Drawing.Point(12, 12);
|
||||
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
this.pictureBoxCollection.Size = new System.Drawing.Size(711, 571);
|
||||
this.pictureBoxCollection.TabIndex = 0;
|
||||
this.pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// panelTools
|
||||
//
|
||||
this.panelTools.Controls.Add(this.textBox);
|
||||
this.panelTools.Controls.Add(this.buttonUpdateColletion);
|
||||
this.panelTools.Controls.Add(this.buttonDeleteZenit);
|
||||
this.panelTools.Controls.Add(this.buttonAddZenit);
|
||||
this.panelTools.Location = new System.Drawing.Point(729, 14);
|
||||
this.panelTools.Name = "panelTools";
|
||||
this.panelTools.Size = new System.Drawing.Size(234, 568);
|
||||
this.panelTools.TabIndex = 1;
|
||||
this.panelTools.Tag = "";
|
||||
//
|
||||
// textBox
|
||||
//
|
||||
this.textBox.Location = new System.Drawing.Point(23, 164);
|
||||
this.textBox.Name = "textBox";
|
||||
this.textBox.Size = new System.Drawing.Size(193, 23);
|
||||
this.textBox.TabIndex = 3;
|
||||
//
|
||||
// buttonUpdateColletion
|
||||
//
|
||||
this.buttonUpdateColletion.Location = new System.Drawing.Point(23, 263);
|
||||
this.buttonUpdateColletion.Name = "buttonUpdateColletion";
|
||||
this.buttonUpdateColletion.Size = new System.Drawing.Size(193, 40);
|
||||
this.buttonUpdateColletion.TabIndex = 2;
|
||||
this.buttonUpdateColletion.Text = "Обновить коллекцию";
|
||||
this.buttonUpdateColletion.UseVisualStyleBackColor = true;
|
||||
this.buttonUpdateColletion.Click += new System.EventHandler(this.ButtonUpdateCollection_Click);
|
||||
//
|
||||
// buttonDeleteZenit
|
||||
//
|
||||
this.buttonDeleteZenit.Location = new System.Drawing.Point(23, 193);
|
||||
this.buttonDeleteZenit.Name = "buttonDeleteZenit";
|
||||
this.buttonDeleteZenit.Size = new System.Drawing.Size(193, 40);
|
||||
this.buttonDeleteZenit.TabIndex = 1;
|
||||
this.buttonDeleteZenit.Text = "Удалить объект";
|
||||
this.buttonDeleteZenit.UseVisualStyleBackColor = true;
|
||||
this.buttonDeleteZenit.Click += new System.EventHandler(this.ButtonDeleteZenit_Click);
|
||||
//
|
||||
// buttonAddZenit
|
||||
//
|
||||
this.buttonAddZenit.Location = new System.Drawing.Point(23, 32);
|
||||
this.buttonAddZenit.Name = "buttonAddZenit";
|
||||
this.buttonAddZenit.Size = new System.Drawing.Size(193, 40);
|
||||
this.buttonAddZenit.TabIndex = 0;
|
||||
this.buttonAddZenit.Text = "Добавить объект";
|
||||
this.buttonAddZenit.UseVisualStyleBackColor = true;
|
||||
this.buttonAddZenit.Click += new System.EventHandler(this.ButtonAddZenit_Click);
|
||||
//
|
||||
// FormAntiAirCraftGunCollection
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(971, 595);
|
||||
this.Controls.Add(this.panelTools);
|
||||
this.Controls.Add(this.pictureBoxCollection);
|
||||
this.Name = "FormAntiAirCraftGunCollection";
|
||||
this.Text = "FormAntiAirCraftGunCollection";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
||||
this.panelTools.ResumeLayout(false);
|
||||
this.panelTools.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxCollection;
|
||||
private Panel panelTools;
|
||||
private TextBox textBox;
|
||||
private Button buttonUpdateColletion;
|
||||
private Button buttonDeleteZenit;
|
||||
private Button buttonAddZenit;
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
using AntiAircraftGun.DrawingObjects;
|
||||
using AntiAircraftGun.Generics;
|
||||
using AntiAircraftGun.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 AntiAircraftGun
|
||||
{
|
||||
public partial class FormAntiAirCraftGunCollection : Form
|
||||
{
|
||||
private readonly AntiAirCraftGunGenericCollection<BaseDrawingAntiAirCraftGun,DrawingObjectAntiAirCraftGun> _zenits;
|
||||
public FormAntiAirCraftGunCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_zenits = new AntiAirCraftGunGenericCollection<BaseDrawingAntiAirCraftGun,
|
||||
DrawingObjectAntiAirCraftGun>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
|
||||
}
|
||||
private void ButtonAddZenit_Click(object sender, EventArgs e)
|
||||
{
|
||||
FormAntiAirCraftGun form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_zenits + form.SelectedZenit != null)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = _zenits.ShowZenits();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonDeleteZenit_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(textBox.Text);
|
||||
if (_zenits - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = _zenits.ShowZenits();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonUpdateCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _zenits.ShowZenits();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -0,0 +1,171 @@
|
||||
using AntiAircraftGun.DrawingObjects;
|
||||
using AntiAircraftGun.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AntiAircraftGun.Generics
|
||||
{
|
||||
internal class AntiAirCraftGunGenericCollection<T,U>
|
||||
where T : BaseDrawingAntiAirCraftGun
|
||||
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 AntiAirCraftGunGenericCollection(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 +(AntiAirCraftGunGenericCollection<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 bool operator -(AntiAirCraftGunGenericCollection<T, U> collect, int pos)
|
||||
{
|
||||
T? obj = collect._collection.Get(pos);
|
||||
if (obj != null)
|
||||
return collect._collection.Remove(pos);
|
||||
eegov
commented
Требовалось поменять тип возвращаемого значения Требовалось поменять тип возвращаемого значения
|
||||
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 ShowZenits()
|
||||
{
|
||||
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.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
||||
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки объектов
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int x = 0; // Начальная координата X
|
||||
int y = 0; // Начальная координата Y
|
||||
int maxX = _pictureWidth; // Максимальное значение X, при достижении которого будет ошибка
|
||||
int maxY = _pictureHeight; // Максимальное значение Y, когда нужно изменить X
|
||||
int distance_between_objects = _placeSizeHeight;
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
// TODO: Получение объекта
|
||||
T? obj = _collection.Get(i);
|
||||
|
||||
if (obj != null)
|
||||
{
|
||||
// Проверяем, если X достигло максимума, выводим ошибку
|
||||
if (x >= maxX)
|
||||
{
|
||||
MessageBox.Show("Не хватает места для объекта.");
|
||||
break;
|
||||
}
|
||||
|
||||
// Устанавливаем позицию
|
||||
obj.SetPosition(x, y+10);
|
||||
|
||||
// TODO: Прорисовка объекта
|
||||
obj.DrawTransport(g);
|
||||
|
||||
// Увеличиваем координату Y для следующего объекта
|
||||
y += distance_between_objects;
|
||||
|
||||
// Проверяем, если Y достигло максимума, изменяем X и сбрасываем Y
|
||||
if (y+distance_between_objects >= maxY)
|
||||
{
|
||||
y = 0;
|
||||
x += _placeSizeWidth;
|
||||
}
|
||||
}
|
||||
if (obj == null)
|
||||
{
|
||||
// Увеличиваем координату Y для следующего объекта
|
||||
y += distance_between_objects;
|
||||
|
||||
// Проверяем, если Y достигло максимума, изменяем X и сбрасываем Y
|
||||
if (y+distance_between_objects >= maxY)
|
||||
{
|
||||
y = 0;
|
||||
x += _placeSizeWidth;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
109
AntiAirCraftGun/AntiAirCraftGun/Generics/SetGeneric.cs
Normal file
109
AntiAirCraftGun/AntiAirCraftGun/Generics/SetGeneric.cs
Normal file
@ -0,0 +1,109 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AntiAircraftGun.Generics
|
||||
{
|
||||
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="car">Добавляемый автомобиль</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T car)
|
||||
{
|
||||
// Вставка в начало набора
|
||||
for (int i = 0; i < _places.Length; i++)
|
||||
eegov
commented
Правильнее было вызвать Insert(T obj, 0); Правильнее было вызвать Insert(T obj, 0);
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
_places[i] = car;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return -1; // Если нет пустых мест
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// /// </summary>
|
||||
/// <param name="car">Добавляемый автомобиль</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T car, int position)
|
||||
{
|
||||
// Проверка позиции
|
||||
if (position < 0 || position >= _places.Length)
|
||||
return -1;
|
||||
|
||||
// Проверка, что элемент массива по этой позиции пустой
|
||||
if (_places[position] != null)
|
||||
return -1;
|
||||
|
||||
// Проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||
for (int i = position + 1; i < _places.Length; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
// Сдвиг всех объектов справа от позиции до первого пустого элемента
|
||||
for (int j = i; j > position; j--)
|
||||
{
|
||||
_places[j] = _places[j - 1];
|
||||
}
|
||||
_places[position] = car;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return -1; // Если нет пустых мест справа
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public bool Remove(int position)
|
||||
{
|
||||
// Проверка позиции
|
||||
if (position < 0 || position >= _places.Length)
|
||||
return false;
|
||||
|
||||
// Удаление объекта из массива, присвоив элементу массива значение null
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (position < 0 || position >= _places.Length)
|
||||
{
|
||||
// Позиция находится за пределами допустимого диапазона, вернем null
|
||||
return null;
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ namespace AntiAircraftGun
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormAntiAirCraftGun());
|
||||
Application.Run(new FormAntiAirCraftGunCollection());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user
Требовалось поменять тип возвращаемого значения