LabWork03 PIbd-21 Zacharchenko #3

Closed
shadowik wants to merge 4 commits from LabWork03 into master
5 changed files with 132 additions and 104 deletions
Showing only changes of commit c84fb1538f - Show all commits

View File

@ -34,9 +34,7 @@ namespace DoubleDeckerBus
return DrawMapWithObject();
}
public Bitmap MoveObject(Direction direction)
{
// TODO проверка, что объект может переместится в требуемом направлении
{
_drawingObject.MoveObject(direction);
bool collision = CheckCollision();
@ -69,16 +67,9 @@ namespace DoubleDeckerBus
int x = _random.Next(0, 10);
int y = _random.Next(0, 10);
_drawingObject.SetObject(x, y, _width, _height);
// TODO првоерка, что объект не "накладывается" на закрытые участки
while (CheckCollision()) {
x = _random.Next(0, 10);
y = _random.Next(0, 10);
_drawingObject.SetObject(x, y, _width, _height);
}
return true;
return !CheckCollision();
}
private Bitmap DrawMapWithObject()
{

View File

@ -29,17 +29,17 @@
private void InitializeComponent()
{
this.groupBoxSettings = new System.Windows.Forms.GroupBox();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.buttonAddBus = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonDeleteBus = new System.Windows.Forms.Button();
this.buttonShowStorage = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.buttonShowStorage = new System.Windows.Forms.Button();
this.buttonDeleteBus = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonAddBus = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBoxSettings.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
@ -64,72 +64,6 @@
this.groupBoxSettings.TabStop = false;
this.groupBoxSettings.Text = "Инструменты";
//
// pictureBox
//
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 0);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(600, 450);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 22);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(188, 23);
this.comboBoxSelectorMap.TabIndex = 0;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// buttonAddBus
//
this.buttonAddBus.Location = new System.Drawing.Point(6, 87);
this.buttonAddBus.Name = "buttonAddBus";
this.buttonAddBus.Size = new System.Drawing.Size(188, 36);
this.buttonAddBus.TabIndex = 1;
this.buttonAddBus.Text = "Добавить автобус";
this.buttonAddBus.UseVisualStyleBackColor = true;
this.buttonAddBus.Click += new System.EventHandler(this.ButtonAddBus_Click);
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 152);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(188, 23);
this.maskedTextBoxPosition.TabIndex = 2;
//
// buttonDeleteBus
//
this.buttonDeleteBus.Location = new System.Drawing.Point(6, 181);
this.buttonDeleteBus.Name = "buttonDeleteBus";
this.buttonDeleteBus.Size = new System.Drawing.Size(188, 36);
this.buttonDeleteBus.TabIndex = 3;
this.buttonDeleteBus.Text = "Удалить автобус";
this.buttonDeleteBus.UseVisualStyleBackColor = true;
this.buttonDeleteBus.Click += new System.EventHandler(this.ButtonRemoveBus_Click);
//
// buttonShowStorage
//
this.buttonShowStorage.Location = new System.Drawing.Point(6, 261);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(182, 35);
this.buttonShowStorage.TabIndex = 4;
this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true;
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(6, 320);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(182, 35);
this.button1.TabIndex = 5;
this.button1.Text = "Посмотреть карту";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
//
// buttonRight
//
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
@ -186,6 +120,76 @@
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(6, 320);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(182, 35);
this.button1.TabIndex = 5;
this.button1.Text = "Посмотреть карту";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
//
// buttonShowStorage
//
this.buttonShowStorage.Location = new System.Drawing.Point(6, 261);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(182, 35);
this.buttonShowStorage.TabIndex = 4;
this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true;
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
//
// buttonDeleteBus
//
this.buttonDeleteBus.Location = new System.Drawing.Point(6, 181);
this.buttonDeleteBus.Name = "buttonDeleteBus";
this.buttonDeleteBus.Size = new System.Drawing.Size(188, 36);
this.buttonDeleteBus.TabIndex = 3;
this.buttonDeleteBus.Text = "Удалить автобус";
this.buttonDeleteBus.UseVisualStyleBackColor = true;
this.buttonDeleteBus.Click += new System.EventHandler(this.ButtonRemoveBus_Click);
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 152);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(188, 23);
this.maskedTextBoxPosition.TabIndex = 2;
//
// buttonAddBus
//
this.buttonAddBus.Location = new System.Drawing.Point(6, 87);
this.buttonAddBus.Name = "buttonAddBus";
this.buttonAddBus.Size = new System.Drawing.Size(188, 36);
this.buttonAddBus.TabIndex = 1;
this.buttonAddBus.Text = "Добавить автобус";
this.buttonAddBus.UseVisualStyleBackColor = true;
this.buttonAddBus.Click += new System.EventHandler(this.ButtonAddBus_Click);
//
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Простая карта",
"Водная карта"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 22);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(188, 23);
this.comboBoxSelectorMap.TabIndex = 0;
this.comboBoxSelectorMap.Text = "Простая карта";
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// pictureBox
//
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 0);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(600, 450);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
// FormMapWithSetBuses
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);

View File

@ -18,6 +18,9 @@ namespace DoubleDeckerBus
public FormMapWithSetBuses()
{
InitializeComponent();
AbstractMap map = new SimpleMap();
_mapBusesCollectionGeneric = new MapWithSetBusesGeneric<DrawingObjectBus, AbstractMap>(
pictureBox.Width, pictureBox.Height, map);
}
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
@ -28,6 +31,9 @@ namespace DoubleDeckerBus
case "Простая карта":
map = new SimpleMap();
break;
case "Водная карта":
map = new WaterMap();
break;
}
if (map != null)
{
@ -49,7 +55,14 @@ namespace DoubleDeckerBus
FormBus form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (form.SelectedBus == null)
{
MessageBox.Show("Вы не создали объект");
return;
}
DrawingObjectBus bus = new(form.SelectedBus);
if (_mapBusesCollectionGeneric + bus)
{
MessageBox.Show("Объект добавлен");

View File

@ -94,17 +94,14 @@ namespace DoubleDeckerBus
}
}
}
/// <summary>
/// Метод отрисовки фона
/// </summary>
/// <param name="g"></param>
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
{//линия рамзетки места
{//линия разетки места
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
@ -113,10 +110,27 @@ namespace DoubleDeckerBus
private void DrawBuses(Graphics g)
{
for (int i = 0; i < _setBuses.Count; i++)
{
// TODO установка позиции
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
int currentWidth = 0;
int currentHeight = 0;
for (int i = 0; i < _setBuses.Count; i++) {
_setBuses.Get(i)?.SetObject(currentWidth * _placeSizeWidth,
currentHeight * _placeSizeHeight,
_pictureWidth, _pictureHeight);
_setBuses.Get(i)?.DrawingObject(g);
if (currentHeight < height)
currentHeight++;
else
{
currentHeight = 0;
currentWidth++;
}
if (currentWidth > width) return;
}
}
}

View File

@ -12,39 +12,45 @@ namespace DoubleDeckerBus
private readonly T[] _places;
public int Count => _places.Length;
private int BusyPlaces = 0;
public SetBusesGeneric(int count)
{
_places = new T[count];
}
public bool Insert(T car)
public bool Insert(T bus)
{
// TODO вставка в начало набора
return true;
return Insert(bus, 0);
}
public bool Insert(T bus, int position)
{
// TODO проверка позиции
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
// проверка, что после вставляемого элемента в массиве есть пустой элемент
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
// TODO вставка по позиции
if (position < 0 || position >= _places.Length || BusyPlaces == _places.Length) return false;
BusyPlaces++;
while (_places[position] != null) {
for (int i = _places.Length - 1; i > 0; --i) {
if (_places[i] == null && _places[i - 1] != null) {
_places[i] = _places[i - 1];
_places[i - 1] = null;
}
}
}
_places[position] = bus;
return true;
}
public bool Remove(int position)
{
// TODO проверка позиции
// TODO удаление объекта из массива, присовив элементу массива значение null
if (position < 0 || position >= _places.Length) return false;
_places[position] = null;
return true;
}
public T Get(int position)
{
// TODO проверка позиции
if (position < 0 || position >= _places.Length) return null;
return _places[position];
}
}