Лаба 3, перед перенесением доп цвета в крутой бульдозер.

This commit is contained in:
MariaBelkina 2024-04-12 22:19:35 +04:00
parent 2dd9a71e1f
commit 614075b569
7 changed files with 170 additions and 85 deletions

View File

@ -16,12 +16,12 @@ public abstract class AbstractCompany
/// <summary>
/// Размер места (ширина)
/// </summary>
protected readonly int _placeSizeWidth = 210;
protected readonly int _placeSizeWidth = 190;
/// <summary>
/// Размер места (высота)
/// </summary>
protected readonly int _placeSizeHeight = 80;
protected readonly int _placeSizeHeight = 130;
/// <summary>
/// Ширина окна

View File

@ -1,35 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectBulldozer.Drawnings;
namespace ProjectBulldozer.CollectionGenericObjects;
/// <summary>
/// Реализация абстрактной компании
/// </summary>
public class CarSharingService : AbstractCompany
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
/// <param name="collectoin"></param>
public CarSharingService(int picWidth, int picHeight, ICollectoinGenericObjects<DrawningDozer> collectoin) : base(picWidth, picHeight, collectoin)
{
}
protected override void DrawBackground(Graphics g)
{
throw new NotImplementedException();
}
protected override void SetObjectsPosition()
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectBulldozer.Drawnings;
namespace ProjectBulldozer.CollectionGenericObjects;
/// <summary>
/// Реализация абстрактной компании
/// </summary>
public class Garage : AbstractCompany
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
/// <param name="collectoin"></param>
public Garage(int picWidth, int picHeight, ICollectoinGenericObjects<DrawningDozer> collectoin) : base(picWidth, picHeight, collectoin)
{
}
/// <summary>
/// отрисовка парковки
/// </summary>
/// <param name="g"></param>
protected override void DrawBackground(Graphics g)
{
int cntVertically = _pictureHeight / _placeSizeHeight; //Колличество мест по вертикали
int cntHorizontally = _pictureWidth / _placeSizeWidth; //Колличество мест по горизонтали
Pen pen = new Pen(Color.FromArgb(0, 0, 0));
pen.Width = 3;
for (int i = 0; i < cntHorizontally; i++)
{
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, cntVertically * _placeSizeHeight);
for (int j = 0; j < cntVertically + 1; j++)
{
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, (i + 1) * _placeSizeWidth - 50, j * _placeSizeHeight);
}
}
}
/// <summary>
/// выбор места на парковке
/// </summary>
protected override void SetObjectsPosition()
{
//Влево, вверх
int width = _pictureWidth / _placeSizeWidth - 1;
int height = _pictureHeight / _placeSizeHeight - 1;
int placeHorizontally = width;
int placeVertically = height;
for (int i = 0; i < (_collection?.Count ?? 0); i++)
{
if (placeVertically < 0)
{
return;
}
if (_collection?.Get(i) != null)
{
_collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
_collection?.Get(i)?.SetPosition(_placeSizeWidth * placeHorizontally + 20, _placeSizeHeight * placeVertically + 20);
}
if (placeHorizontally > 0)
{
placeHorizontally--;
}
else
{
placeHorizontally = width;
placeVertically--;
}
}
//throw new NotImplementedException();
}
}

View File

@ -41,29 +41,89 @@ public class MassiveGenericObject<T> : ICollectoinGenericObjects<T>
public T? Get(int position)
{
//TODO проверка позиции
//Проверка позиции
if ((position >= 0) && (position < Count))
{
return _collection[position];
}
else
{
return null;
}
}
public bool Insert(T obj)
{
//TODO вставка в свободное место набора
//Вставка в свободное место набора
for (int i = 0; i < Count; i++)
{
if (_collection[i] == null)
{
_collection[i] = obj;
return true;
}
}
return false;
}
public bool Insert(T obj, int position)
{
//TODO Проверка позиции
//TODO проверка, что элемент массива по этой позиции пустой, если нет, то ищется свободное место после этой
//позиции и идёт вставка туда, если нет после, ищем до
//TODO вставка
//Проверка позиции
if ((position < 0) || (position >= Count))
{
return false;
}
//Проверка, что элемент массива по этой позиции пустой, если нет, то ищется свободное место после этой
//позиции и идёт вставка туда, если нет после, ищем до
if (_collection[position] != null)
{
bool placed = false;
for (int i = position + 1; i < Count; i++)
{
if (_collection[i] == null)
{
position = i;
placed = true;
break;
}
}
if (placed == false)
{
for (int i = position - 1; i >= 0; i--)
{
if (_collection[i] == null)
{
position = i;
placed = true;
break;
}
}
}
if (placed == false)
{
return false;
}
}
//Вставка
_collection[position] = obj;
return true;
}
public bool Remove(int position)
{
//TODO проверка позиции
//TODO удаление объекта из массива, присвоив элементу массива значение null
//Проверка позиции
if ((position < 0) || (position >= Count) || (_collection[position] == null))
{
return false;
}
//Удаление объекта из массива, присвоив элементу массива значение null
_collection[position] = null;
return true;
}
}

View File

@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxBulldozer = new PictureBox();
ButtonCreateBulldozer = new Button();
buttonRight = new Button();
buttonUp = new Button();
buttonLeft = new Button();
buttonDown = new Button();
ButtonCreateDozer = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxBulldozer).BeginInit();
@ -50,18 +48,6 @@
pictureBoxBulldozer.TabIndex = 0;
pictureBoxBulldozer.TabStop = false;
//
// ButtonCreateBulldozer
//
ButtonCreateBulldozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
ButtonCreateBulldozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
ButtonCreateBulldozer.Location = new Point(12, 371);
ButtonCreateBulldozer.Name = "ButtonCreateBulldozer";
ButtonCreateBulldozer.Size = new Size(325, 46);
ButtonCreateBulldozer.TabIndex = 1;
ButtonCreateBulldozer.Text = "Создать крутой бульдозер";
ButtonCreateBulldozer.UseVisualStyleBackColor = true;
ButtonCreateBulldozer.Click += ButtonCreateBulldozer_Click;
//
// buttonRight
//
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
@ -110,18 +96,6 @@
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click;
//
// ButtonCreateDozer
//
ButtonCreateDozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
ButtonCreateDozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point);
ButtonCreateDozer.Location = new Point(343, 371);
ButtonCreateDozer.Name = "ButtonCreateDozer";
ButtonCreateDozer.Size = new Size(248, 46);
ButtonCreateDozer.TabIndex = 6;
ButtonCreateDozer.Text = "Создать бульдозер";
ButtonCreateDozer.UseVisualStyleBackColor = true;
ButtonCreateDozer.Click += ButtonCreateDozer_Click;
//
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@ -151,12 +125,10 @@
ClientSize = new Size(874, 429);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
Controls.Add(ButtonCreateDozer);
Controls.Add(buttonDown);
Controls.Add(buttonLeft);
Controls.Add(buttonUp);
Controls.Add(buttonRight);
Controls.Add(ButtonCreateBulldozer);
Controls.Add(pictureBoxBulldozer);
Name = "FormBulldozer";
Text = "FormBulldozer";
@ -168,12 +140,10 @@
#endregion
private PictureBox pictureBoxBulldozer;
private Button ButtonCreateBulldozer;
private Button buttonRight;
private Button buttonUp;
private Button buttonLeft;
private Button buttonDown;
private Button ButtonCreateDozer;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}

View File

@ -76,6 +76,7 @@
buttonRefresh.TabIndex = 3;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click;
//
// buttonGoToCheck
//
@ -136,6 +137,7 @@
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(332, 41);
comboBoxSelectorCompany.TabIndex = 1;
comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged;
//
// pictureBox
//

View File

@ -36,7 +36,17 @@ public partial class FormBulldozerCollection : Form
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxSelectorCompany_SelectedIndexChanget(object sender, EventArgs e)
private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new Garage(pictureBox.Width, pictureBox.Height, new MassiveGenericObject<DrawningDozer>());
break;
}
}
/* private void ComboBoxSelectorCompany_SelectedIndexChanget(object sender, EventArgs e)
{
switch (comboBoxSelectorCompany.Text)
{
@ -44,7 +54,7 @@ public partial class FormBulldozerCollection : Form
_company = new CarSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObject<DrawningDozer>());
break;
}
}
}*/
/// <summary>
/// Добавление обычного бульдозера
@ -101,12 +111,6 @@ public partial class FormBulldozerCollection : Form
{
MessageBox.Show("Не удалось добавить объект...");
}
/*
_drawningDozer.SetPictureSize(pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
_drawningDozer.SetPosition(random.Next(10, 100), random.Next(10, 100));
_strategy = null;
comboBoxStrategy.Enabled = true;
Draw();*/
}
/// <summary>
@ -197,7 +201,7 @@ public partial class FormBulldozerCollection : Form
/// <param name="e"></param>
private void ButtonRefresh_Click(object sender, EventArgs e)
{
if(_company == null)
if (_company == null)
{
return;
}