Lab3 KozyrevSS GasolineTanker
This commit is contained in:
parent
e465a1b9ad
commit
33b9f0f1a0
91
Lab/CarsGenericCollection.cs
Normal file
91
Lab/CarsGenericCollection.cs
Normal file
@ -0,0 +1,91 @@
|
||||
using Lab.Generics;
|
||||
using Lab.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Lab.DrawningObjects;
|
||||
|
||||
namespace Lab.Generics
|
||||
{
|
||||
internal class CarsGenericCollection<T, U>
|
||||
where T : DrawTanker
|
||||
where U : IMoveableObject
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
private readonly int _placeSizeWidth = 110;
|
||||
private readonly int _placeSizeHeight = 80;
|
||||
private readonly SetGeneric<T> _collection;
|
||||
public CarsGenericCollection(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 +(CarsGenericCollection<T, U> collect, T?
|
||||
obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return collect?._collection.Insert(obj);
|
||||
}
|
||||
public static bool operator -(CarsGenericCollection<T, U> collect, int
|
||||
pos)
|
||||
{
|
||||
T? obj = collect._collection.Get(pos);
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return collect._collection.Remove(pos);
|
||||
}
|
||||
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||
}
|
||||
public Bitmap ShowCars()
|
||||
{
|
||||
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 width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
for (int i = 0; i < _collection.Count; i++)
|
||||
{
|
||||
DrawTanker? tank = _collection.Get(i);
|
||||
if (tank == null)
|
||||
continue;
|
||||
tank.SetPosition(i % height * _placeSizeWidth, (height - i / height - 1) * _placeSizeHeight);
|
||||
tank.DrawTransport(g);
|
||||
|
||||
}
|
||||
}
|
||||
}}
|
135
Lab/CollectionsFrame.Designer.cs
generated
Normal file
135
Lab/CollectionsFrame.Designer.cs
generated
Normal file
@ -0,0 +1,135 @@
|
||||
namespace Lab
|
||||
{
|
||||
partial class CollectionsFrame
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
panel1 = new Panel();
|
||||
UpdateButton = new Button();
|
||||
DeleteButton = new Button();
|
||||
AddButton = new Button();
|
||||
InputNum = new TextBox();
|
||||
label1 = new Label();
|
||||
DrawTank = new PictureBox();
|
||||
panel1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)DrawTank).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
panel1.Controls.Add(UpdateButton);
|
||||
panel1.Controls.Add(DeleteButton);
|
||||
panel1.Controls.Add(AddButton);
|
||||
panel1.Controls.Add(InputNum);
|
||||
panel1.Controls.Add(label1);
|
||||
panel1.Dock = DockStyle.Right;
|
||||
panel1.Location = new Point(550, 0);
|
||||
panel1.Name = "panel1";
|
||||
panel1.Size = new Size(250, 450);
|
||||
panel1.TabIndex = 0;
|
||||
//
|
||||
// UpdateButton
|
||||
//
|
||||
UpdateButton.Location = new Point(10, 241);
|
||||
UpdateButton.Name = "UpdateButton";
|
||||
UpdateButton.Size = new Size(228, 37);
|
||||
UpdateButton.TabIndex = 4;
|
||||
UpdateButton.Text = "Обновить коллекцию";
|
||||
UpdateButton.UseVisualStyleBackColor = true;
|
||||
UpdateButton.Click += ButtonRefreshCollection_Click;
|
||||
//
|
||||
// DeleteButton
|
||||
//
|
||||
DeleteButton.Location = new Point(10, 176);
|
||||
DeleteButton.Name = "DeleteButton";
|
||||
DeleteButton.Size = new Size(228, 37);
|
||||
DeleteButton.TabIndex = 3;
|
||||
DeleteButton.Text = "Удалить автомобиль";
|
||||
DeleteButton.UseVisualStyleBackColor = true;
|
||||
DeleteButton.Click += ButtonRemoveCar_Click;
|
||||
//
|
||||
// AddButton
|
||||
//
|
||||
AddButton.Location = new Point(10, 53);
|
||||
AddButton.Name = "AddButton";
|
||||
AddButton.Size = new Size(228, 37);
|
||||
AddButton.TabIndex = 2;
|
||||
AddButton.Text = "Добавить автомобиль";
|
||||
AddButton.UseVisualStyleBackColor = true;
|
||||
AddButton.Click += ButtonAddTank_Click;
|
||||
//
|
||||
// InputNum
|
||||
//
|
||||
InputNum.Location = new Point(10, 133);
|
||||
InputNum.Name = "InputNum";
|
||||
InputNum.Size = new Size(228, 27);
|
||||
InputNum.TabIndex = 1;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(2, 2);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(103, 20);
|
||||
label1.TabIndex = 0;
|
||||
label1.Text = "Инструменты";
|
||||
//
|
||||
// DrawTank
|
||||
//
|
||||
DrawTank.Dock = DockStyle.Fill;
|
||||
DrawTank.Location = new Point(0, 0);
|
||||
DrawTank.Name = "DrawTank";
|
||||
DrawTank.Size = new Size(550, 450);
|
||||
DrawTank.TabIndex = 1;
|
||||
DrawTank.TabStop = false;
|
||||
//
|
||||
// CollectionsFrame
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(DrawTank);
|
||||
Controls.Add(panel1);
|
||||
Name = "CollectionsFrame";
|
||||
Text = "Form1";
|
||||
panel1.ResumeLayout(false);
|
||||
panel1.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)DrawTank).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Panel panel1;
|
||||
private Button UpdateButton;
|
||||
private Button DeleteButton;
|
||||
private Button AddButton;
|
||||
private TextBox InputNum;
|
||||
private Label label1;
|
||||
private PictureBox DrawTank;
|
||||
}
|
||||
}
|
71
Lab/CollectionsFrame.cs
Normal file
71
Lab/CollectionsFrame.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using Lab.DrawningObjects;
|
||||
using Lab.Generics;
|
||||
using Lab.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 Lab
|
||||
{
|
||||
public partial class CollectionsFrame : Form
|
||||
{
|
||||
private readonly CarsGenericCollection<DrawTanker, DrawingObjectTanker> _cars;
|
||||
|
||||
public CollectionsFrame()
|
||||
{
|
||||
InitializeComponent();
|
||||
_cars = new CarsGenericCollection<DrawTanker, DrawingObjectTanker>(DrawTank.Width, DrawTank.Height);
|
||||
}
|
||||
|
||||
private void ButtonAddTank_Click(object sender, EventArgs e)
|
||||
{
|
||||
Frame form = new Frame();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_cars + form.SelectedCar != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
DrawTank.Image = _cars.ShowCars();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ButtonRemoveCar_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = -1;
|
||||
try
|
||||
{
|
||||
pos = Convert.ToInt32(InputNum.Text);
|
||||
}
|
||||
catch (Exception ex) { }
|
||||
if (_cars - pos)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
DrawTank.Image = _cars.ShowCars();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
DrawTank.Image = _cars.ShowCars();
|
||||
}
|
||||
}
|
||||
}
|
120
Lab/CollectionsFrame.resx
Normal file
120
Lab/CollectionsFrame.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>
|
@ -5,6 +5,7 @@ using System.Security.Cryptography.Pkcs;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Lab.Entities;
|
||||
using Lab.MovementStrategy;
|
||||
|
||||
namespace Lab.DrawningObjects
|
||||
{
|
||||
@ -119,5 +120,7 @@ namespace Lab.DrawningObjects
|
||||
|
||||
|
||||
}
|
||||
|
||||
public IMoveableObject GetMoveableObject => new DrawingObjectTanker(this);
|
||||
}
|
||||
}
|
||||
|
130
Lab/Frame.Designer.cs
generated
130
Lab/Frame.Designer.cs
generated
@ -29,14 +29,15 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
DrawCar = new PictureBox();
|
||||
CreateBaseCarButton = new Button();
|
||||
Up = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStep = new Button();
|
||||
Right = new Button();
|
||||
Left = new Button();
|
||||
Down = new Button();
|
||||
Right = new Button();
|
||||
Up = new Button();
|
||||
buttonCreateGasolineTanker = new Button();
|
||||
buttonStep = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
CreateBaseCarButton = new Button();
|
||||
ChooseCar = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)DrawCar).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -49,28 +50,37 @@
|
||||
DrawCar.TabIndex = 1;
|
||||
DrawCar.TabStop = false;
|
||||
//
|
||||
// CreateBaseCarButton
|
||||
// comboBoxStrategy
|
||||
//
|
||||
CreateBaseCarButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
CreateBaseCarButton.Location = new Point(12, 441);
|
||||
CreateBaseCarButton.Name = "CreateBaseCarButton";
|
||||
CreateBaseCarButton.Size = new Size(200, 100);
|
||||
CreateBaseCarButton.TabIndex = 2;
|
||||
CreateBaseCarButton.Text = "Создать простой бензовоз";
|
||||
CreateBaseCarButton.UseVisualStyleBackColor = true;
|
||||
CreateBaseCarButton.Click += CreateCarButton_Click;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "0", "1" });
|
||||
comboBoxStrategy.Location = new Point(719, 27);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(151, 28);
|
||||
comboBoxStrategy.TabIndex = 9;
|
||||
//
|
||||
// Up
|
||||
// buttonStep
|
||||
//
|
||||
Up.BackgroundImage = Properties.Resources.Up;
|
||||
Up.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
Up.Location = new Point(804, 476);
|
||||
Up.Name = "Up";
|
||||
Up.Size = new Size(30, 30);
|
||||
Up.TabIndex = 3;
|
||||
Up.Text = "↑";
|
||||
Up.UseVisualStyleBackColor = true;
|
||||
Up.Click += ButtonMove_Click;
|
||||
buttonStep.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonStep.Location = new Point(776, 72);
|
||||
buttonStep.Name = "buttonStep";
|
||||
buttonStep.Size = new Size(94, 29);
|
||||
buttonStep.TabIndex = 8;
|
||||
buttonStep.Text = "Шаг";
|
||||
buttonStep.UseVisualStyleBackColor = true;
|
||||
buttonStep.Click += ButtonStep_Click;
|
||||
//
|
||||
// Right
|
||||
//
|
||||
Right.BackgroundImage = Properties.Resources.Right;
|
||||
Right.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
Right.Location = new Point(840, 512);
|
||||
Right.Name = "Right";
|
||||
Right.Size = new Size(30, 30);
|
||||
Right.TabIndex = 6;
|
||||
Right.Text = "→";
|
||||
Right.UseVisualStyleBackColor = true;
|
||||
Right.Click += ButtonMove_Click;
|
||||
//
|
||||
// Left
|
||||
//
|
||||
@ -96,17 +106,17 @@
|
||||
Down.UseVisualStyleBackColor = true;
|
||||
Down.Click += ButtonMove_Click;
|
||||
//
|
||||
// Right
|
||||
// Up
|
||||
//
|
||||
Right.BackgroundImage = Properties.Resources.Right;
|
||||
Right.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
Right.Location = new Point(840, 512);
|
||||
Right.Name = "Right";
|
||||
Right.Size = new Size(30, 30);
|
||||
Right.TabIndex = 6;
|
||||
Right.Text = "→";
|
||||
Right.UseVisualStyleBackColor = true;
|
||||
Right.Click += ButtonMove_Click;
|
||||
Up.BackgroundImage = Properties.Resources.Up;
|
||||
Up.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
Up.Location = new Point(804, 476);
|
||||
Up.Name = "Up";
|
||||
Up.Size = new Size(30, 30);
|
||||
Up.TabIndex = 3;
|
||||
Up.Text = "↑";
|
||||
Up.UseVisualStyleBackColor = true;
|
||||
Up.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreateGasolineTanker
|
||||
//
|
||||
@ -119,31 +129,33 @@
|
||||
buttonCreateGasolineTanker.UseVisualStyleBackColor = true;
|
||||
buttonCreateGasolineTanker.Click += CreateGasolineTankerButton_Click;
|
||||
//
|
||||
// buttonStep
|
||||
// CreateBaseCarButton
|
||||
//
|
||||
buttonStep.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonStep.Location = new Point(776, 72);
|
||||
buttonStep.Name = "buttonStep";
|
||||
buttonStep.Size = new Size(94, 29);
|
||||
buttonStep.TabIndex = 8;
|
||||
buttonStep.Text = "Шаг";
|
||||
buttonStep.UseVisualStyleBackColor = true;
|
||||
buttonStep.Click += ButtonStep_Click;
|
||||
CreateBaseCarButton.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
CreateBaseCarButton.Location = new Point(12, 441);
|
||||
CreateBaseCarButton.Name = "CreateBaseCarButton";
|
||||
CreateBaseCarButton.Size = new Size(200, 100);
|
||||
CreateBaseCarButton.TabIndex = 2;
|
||||
CreateBaseCarButton.Text = "Создать простой бензовоз";
|
||||
CreateBaseCarButton.UseVisualStyleBackColor = true;
|
||||
CreateBaseCarButton.Click += CreateCarButton_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
// ChooseCar
|
||||
//
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "0", "1" });
|
||||
comboBoxStrategy.Location = new Point(719, 27);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(151, 28);
|
||||
comboBoxStrategy.TabIndex = 9;
|
||||
ChooseCar.Location = new Point(776, 149);
|
||||
ChooseCar.Name = "ChooseCar";
|
||||
ChooseCar.Size = new Size(94, 52);
|
||||
ChooseCar.TabIndex = 10;
|
||||
ChooseCar.Text = "Выбрать машину";
|
||||
ChooseCar.UseVisualStyleBackColor = true;
|
||||
ChooseCar.Click += ButtonSelectTank_Click;
|
||||
//
|
||||
// GasolineTanker
|
||||
// Frame
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(882, 553);
|
||||
Controls.Add(ChooseCar);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonStep);
|
||||
Controls.Add(buttonCreateGasolineTanker);
|
||||
@ -153,7 +165,7 @@
|
||||
Controls.Add(Up);
|
||||
Controls.Add(CreateBaseCarButton);
|
||||
Controls.Add(DrawCar);
|
||||
Name = "GasolineTanker";
|
||||
Name = "Frame";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "GasolineTanker";
|
||||
((System.ComponentModel.ISupportInitialize)DrawCar).EndInit();
|
||||
@ -161,14 +173,18 @@
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox DrawCar;
|
||||
private Button CreateBaseCarButton;
|
||||
private Button Up;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStep;
|
||||
private Button Right;
|
||||
private Button Left;
|
||||
private Button Down;
|
||||
private Button Right;
|
||||
private Button Up;
|
||||
private Button buttonCreateGasolineTanker;
|
||||
private Button buttonStep;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button CreateBaseCarButton;
|
||||
private Button button2;
|
||||
private Button AddTanker;
|
||||
private Button ChooseCar;
|
||||
}
|
||||
}
|
37
Lab/Frame.cs
37
Lab/Frame.cs
@ -1,6 +1,7 @@
|
||||
using Lab.DrawningObjects;
|
||||
using Lab.MovementStrategy;
|
||||
using Lab;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Lab
|
||||
{
|
||||
@ -8,11 +9,16 @@ namespace Lab
|
||||
{
|
||||
private DrawTanker? _drawingTanker;
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
public DrawTanker? SelectedCar { get; private set; }
|
||||
|
||||
public Frame()
|
||||
{
|
||||
InitializeComponent();
|
||||
_abstractStrategy = null;
|
||||
SelectedCar = null;
|
||||
}
|
||||
|
||||
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawingTanker == null)
|
||||
@ -25,9 +31,19 @@ namespace Lab
|
||||
private void CreateGasolineTankerButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
Color mainColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
mainColor = dialog.Color;
|
||||
}
|
||||
Color addColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
addColor = dialog.Color;
|
||||
}
|
||||
_drawingTanker = new DrawGasolineTanker(rnd.Next(100, 200), rnd.Next(2000, 4000),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
mainColor, addColor,
|
||||
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)),
|
||||
DrawCar.Width, DrawCar.Height);
|
||||
_drawingTanker.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100));
|
||||
@ -37,8 +53,13 @@ namespace Lab
|
||||
private void CreateCarButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_drawingTanker = new DrawTanker(rnd.Next(100, 200), rnd.Next(2000, 4000),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
_drawingTanker = new DrawTanker(rnd.Next(100, 200), rnd.Next(2000, 4000), color,
|
||||
DrawCar.Width, DrawCar.Height);
|
||||
_drawingTanker.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100));
|
||||
Draw();
|
||||
@ -77,7 +98,7 @@ namespace Lab
|
||||
};
|
||||
if (_abstractStrategy == null)
|
||||
return;
|
||||
_abstractStrategy.SetData(new DrawingObjectTanker(_drawingTanker), DrawCar.Width, DrawCar.Height);
|
||||
_abstractStrategy.SetData(_drawingTanker.GetMoveableObject, DrawCar.Width, DrawCar.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
@ -90,5 +111,11 @@ namespace Lab
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSelectTank_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedCar = _drawingTanker;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ namespace Lab
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Frame());
|
||||
Application.Run(new CollectionsFrame());
|
||||
}
|
||||
}
|
||||
}
|
84
Lab/SetGeneric.cs
Normal file
84
Lab/SetGeneric.cs
Normal file
@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Lab.Generics
|
||||
{
|
||||
internal class SetGeneric<T> where T : class
|
||||
{
|
||||
private readonly T?[] _places;
|
||||
|
||||
public int Count => _places.Length;
|
||||
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_places = new T?[count];
|
||||
}
|
||||
|
||||
public int Insert(T car)
|
||||
{
|
||||
int index = -1;
|
||||
for (int i = 0; i < _places.Length; i++ )
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
index = i; break;
|
||||
}
|
||||
}
|
||||
if ( index < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
for (int i = index; i > 0; i-- )
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
_places[0] = car;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int Insert(T car, int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
return -1;
|
||||
if (_places[position] == null)
|
||||
{
|
||||
_places[position] = car;
|
||||
return position;
|
||||
}
|
||||
int index = -1;
|
||||
for (int i = position; i < Count; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
index = i; break;
|
||||
}
|
||||
}
|
||||
if (index < 0)
|
||||
return -1;
|
||||
for (int i = index; index > position; i--)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
_places[position] = car;
|
||||
return position;
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user