Лаба 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>
/// Размер места (ширина) /// Размер места (ширина)
/// </summary> /// </summary>
protected readonly int _placeSizeWidth = 210; protected readonly int _placeSizeWidth = 190;
/// <summary> /// <summary>
/// Размер места (высота) /// Размер места (высота)
/// </summary> /// </summary>
protected readonly int _placeSizeHeight = 80; protected readonly int _placeSizeHeight = 130;
/// <summary> /// <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) public T? Get(int position)
{ {
//TODO проверка позиции //Проверка позиции
return _collection[position]; if ((position >= 0) && (position < Count))
{
return _collection[position];
}
else
{
return null;
}
} }
public bool Insert(T obj) public bool Insert(T obj)
{ {
//TODO вставка в свободное место набора //Вставка в свободное место набора
for (int i = 0; i < Count; i++)
{
if (_collection[i] == null)
{
_collection[i] = obj;
return true;
}
}
return false; return false;
} }
public bool Insert(T obj, int position) public bool Insert(T obj, int position)
{ {
//TODO Проверка позиции //Проверка позиции
//TODO проверка, что элемент массива по этой позиции пустой, если нет, то ищется свободное место после этой if ((position < 0) || (position >= Count))
{
return false;
}
//Проверка, что элемент массива по этой позиции пустой, если нет, то ищется свободное место после этой
//позиции и идёт вставка туда, если нет после, ищем до //позиции и идёт вставка туда, если нет после, ищем до
//TODO вставка if (_collection[position] != null)
return false; {
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) public bool Remove(int position)
{ {
//TODO проверка позиции //Проверка позиции
//TODO удаление объекта из массива, присвоив элементу массива значение null if ((position < 0) || (position >= Count) || (_collection[position] == null))
{
return false;
}
//Удаление объекта из массива, присвоив элементу массива значение null
_collection[position] = null;
return true; return true;
} }
} }

View File

@ -29,12 +29,10 @@
private void InitializeComponent() private void InitializeComponent()
{ {
pictureBoxBulldozer = new PictureBox(); pictureBoxBulldozer = new PictureBox();
ButtonCreateBulldozer = new Button();
buttonRight = new Button(); buttonRight = new Button();
buttonUp = new Button(); buttonUp = new Button();
buttonLeft = new Button(); buttonLeft = new Button();
buttonDown = new Button(); buttonDown = new Button();
ButtonCreateDozer = new Button();
comboBoxStrategy = new ComboBox(); comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button(); buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxBulldozer).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxBulldozer).BeginInit();
@ -50,18 +48,6 @@
pictureBoxBulldozer.TabIndex = 0; pictureBoxBulldozer.TabIndex = 0;
pictureBoxBulldozer.TabStop = false; 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
// //
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
@ -110,18 +96,6 @@
buttonDown.UseVisualStyleBackColor = true; buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click; 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
// //
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@ -151,12 +125,10 @@
ClientSize = new Size(874, 429); ClientSize = new Size(874, 429);
Controls.Add(buttonStrategyStep); Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy); Controls.Add(comboBoxStrategy);
Controls.Add(ButtonCreateDozer);
Controls.Add(buttonDown); Controls.Add(buttonDown);
Controls.Add(buttonLeft); Controls.Add(buttonLeft);
Controls.Add(buttonUp); Controls.Add(buttonUp);
Controls.Add(buttonRight); Controls.Add(buttonRight);
Controls.Add(ButtonCreateBulldozer);
Controls.Add(pictureBoxBulldozer); Controls.Add(pictureBoxBulldozer);
Name = "FormBulldozer"; Name = "FormBulldozer";
Text = "FormBulldozer"; Text = "FormBulldozer";
@ -168,12 +140,10 @@
#endregion #endregion
private PictureBox pictureBoxBulldozer; private PictureBox pictureBoxBulldozer;
private Button ButtonCreateBulldozer;
private Button buttonRight; private Button buttonRight;
private Button buttonUp; private Button buttonUp;
private Button buttonLeft; private Button buttonLeft;
private Button buttonDown; private Button buttonDown;
private Button ButtonCreateDozer;
private ComboBox comboBoxStrategy; private ComboBox comboBoxStrategy;
private Button buttonStrategyStep; private Button buttonStrategyStep;
} }

View File

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

View File

@ -36,7 +36,17 @@ public partial class FormBulldozerCollection : Form
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></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) switch (comboBoxSelectorCompany.Text)
{ {
@ -44,7 +54,7 @@ public partial class FormBulldozerCollection : Form
_company = new CarSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObject<DrawningDozer>()); _company = new CarSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObject<DrawningDozer>());
break; break;
} }
} }*/
/// <summary> /// <summary>
/// Добавление обычного бульдозера /// Добавление обычного бульдозера
@ -101,12 +111,6 @@ public partial class FormBulldozerCollection : Form
{ {
MessageBox.Show("Не удалось добавить объект..."); 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> /// <summary>
@ -197,7 +201,7 @@ public partial class FormBulldozerCollection : Form
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonRefresh_Click(object sender, EventArgs e) private void ButtonRefresh_Click(object sender, EventArgs e)
{ {
if(_company == null) if (_company == null)
{ {
return; return;
} }