2 Commits
Lab3 ... Lab5

Author SHA1 Message Date
46283ecf8f Lab5_DONE 2024-10-03 00:43:12 +03:00
af5ff49bc8 Lab4_DONE 2024-10-03 00:42:04 +03:00
17 changed files with 1022 additions and 208 deletions

View File

@@ -11,7 +11,6 @@ namespace ProjectGasolineTanker.Drawings
public class DrawingGasolineTanker : DrawingTruck
{
public DrawingGasolineTanker(int speed, double weight, Color bodyColor, Color additionalColor, bool tank, bool wheel, int width, int height) : base(speed, weight, bodyColor, width, height, 130, 70)
{
if (EntityTruck != null)

View File

@@ -38,7 +38,6 @@ namespace ProjectGasolineTanker.Drawings
public DrawingTruck(int speed, double weight, Color bodyColor, int width, int height)
{
if (width < _tankerWidth || height < _tankerHeight)
{
return;
@@ -117,16 +116,16 @@ namespace ProjectGasolineTanker.Drawings
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(EntityTruck.BodyColor);
g.FillRectangle(additionalBrush, _startPosX + 29, _startPosY + 11, 71, 28); //канистра-бак
g.FillRectangle(additionalBrush, _startPosX + 29, _startPosY + 20, 71, 9); //полосы
g.FillRectangle(additionalBrush, _startPosX + 29, _startPosY + 11, 71, 28);
g.FillRectangle(additionalBrush, _startPosX + 29, _startPosY + 20, 71, 9);
g.DrawRectangle(pen, _startPosX + 29, _startPosY + 11, 71, 28); //канистра-бак
g.DrawRectangle(pen, _startPosX + 29, _startPosY + 20, 71, 9); //полосы
g.DrawRectangle(pen, _startPosX + 29, _startPosY + 11, 71, 28);
g.DrawRectangle(pen, _startPosX + 29, _startPosY + 20, 71, 9);
Brush additionalBrush1 = new
SolidBrush(EntityTruck.BodyColor);
//кабина
g.FillRectangle(additionalBrush1, _startPosX + 100, _startPosY + 10, 24, 16);
g.FillRectangle(additionalBrush1, _startPosX + 124, _startPosY + 10, 9, 16);
g.FillRectangle(additionalBrush1, _startPosX + 100, _startPosY + 10, 33, 16);
@@ -145,7 +144,7 @@ namespace ProjectGasolineTanker.Drawings
g.FillRectangle(additionalBrush2, _startPosX + 4, _startPosY + 40, 130, 25);
g.DrawLine(pen, _startPosX + 4, _startPosY + 65, _startPosX + 25, _startPosY + 40);
//колёса
Brush gr = new SolidBrush(Color.Gray);
g.FillEllipse(additionalBrush, _startPosX + 15, _startPosY + 50, 26, 26);
@@ -158,6 +157,7 @@ namespace ProjectGasolineTanker.Drawings
g.DrawEllipse(pen, _startPosX + 110, _startPosY + 55, 22, 22);
}
public bool CanMove(DirectionType direction)
{
if (EntityTruck == null)
@@ -177,6 +177,12 @@ namespace ProjectGasolineTanker.Drawings
_ => false,
};
}
public void ChangePictureSize(int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
}
}
}

View File

@@ -23,6 +23,11 @@ namespace ProjectGasolineTanker.Entities
Tank = tank;
Wheel = wheel;
}
public void ChangeAdditionalColor(Color additionalColor)
{
Add_Color = additionalColor;
}
}
}

View File

@@ -25,5 +25,10 @@ namespace ProjectGasolineTanker.Entities
BodyColor = bodyColor;
}
public void ChangeBodyColor(Color color)
{
BodyColor = color;
}
}
}

View File

@@ -4,14 +4,23 @@ using ProjectGasolineTanker.MovementStratg;
namespace ProjectGasolineTanker
{
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
public partial class FormGasolineTanker : Form
{
/// <summary>
/// <20><><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
private DrawingTruck? _drawingTruck;
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
private AbstractStrategy? _abstractStrategy;
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
public DrawingTruck? SelectedTruck { get; private set; }
public FormGasolineTanker()
@@ -20,7 +29,9 @@ namespace ProjectGasolineTanker
_abstractStrategy = null;
SelectedTruck = null;
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
private void Draw()
{
if (_drawingTruck == null)
@@ -33,7 +44,11 @@ namespace ProjectGasolineTanker
pictureBoxGasolineTanker.Image = bmp;
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreateProjectGasolineTanker_Click(object sender, EventArgs e)
{
Random random = new();
@@ -56,7 +71,11 @@ namespace ProjectGasolineTanker
_drawingTruck.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ProjectGasolineTanker"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreateTruck_Click(object sender, EventArgs e)
{
Random random = new();
@@ -75,7 +94,11 @@ namespace ProjectGasolineTanker
Draw();
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonMove_Click(object sender, EventArgs e)
{
if (_drawingTruck == null)
@@ -100,7 +123,11 @@ namespace ProjectGasolineTanker
}
Draw();
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> "<22><><EFBFBD>"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonStep_Click(object sender, EventArgs e)
{
if (_drawingTruck == null)

View File

@@ -28,88 +28,154 @@
/// </summary>
private void InitializeComponent()
{
this.buttonAddTruck = new System.Windows.Forms.Button();
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
this.labelInstruments = new System.Windows.Forms.Label();
this.buttonAdd = new System.Windows.Forms.Button();
this.maskedTextBoxNumber = new System.Windows.Forms.TextBox();
this.buttonDelete = new System.Windows.Forms.Button();
this.buttonUpdate = new System.Windows.Forms.Button();
this.buttonDeleteTruck = new System.Windows.Forms.Button();
this.colorDialog = new System.Windows.Forms.ColorDialog();
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
this.label1 = new System.Windows.Forms.Label();
this.listBoxStorages = new System.Windows.Forms.ListBox();
this.buttonAddStorage = new System.Windows.Forms.Button();
this.buttonDeleteStorage = new System.Windows.Forms.Button();
this.textBoxStorageName = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
this.SuspendLayout();
//
// buttonAddTruck
//
this.buttonAddTruck.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonAddTruck.Location = new System.Drawing.Point(734, 420);
this.buttonAddTruck.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonAddTruck.Name = "buttonAddTruck";
this.buttonAddTruck.Size = new System.Drawing.Size(157, 37);
this.buttonAddTruck.TabIndex = 0;
this.buttonAddTruck.Text = "Добавить грузовик";
this.buttonAddTruck.UseVisualStyleBackColor = true;
this.buttonAddTruck.Click += new System.EventHandler(this.buttonAddTruck_Click);
//
// pictureBoxCollection
//
this.pictureBoxCollection.Location = new System.Drawing.Point(2, 1);
this.pictureBoxCollection.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
this.pictureBoxCollection.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.pictureBoxCollection.Name = "pictureBoxCollection";
this.pictureBoxCollection.Size = new System.Drawing.Size(803, 376);
this.pictureBoxCollection.TabIndex = 0;
this.pictureBoxCollection.Size = new System.Drawing.Size(715, 581);
this.pictureBoxCollection.TabIndex = 1;
this.pictureBoxCollection.TabStop = false;
//
// labelInstruments
//
this.labelInstruments.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.labelInstruments.AutoSize = true;
this.labelInstruments.Location = new System.Drawing.Point(852, 22);
this.labelInstruments.Font = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.labelInstruments.Location = new System.Drawing.Point(753, 12);
this.labelInstruments.Name = "labelInstruments";
this.labelInstruments.Size = new System.Drawing.Size(83, 15);
this.labelInstruments.TabIndex = 1;
this.labelInstruments.Size = new System.Drawing.Size(136, 28);
this.labelInstruments.TabIndex = 2;
this.labelInstruments.Text = "Инструменты";
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(840, 64);
this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(161, 44);
this.buttonAdd.TabIndex = 2;
this.buttonAdd.Text = "Добавить грузовик";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAddTruck_Click);
//
// maskedTextBoxNumber
//
this.maskedTextBoxNumber.Location = new System.Drawing.Point(874, 140);
this.maskedTextBoxNumber.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
this.maskedTextBoxNumber.Size = new System.Drawing.Size(110, 23);
this.maskedTextBoxNumber.TabIndex = 3;
//
// buttonDelete
//
this.buttonDelete.Location = new System.Drawing.Point(840, 167);
this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonDelete.Name = "buttonDelete";
this.buttonDelete.Size = new System.Drawing.Size(165, 45);
this.buttonDelete.TabIndex = 4;
this.buttonDelete.Text = "Удалить грузовик";
this.buttonDelete.UseVisualStyleBackColor = true;
this.buttonDelete.Click += new System.EventHandler(this.ButtonRemoveTruck_Click);
//
// buttonUpdate
//
this.buttonUpdate.Location = new System.Drawing.Point(840, 260);
this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonUpdate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUpdate.Location = new System.Drawing.Point(741, 172);
this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonUpdate.Name = "buttonUpdate";
this.buttonUpdate.Size = new System.Drawing.Size(165, 45);
this.buttonUpdate.TabIndex = 5;
this.buttonUpdate.Text = "Обновить";
this.buttonUpdate.Size = new System.Drawing.Size(150, 33);
this.buttonUpdate.TabIndex = 3;
this.buttonUpdate.Text = "Обновить набор";
this.buttonUpdate.UseVisualStyleBackColor = true;
this.buttonUpdate.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click);
//
// buttonDeleteTruck
//
this.buttonDeleteTruck.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDeleteTruck.Location = new System.Drawing.Point(734, 537);
this.buttonDeleteTruck.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonDeleteTruck.Name = "buttonDeleteTruck";
this.buttonDeleteTruck.Size = new System.Drawing.Size(157, 37);
this.buttonDeleteTruck.TabIndex = 4;
this.buttonDeleteTruck.Text = "Удалить грузовик";
this.buttonDeleteTruck.UseVisualStyleBackColor = true;
this.buttonDeleteTruck.Click += new System.EventHandler(this.buttonDeleteTruck_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(734, 480);
this.maskedTextBoxNumber.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.maskedTextBoxNumber.Mask = "00";
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
this.maskedTextBoxNumber.Size = new System.Drawing.Size(157, 27);
this.maskedTextBoxNumber.TabIndex = 5;
this.maskedTextBoxNumber.ValidatingType = typeof(int);
//
// label1
//
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(741, 63);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(66, 20);
this.label1.TabIndex = 7;
this.label1.Text = "Наборы";
//
// listBoxStorages
//
this.listBoxStorages.FormattingEnabled = true;
this.listBoxStorages.ItemHeight = 20;
this.listBoxStorages.Location = new System.Drawing.Point(741, 209);
this.listBoxStorages.Name = "listBoxStorages";
this.listBoxStorages.Size = new System.Drawing.Size(150, 144);
this.listBoxStorages.TabIndex = 8;
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxObjects_SelectedIndexChanged);
//
// buttonAddStorage
//
this.buttonAddStorage.Location = new System.Drawing.Point(741, 132);
this.buttonAddStorage.Name = "buttonAddStorage";
this.buttonAddStorage.Size = new System.Drawing.Size(150, 33);
this.buttonAddStorage.TabIndex = 9;
this.buttonAddStorage.Text = "Добавить набор";
this.buttonAddStorage.UseVisualStyleBackColor = true;
this.buttonAddStorage.Click += new System.EventHandler(this.buttonAddStorage_Click);
//
// buttonDeleteStorage
//
this.buttonDeleteStorage.Location = new System.Drawing.Point(741, 360);
this.buttonDeleteStorage.Name = "buttonDeleteStorage";
this.buttonDeleteStorage.Size = new System.Drawing.Size(150, 33);
this.buttonDeleteStorage.TabIndex = 10;
this.buttonDeleteStorage.Text = "Удалить набор";
this.buttonDeleteStorage.UseVisualStyleBackColor = true;
this.buttonDeleteStorage.Click += new System.EventHandler(this.buttonDeleteStorage_Click);
//
// textBoxStorageName
//
this.textBoxStorageName.Location = new System.Drawing.Point(741, 99);
this.textBoxStorageName.Name = "textBoxStorageName";
this.textBoxStorageName.Size = new System.Drawing.Size(150, 27);
this.textBoxStorageName.TabIndex = 11;
//
// FormTruckCollection
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1152, 382);
this.Controls.Add(this.buttonUpdate);
this.Controls.Add(this.buttonDelete);
this.ClientSize = new System.Drawing.Size(911, 591);
this.Controls.Add(this.textBoxStorageName);
this.Controls.Add(this.buttonDeleteStorage);
this.Controls.Add(this.buttonAddStorage);
this.Controls.Add(this.listBoxStorages);
this.Controls.Add(this.label1);
this.Controls.Add(this.buttonAddTruck);
this.Controls.Add(this.maskedTextBoxNumber);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.buttonDeleteTruck);
this.Controls.Add(this.buttonUpdate);
this.Controls.Add(this.labelInstruments);
this.Controls.Add(this.pictureBoxCollection);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormTruckCollection";
this.Text = "Грузовик";
this.Text = "Набор грузовиков";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@@ -118,11 +184,17 @@
#endregion
private Button buttonAddTruck;
private PictureBox pictureBoxCollection;
private Label labelInstruments;
private Button buttonAdd;
private TextBox maskedTextBoxNumber;
private Button buttonDelete;
private Button buttonUpdate;
private Button buttonDeleteTruck;
private ColorDialog colorDialog;
private MaskedTextBox maskedTextBoxNumber;
private Label label1;
private ListBox listBoxStorages;
private Button buttonAddStorage;
private Button buttonDeleteStorage;
private TextBox textBoxStorageName;
}
}

View File

@@ -7,79 +7,162 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ProjectGasolineTanker.Drawings;
using ProjectGasolineTanker.Generic;
using ProjectGasolineTanker.Drawings;
using ProjectGasolineTanker.MovementStratg;
using ProjectGasolineTanker;
namespace ProjectGasolineTanker
{
public partial class FormTruckCollection : Form
{
private readonly TruckGenericCollection<DrawingTruck, DrawingObjectTruck> _truck;
// Набор объектов
private readonly TruckGenericStorage _storage;
public FormTruckCollection()
{
InitializeComponent();
_truck = new TruckGenericCollection<DrawingTruck, DrawingObjectTruck>(pictureBoxCollection.Width, pictureBoxCollection.Height);
_storage = new TruckGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
}
private void ButtonAddTruck_Click(object sender, EventArgs e)
// заполнение лист бокс
private void ReloadObjects()
{
FormGasolineTanker form = new();
if (form.ShowDialog() == DialogResult.OK)
int index = listBoxStorages.SelectedIndex;
listBoxStorages.Items.Clear();
for (int i = 0; i < _storage.Keys.Count; i++)
{
if (_truck + form.SelectedTruck != -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = _truck.ShowTruck();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
listBoxStorages.Items.Add(_storage.Keys[i]);
}
if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count))
{
listBoxStorages.SelectedIndex = 0;
}
else if (listBoxStorages.Items.Count > 0 && index > -1 && index < listBoxStorages.Items.Count)
{
listBoxStorages.SelectedIndex = index;
}
}
private void ButtonRemoveTruck_Click(object sender, EventArgs e)
// добавить набор в коллекцию
private void buttonAddStorage_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
if (string.IsNullOrEmpty(textBoxStorageName.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_storage.AddSet(textBoxStorageName.Text);
ReloadObjects();
}
// выбрать набор
private void listBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowTruck();
}
// удалить набор
private void buttonDeleteStorage_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty);
ReloadObjects();
}
}
private void buttonAddTruck_Click(object sender, EventArgs e)
{
var formTruckConfig = new FormTruckConfig();
formTruckConfig.AddEvent(AddTruck);
formTruckConfig.Show();
}
private void AddTruck(DrawingTruck selectedTruck)
{
if (listBoxStorages.SelectedIndex == -1)
{
MessageBox.Show("Не выбран набор");
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
selectedTruck.ChangePictureSize(pictureBoxCollection.Width, pictureBoxCollection.Height);
if (obj + selectedTruck != -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowTruck();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
private void buttonDeleteTruck_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = 0;
try
{
pos = Convert.ToInt32(maskedTextBoxNumber.Text) ;
pos = Convert.ToInt32(maskedTextBoxNumber.Text);
}
catch
{
MessageBox.Show("Ошибка ввода данных");
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (_truck - (_truck.ReturnLength() - pos))
if (obj - pos)
{
MessageBox.Show("Объект удален");
pictureBoxCollection.Image = _truck.ShowTruck();
pictureBoxCollection.Image = obj.ShowTruck();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
}
private void ButtonRefreshCollection_Click(object sender, EventArgs
e)
// обновить рисунок по набору
private void buttonUpdate_Click(object sender, EventArgs e)
{
pictureBoxCollection.Image = _truck.ShowTruck();
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
pictureBoxCollection.Image = obj.ShowTruck();
}
}
}

View File

@@ -57,4 +57,10 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="colorDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>36</value>
</metadata>
</root>

View File

@@ -0,0 +1,382 @@
namespace ProjectGasolineTanker
{
partial class FormTruckConfig
{
/// <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.groupBoxConfig = new System.Windows.Forms.GroupBox();
this.labelAdvancedObject = new System.Windows.Forms.Label();
this.labelSimpleObject = new System.Windows.Forms.Label();
this.groupBoxColor = new System.Windows.Forms.GroupBox();
this.panelLightBlue = new System.Windows.Forms.Panel();
this.panelBlue = new System.Windows.Forms.Panel();
this.panelPurple = new System.Windows.Forms.Panel();
this.panelGray = new System.Windows.Forms.Panel();
this.panelGreen = new System.Windows.Forms.Panel();
this.panelYellow = new System.Windows.Forms.Panel();
this.panelOrange = new System.Windows.Forms.Panel();
this.panelRed = new System.Windows.Forms.Panel();
this.checkBoxWheel = new System.Windows.Forms.CheckBox();
this.checkBoxTanker = new System.Windows.Forms.CheckBox();
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
this.labelWeight = new System.Windows.Forms.Label();
this.labelSpeed = new System.Windows.Forms.Label();
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
this.panelObject = new System.Windows.Forms.Panel();
this.labelAdditionalColor = new System.Windows.Forms.Label();
this.labelMainColor = new System.Windows.Forms.Label();
this.buttonAdd = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.groupBoxConfig.SuspendLayout();
this.groupBoxColor.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
this.panelObject.SuspendLayout();
this.SuspendLayout();
//
// groupBoxConfig
//
this.groupBoxConfig.Controls.Add(this.labelAdvancedObject);
this.groupBoxConfig.Controls.Add(this.labelSimpleObject);
this.groupBoxConfig.Controls.Add(this.groupBoxColor);
this.groupBoxConfig.Controls.Add(this.checkBoxWheel);
this.groupBoxConfig.Controls.Add(this.checkBoxTanker);
this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed);
this.groupBoxConfig.Controls.Add(this.numericUpDownWeight);
this.groupBoxConfig.Controls.Add(this.labelWeight);
this.groupBoxConfig.Controls.Add(this.labelSpeed);
this.groupBoxConfig.Location = new System.Drawing.Point(14, 48);
this.groupBoxConfig.Name = "groupBoxConfig";
this.groupBoxConfig.Size = new System.Drawing.Size(570, 251);
this.groupBoxConfig.TabIndex = 0;
this.groupBoxConfig.TabStop = false;
this.groupBoxConfig.Text = "Параметры";
//
// labelAdvancedObject
//
this.labelAdvancedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelAdvancedObject.Location = new System.Drawing.Point(440, 188);
this.labelAdvancedObject.Name = "labelAdvancedObject";
this.labelAdvancedObject.Size = new System.Drawing.Size(120, 30);
this.labelAdvancedObject.TabIndex = 8;
this.labelAdvancedObject.Text = "Продвинутый";
this.labelAdvancedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelAdvancedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// labelSimpleObject
//
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelSimpleObject.Location = new System.Drawing.Point(283, 188);
this.labelSimpleObject.Name = "labelSimpleObject";
this.labelSimpleObject.Size = new System.Drawing.Size(120, 30);
this.labelSimpleObject.TabIndex = 7;
this.labelSimpleObject.Text = "Простой";
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// groupBoxColor
//
this.groupBoxColor.Controls.Add(this.panelLightBlue);
this.groupBoxColor.Controls.Add(this.panelBlue);
this.groupBoxColor.Controls.Add(this.panelPurple);
this.groupBoxColor.Controls.Add(this.panelGray);
this.groupBoxColor.Controls.Add(this.panelGreen);
this.groupBoxColor.Controls.Add(this.panelYellow);
this.groupBoxColor.Controls.Add(this.panelOrange);
this.groupBoxColor.Controls.Add(this.panelRed);
this.groupBoxColor.Location = new System.Drawing.Point(283, 32);
this.groupBoxColor.Name = "groupBoxColor";
this.groupBoxColor.Size = new System.Drawing.Size(277, 145);
this.groupBoxColor.TabIndex = 6;
this.groupBoxColor.TabStop = false;
this.groupBoxColor.Text = "Цвета";
//
// panelLightBlue
//
this.panelLightBlue.BackColor = System.Drawing.Color.Indigo;
this.panelLightBlue.Location = new System.Drawing.Point(5, 85);
this.panelLightBlue.Name = "panelLightBlue";
this.panelLightBlue.Size = new System.Drawing.Size(50, 40);
this.panelLightBlue.TabIndex = 0;
//
// panelBlue
//
this.panelBlue.BackColor = System.Drawing.Color.Black;
this.panelBlue.Location = new System.Drawing.Point(75, 85);
this.panelBlue.Name = "panelBlue";
this.panelBlue.Size = new System.Drawing.Size(50, 40);
this.panelBlue.TabIndex = 0;
//
// panelPurple
//
this.panelPurple.BackColor = System.Drawing.Color.Fuchsia;
this.panelPurple.Location = new System.Drawing.Point(145, 85);
this.panelPurple.Name = "panelPurple";
this.panelPurple.Size = new System.Drawing.Size(50, 40);
this.panelPurple.TabIndex = 0;
//
// panelGray
//
this.panelGray.BackColor = System.Drawing.Color.Gray;
this.panelGray.Location = new System.Drawing.Point(215, 85);
this.panelGray.Name = "panelGray";
this.panelGray.Size = new System.Drawing.Size(50, 40);
this.panelGray.TabIndex = 0;
//
// panelGreen
//
this.panelGreen.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0)))));
this.panelGreen.Location = new System.Drawing.Point(215, 25);
this.panelGreen.Name = "panelGreen";
this.panelGreen.Size = new System.Drawing.Size(50, 40);
this.panelGreen.TabIndex = 0;
//
// panelYellow
//
this.panelYellow.BackColor = System.Drawing.Color.Gold;
this.panelYellow.Location = new System.Drawing.Point(145, 25);
this.panelYellow.Name = "panelYellow";
this.panelYellow.Size = new System.Drawing.Size(50, 40);
this.panelYellow.TabIndex = 0;
//
// panelOrange
//
this.panelOrange.BackColor = System.Drawing.Color.Cyan;
this.panelOrange.Location = new System.Drawing.Point(75, 25);
this.panelOrange.Name = "panelOrange";
this.panelOrange.Size = new System.Drawing.Size(50, 40);
this.panelOrange.TabIndex = 0;
//
// panelRed
//
this.panelRed.BackColor = System.Drawing.Color.LawnGreen;
this.panelRed.Location = new System.Drawing.Point(5, 25);
this.panelRed.Name = "panelRed";
this.panelRed.Size = new System.Drawing.Size(50, 40);
this.panelRed.TabIndex = 0;
//
// checkBoxWheel
//
this.checkBoxWheel.AutoSize = true;
this.checkBoxWheel.Location = new System.Drawing.Point(13, 149);
this.checkBoxWheel.Name = "checkBoxWheel";
this.checkBoxWheel.Size = new System.Drawing.Size(173, 24);
this.checkBoxWheel.TabIndex = 5;
this.checkBoxWheel.Text = "Наличие доп колеса";
this.checkBoxWheel.UseVisualStyleBackColor = true;
//
// checkBoxTanker
//
this.checkBoxTanker.AutoSize = true;
this.checkBoxTanker.Location = new System.Drawing.Point(13, 119);
this.checkBoxTanker.Name = "checkBoxTanker";
this.checkBoxTanker.Size = new System.Drawing.Size(128, 24);
this.checkBoxTanker.TabIndex = 4;
this.checkBoxTanker.Text = "Наличие бака";
this.checkBoxTanker.UseVisualStyleBackColor = true;
//
// numericUpDownSpeed
//
this.numericUpDownSpeed.Location = new System.Drawing.Point(94, 32);
this.numericUpDownSpeed.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.numericUpDownSpeed.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
this.numericUpDownSpeed.Size = new System.Drawing.Size(150, 27);
this.numericUpDownSpeed.TabIndex = 3;
this.numericUpDownSpeed.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// numericUpDownWeight
//
this.numericUpDownWeight.Location = new System.Drawing.Point(94, 83);
this.numericUpDownWeight.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.numericUpDownWeight.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDownWeight.Name = "numericUpDownWeight";
this.numericUpDownWeight.Size = new System.Drawing.Size(150, 27);
this.numericUpDownWeight.TabIndex = 2;
this.numericUpDownWeight.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// labelWeight
//
this.labelWeight.AutoSize = true;
this.labelWeight.Location = new System.Drawing.Point(6, 85);
this.labelWeight.Name = "labelWeight";
this.labelWeight.Size = new System.Drawing.Size(36, 20);
this.labelWeight.TabIndex = 1;
this.labelWeight.Text = "Вес:";
//
// labelSpeed
//
this.labelSpeed.AutoSize = true;
this.labelSpeed.Location = new System.Drawing.Point(6, 32);
this.labelSpeed.Name = "labelSpeed";
this.labelSpeed.Size = new System.Drawing.Size(76, 20);
this.labelSpeed.TabIndex = 0;
this.labelSpeed.Text = "Скорость:";
//
// pictureBoxObject
//
this.pictureBoxObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBoxObject.Location = new System.Drawing.Point(35, 84);
this.pictureBoxObject.Name = "pictureBoxObject";
this.pictureBoxObject.Size = new System.Drawing.Size(327, 205);
this.pictureBoxObject.TabIndex = 1;
this.pictureBoxObject.TabStop = false;
//
// panelObject
//
this.panelObject.AllowDrop = true;
this.panelObject.Controls.Add(this.labelAdditionalColor);
this.panelObject.Controls.Add(this.labelMainColor);
this.panelObject.Controls.Add(this.pictureBoxObject);
this.panelObject.Location = new System.Drawing.Point(613, 29);
this.panelObject.Name = "panelObject";
this.panelObject.Size = new System.Drawing.Size(401, 301);
this.panelObject.TabIndex = 2;
this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
//
// labelAdditionalColor
//
this.labelAdditionalColor.AllowDrop = true;
this.labelAdditionalColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelAdditionalColor.Location = new System.Drawing.Point(233, 19);
this.labelAdditionalColor.Name = "labelAdditionalColor";
this.labelAdditionalColor.Size = new System.Drawing.Size(90, 50);
this.labelAdditionalColor.TabIndex = 3;
this.labelAdditionalColor.Text = "Доп. цвет";
this.labelAdditionalColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelAdditionalColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelAdditionalColor_DragDrop);
this.labelAdditionalColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelAdditionalColor_DragEnter);
//
// labelMainColor
//
this.labelMainColor.AllowDrop = true;
this.labelMainColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelMainColor.Location = new System.Drawing.Point(77, 19);
this.labelMainColor.Name = "labelMainColor";
this.labelMainColor.Size = new System.Drawing.Size(90, 50);
this.labelMainColor.TabIndex = 2;
this.labelMainColor.Text = "Цвет";
this.labelMainColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelMainColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelMainColor_DragDrop);
this.labelMainColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelMainColor_DragEnter);
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(689, 337);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(94, 29);
this.buttonAdd.TabIndex = 3;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(846, 339);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
this.buttonCancel.TabIndex = 4;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// FormTruckConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1032, 383);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.panelObject);
this.Controls.Add(this.groupBoxConfig);
this.Name = "FormTruckConfig";
this.Text = "FormTruckConfig";
this.groupBoxConfig.ResumeLayout(false);
this.groupBoxConfig.PerformLayout();
this.groupBoxColor.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
this.panelObject.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBoxConfig;
private NumericUpDown numericUpDownSpeed;
private NumericUpDown numericUpDownWeight;
private Label labelWeight;
private Label labelSpeed;
private CheckBox checkBoxWheel;
private CheckBox checkBoxTanker;
private GroupBox groupBoxColor;
private Panel panelLightBlue;
private Panel panelBlue;
private Panel panelPurple;
private Panel panelGray;
private Panel panelGreen;
private Panel panelYellow;
private Panel panelOrange;
private Panel panelRed;
private Label labelAdvancedObject;
private Label labelSimpleObject;
private PictureBox pictureBoxObject;
private Panel panelObject;
private Label labelAdditionalColor;
private Label labelMainColor;
private Button buttonAdd;
private Button buttonCancel;
}
}

View File

@@ -0,0 +1,151 @@
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 ProjectGasolineTanker.Drawings;
using ProjectGasolineTanker.Entities;
namespace ProjectGasolineTanker
{
public partial class FormTruckConfig : Form
{
DrawingTruck? _truck = null;
private event Action<DrawingTruck>? EventAddTruck;
public FormTruckConfig()
{
InitializeComponent();
panelRed.MouseDown += PanelColor_MouseDown;
panelOrange.MouseDown += PanelColor_MouseDown;
panelYellow.MouseDown += PanelColor_MouseDown;
panelGreen.MouseDown += PanelColor_MouseDown;
panelLightBlue.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown;
panelPurple.MouseDown += PanelColor_MouseDown;
panelGray.MouseDown += PanelColor_MouseDown;
buttonCancel.Click += (s, e) => Close();
}
private void DrawTruck()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_truck?.SetPosition(5, 5);
_truck?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
public void AddEvent(Action<DrawingTruck> ev)
{
if (EventAddTruck == null)
{
EventAddTruck = ev;
}
else
{
EventAddTruck += ev;
}
}
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name,
DragDropEffects.Move | DragDropEffects.Copy);
}
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void PanelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text).ToString())
{
case "labelSimpleObject":
_truck = new DrawingTruck(
(int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value,
Color.White,
pictureBoxObject.Width, pictureBoxObject.Height);
break;
case "labelAdvancedObject":
_truck = new DrawingGasolineTanker(
(int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value,
Color.White, Color.Black,
checkBoxTanker.Checked, checkBoxWheel.Checked,
pictureBoxObject.Width, pictureBoxObject.Height);
break;
}
DrawTruck();
}
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor,
DragDropEffects.Move | DragDropEffects.Copy);
}
private void LabelMainColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)) && _truck != null)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void LabelMainColor_DragDrop(object sender, DragEventArgs e)
{
var color = (Color)e.Data.GetData(typeof(Color));
_truck.EntityTruck.ChangeBodyColor(color);
DrawTruck();
}
private void LabelAdditionalColor_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)) && _truck != null && _truck is DrawingGasolineTanker)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void LabelAdditionalColor_DragDrop(object sender, DragEventArgs e)
{
var color = (Color)e.Data.GetData(typeof(Color));
EntityGasolineTanker? _gasolinetanker = _truck.EntityTruck as EntityGasolineTanker;
_gasolinetanker.ChangeAdditionalColor(color);
DrawTruck();
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
EventAddTruck?.Invoke(_truck);
Close();
}
}
}

View File

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

View File

@@ -10,97 +10,78 @@ namespace ProjectGasolineTanker.Generic
where T : class
{
private readonly T?[] _places;
private readonly List<T?> _places;
public int Count => _places.Length - 1;
public int Count => _places.Count;
private readonly int _maxCount;
public SetGeneric(int count)
{
_places = new T?[count];
_maxCount = count;
_places = new List<T?>(count);
}
public int Insert(T truck)
{
int pos = Count - 1;
if (_places[Count] != null)
{
for (int i = pos; i > 0; --i)
{
if (_places[i] == null)
{
pos = i;
break;
}
}
for (int i = pos + 1; i <= Count; ++i)
{
_places[i - 1] = _places[i];
}
}
_places[Count] = truck;
return pos;
_places.Insert(0, truck);
return 0;
}
public bool Insert(T truck, int position)
{
// TODO проверка позиции
if (position < 0 || position > Count)
if (position < 0 || position >= Count || Count >= _maxCount)
{
return false;
}
if (_places[Count] != null)
{
int pos = Count;
for (int i = Count; i > 0; --i)
{
if (_places[i] == null)
{
pos = i;
break;
}
}
for (int i = Count; i >= pos; --i)
{
_places[i - 1] = _places[i];
}
}
_places[Count] = truck;
// TODO вставка по позиции
_places.Insert(position, truck);
return true;
}
public bool Remove(int position)
{
if (position < 0 || position > Count)
if (position < 0 || position >= Count)
{
return false;
}
_places[position] = null;
_places.RemoveAt(position);
return true;
}
public T? Get(int position)
public T? this[int position]
{
if (position < 0 || position > Count)
get
{
return null;
if (position < 0 || position >= Count)
{
return null;
}
return _places[position];
}
set
{
if (position < 0 || position > Count || Count >= _maxCount)
{
return;
}
_places.Insert(position, value);
}
}
public IEnumerable<T?> GetTruck(int? maxTruck = null)
{
for (int i = 0; i < _places.Count; ++i)
{
yield return _places[i];
if (maxTruck.HasValue && i == maxTruck.Value)
{
yield break;
}
}
return _places[position];
}
}
}

View File

@@ -20,7 +20,6 @@ namespace ProjectGasolineTanker.Generic
private readonly SetGeneric<T> _collection;
public TruckGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
@@ -40,24 +39,18 @@ namespace ProjectGasolineTanker.Generic
}
public static bool operator -(TruckGenericCollection<T, U> collect, int pos)
{
if (collect._collection.Get(pos) == null)
if (collect._collection.GetTruck(pos) == null)
{
return false;
}
return collect?._collection.Remove(pos) ?? false;
}
public int ReturnLength()
{
return _collection.Count;
}
public U? GetU(int pos)
{
return (U?)_collection.Get(pos)?.GetMoveableObject;
return (U?)_collection[pos]?.GetMoveableObject;
}
public Bitmap ShowTruck()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
@@ -67,7 +60,6 @@ namespace ProjectGasolineTanker.Generic
return bmp;
}
private void DrawBackground(Graphics gr)
{
Pen pen = new(Color.Black, 3);
@@ -81,38 +73,24 @@ namespace ProjectGasolineTanker.Generic
}
}
private void DrawObjects(Graphics g)
{
int x = 0;
int y = 0;
int index = -1;
int y = _pictureHeight / _placeSizeHeight - 1;
for (int i = 0; i <= _collection.Count; ++i)
foreach (var truck in _collection.GetTruck())
{
DrawingTruck _truck = _collection.Get(i);
x = 0;
y = 0;
if (_truck != null)
if (truck != null)
{
index = i;
while (index - _pictureWidth / _placeSizeWidth >= 0)
{
y++;
index -= _pictureWidth / _placeSizeWidth;
}
if (index > 0)
if (x > _pictureWidth / _placeSizeWidth - 1)
{
x += index;
x = 0;
--y;
}
x = _pictureWidth / _placeSizeWidth - 1 - x;
_truck.SetPosition(_placeSizeWidth * x, _placeSizeHeight * y);
_truck.DrawTransport(g);
truck.SetPosition(_placeSizeWidth * x, _placeSizeHeight * y);
truck.DrawTransport(g);
++x;
}
}
}

View File

@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectGasolineTanker.Drawings;
using ProjectGasolineTanker.MovementStratg;
namespace ProjectGasolineTanker.Generic
{
internal class TruckGenericStorage
{
readonly Dictionary<string, TruckGenericCollection<DrawingTruck, DrawingObjectTruck>> _TruckStorages;
public List<string> Keys => _TruckStorages.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
public TruckGenericStorage(int pictureWidth, int pictureHeight)
{
_TruckStorages = new Dictionary<string, TruckGenericCollection<DrawingTruck, DrawingObjectTruck>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
public void AddSet(string name)
{
foreach (string nameStorage in Keys)
{
if (nameStorage == name)
{
MessageBox.Show("Набор с заданным именем уже занят", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
_TruckStorages.Add(name, new TruckGenericCollection<DrawingTruck, DrawingObjectTruck>(_pictureWidth, _pictureHeight));
}
public void DelSet(string name)
{
if (_TruckStorages.ContainsKey(name))
{
_TruckStorages.Remove(name);
}
}
public TruckGenericCollection<DrawingTruck, DrawingObjectTruck>? this[string ind]
{
get
{
// TODO Продумать логику получения набора
if (_TruckStorages.ContainsKey(ind))
{
return _TruckStorages[ind];
}
return null;
}
}
}
}

View File

@@ -9,9 +9,9 @@ using ProjectGasolineTanker.Entities;
namespace ProjectGasolineTanker.MovementStratg
{
public abstract class AbstractStrategy
{
private IMoveableObject? _moveableObject;
private Status _state = Status.NotInit;
@@ -21,7 +21,7 @@ namespace ProjectGasolineTanker.MovementStratg
protected int FieldHeight { get; private set; }
public Status GetStatus() { return _state; }
public void SetData(IMoveableObject moveableObject, int width, int height)
{
if (moveableObject == null)
@@ -54,7 +54,7 @@ namespace ProjectGasolineTanker.MovementStratg
protected bool MoveRight() => MoveTo(DirectionType.Right);
protected bool MoveUp() => MoveTo(DirectionType.Up);
protected bool MoveDown() => MoveTo(DirectionType.Down);
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
@@ -71,7 +71,7 @@ namespace ProjectGasolineTanker.MovementStratg
protected abstract void MoveToTarget();
protected abstract bool IsTargetDestinaion();
private bool MoveTo(DirectionType directionType)
{
if (_state != Status.InProgress)

View File

@@ -12,15 +12,12 @@ namespace ProjectGasolineTanker.MovementStratg
public interface IMoveableObject
{
ObjectParameters? GetObjectPosition { get; }
int GetStep { get; }
bool CheckCanMove(DirectionType direction);
void MoveObject(DirectionType direction);
}
}

View File

@@ -6,6 +6,7 @@ using System.Threading.Tasks;
namespace ProjectGasolineTanker.MovementStratg
{
public class ObjectParameters
{
private readonly int _x;