laba05.fixed
This commit is contained in:
parent
f1f1ee5917
commit
84c4b43dd4
@ -11,7 +11,7 @@ namespace Bulldoser.Drawings
|
|||||||
public class DrawingBulldoser : DrawingTractor
|
public class DrawingBulldoser : DrawingTractor
|
||||||
{
|
{
|
||||||
public DrawingBulldoser(int speed, double weight, Color bodyColor, Color additionalColor,
|
public DrawingBulldoser(int speed, double weight, Color bodyColor, Color additionalColor,
|
||||||
bool otval, bool seifBatteries, int width, int height) : base(speed, weight, bodyColor, width, height, 180, 120)
|
bool otval, bool seifBatteries, int width, int height) : base(speed, weight, bodyColor, width, height, 140, 123)
|
||||||
{
|
{
|
||||||
if (EntityTractor != null)
|
if (EntityTractor != null)
|
||||||
{
|
{
|
||||||
|
@ -33,42 +33,39 @@ namespace Bulldoser.Drawings
|
|||||||
|
|
||||||
public DrawingTractor(int speed, double weight, Color bodyColor, int width, int heigth)
|
public DrawingTractor(int speed, double weight, Color bodyColor, int width, int heigth)
|
||||||
{
|
{
|
||||||
if (width < _tractWidth || heigth < _tractHeight)
|
if ((heigth > _tractHeight) && (width > _pictureWidth))
|
||||||
{
|
{
|
||||||
return;
|
EntityTractor = new EntityTractor(speed, weight, bodyColor);
|
||||||
}
|
}
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
_pictureHeight = heigth;
|
_pictureHeight = heigth;
|
||||||
EntityTractor = new EntityTractor(speed, weight, bodyColor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected DrawingTractor(int speed, double weight, Color bodyColor, int width,
|
protected DrawingTractor(int speed, double weight, Color bodyColor, int width,
|
||||||
int height, int tractWidth, int tractHeight)
|
int height, int tractWidth, int tractHeight)
|
||||||
{
|
{
|
||||||
if (width < _tractWidth || height < _tractHeight)
|
if ((height > tractHeight) && (width > tractWidth))
|
||||||
{
|
{
|
||||||
return;
|
EntityTractor = new EntityTractor(speed, weight, bodyColor);
|
||||||
}
|
}
|
||||||
_pictureWidth = width;
|
_pictureWidth = width;
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
_tractWidth = tractWidth;
|
_tractWidth = tractWidth;
|
||||||
_tractHeight = tractHeight;
|
_tractHeight = tractHeight;
|
||||||
EntityTractor = new EntityTractor(speed, weight, bodyColor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Установка позиции
|
//Установка позиции
|
||||||
public void SetPosition(int x, int y)
|
public void SetPosition(int x, int y)
|
||||||
{
|
{
|
||||||
if (x < 0 || x + _tractWidth > _pictureWidth)
|
if ((x < 0 || y < 0) || (x + _tractWidth > _pictureWidth || y + _tractHeight > _pictureHeight))
|
||||||
{
|
{
|
||||||
x = _pictureWidth - tractWidth;
|
x = 0;
|
||||||
|
y = 0;
|
||||||
}
|
}
|
||||||
if (y < 0 || y + _tractHeight > _pictureHeight)
|
else {
|
||||||
{
|
_startPosX = x;
|
||||||
y = _pictureHeight - _tractHeight;
|
_startPosY = y;
|
||||||
}
|
}
|
||||||
_startPosX = x;
|
|
||||||
_startPosY = y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MoveTransport(Direction direction)
|
public void MoveTransport(Direction direction)
|
||||||
|
@ -41,8 +41,8 @@ namespace Bulldoser
|
|||||||
dopColor = colorDialog.Color;
|
dopColor = colorDialog.Color;
|
||||||
}
|
}
|
||||||
_drawingTractor = new DrawingBulldoser(random.Next(100, 300), random.Next(1000, 3000), color, dopColor,
|
_drawingTractor = new DrawingBulldoser(random.Next(100, 300), random.Next(1000, 3000), color, dopColor,
|
||||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
|
||||||
pictureBoxBulldoser.Width, pictureBoxBulldoser.Height);
|
pictureBoxBulldoser.Width, pictureBoxBulldoser.Height);
|
||||||
_drawingTractor.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
_drawingTractor.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
9
Bulldoser/Bulldoser/Form2.Designer.cs
generated
9
Bulldoser/Bulldoser/Form2.Designer.cs
generated
@ -46,9 +46,11 @@
|
|||||||
//
|
//
|
||||||
// pictureBoxCollections
|
// pictureBoxCollections
|
||||||
//
|
//
|
||||||
pictureBoxCollections.Location = new Point(12, 6);
|
pictureBoxCollections.Dock = DockStyle.Left;
|
||||||
|
pictureBoxCollections.Location = new Point(0, 0);
|
||||||
pictureBoxCollections.Name = "pictureBoxCollections";
|
pictureBoxCollections.Name = "pictureBoxCollections";
|
||||||
pictureBoxCollections.Size = new Size(570, 432);
|
pictureBoxCollections.Size = new Size(588, 450);
|
||||||
|
pictureBoxCollections.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||||
pictureBoxCollections.TabIndex = 1;
|
pictureBoxCollections.TabIndex = 1;
|
||||||
pictureBoxCollections.TabStop = false;
|
pictureBoxCollections.TabStop = false;
|
||||||
//
|
//
|
||||||
@ -59,7 +61,7 @@
|
|||||||
groupBoxTools.Controls.Add(buttonUpdateCollection);
|
groupBoxTools.Controls.Add(buttonUpdateCollection);
|
||||||
groupBoxTools.Controls.Add(buttonRemoveTransport);
|
groupBoxTools.Controls.Add(buttonRemoveTransport);
|
||||||
groupBoxTools.Controls.Add(buttonAddTransport);
|
groupBoxTools.Controls.Add(buttonAddTransport);
|
||||||
groupBoxTools.Location = new Point(588, 6);
|
groupBoxTools.Location = new Point(594, 6);
|
||||||
groupBoxTools.Name = "groupBoxTools";
|
groupBoxTools.Name = "groupBoxTools";
|
||||||
groupBoxTools.Size = new Size(200, 432);
|
groupBoxTools.Size = new Size(200, 432);
|
||||||
groupBoxTools.TabIndex = 2;
|
groupBoxTools.TabIndex = 2;
|
||||||
@ -172,6 +174,7 @@
|
|||||||
groupBox1.ResumeLayout(false);
|
groupBox1.ResumeLayout(false);
|
||||||
groupBox1.PerformLayout();
|
groupBox1.PerformLayout();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -74,27 +74,27 @@ namespace Bulldoser
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var formBulldozerConfig = new FormBulldoserConfig();
|
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
|
||||||
formBulldozerConfig.AddEvent(usta =>
|
if (obj == null)
|
||||||
{
|
{
|
||||||
if (listBoxStorage.SelectedIndex != -1)
|
return;
|
||||||
|
}
|
||||||
|
FormBulldoserConfig form = new(pictureBoxCollections.Width, pictureBoxCollections.Height);
|
||||||
|
form.Show();
|
||||||
|
Action<DrawingTractor>? TractorDelegate = new((m) =>
|
||||||
|
{
|
||||||
|
bool q = (obj + m);
|
||||||
|
if (q)
|
||||||
{
|
{
|
||||||
var obj = _storage[listBoxStorage.SelectedItem?.ToString() ?? string.Empty];
|
MessageBox.Show("Объект добавлен");
|
||||||
if (obj != null)
|
pictureBoxCollections.Image = obj.ShowTractors();
|
||||||
{
|
}
|
||||||
if (obj + usta != 1)
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
pictureBoxCollections.Image = obj.ShowTractors();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MessageBox.Show("Не удалось добавить объект");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
formBulldozerConfig.Show();
|
form.AddEvent(TractorDelegate);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonRemoveTractor_Click(object sender, EventArgs e)
|
private void ButtonRemoveTractor_Click(object sender, EventArgs e)
|
||||||
|
@ -25,7 +25,10 @@ namespace Bulldoser
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FormBulldoserConfig()
|
///
|
||||||
|
private readonly int PictureWidth;
|
||||||
|
private readonly int PictureHeight;
|
||||||
|
public FormBulldoserConfig(int width, int height)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
panelBlack.MouseDown += panelColor_MouseDown;
|
panelBlack.MouseDown += panelColor_MouseDown;
|
||||||
@ -38,6 +41,8 @@ namespace Bulldoser
|
|||||||
panelBlue.MouseDown += panelColor_MouseDown;
|
panelBlue.MouseDown += panelColor_MouseDown;
|
||||||
// TODO buttonCancel.Click with lambda
|
// TODO buttonCancel.Click with lambda
|
||||||
buttonCancel.Click += (sender, e) => Close();
|
buttonCancel.Click += (sender, e) => Close();
|
||||||
|
PictureWidth = width;
|
||||||
|
PictureHeight = height;
|
||||||
}
|
}
|
||||||
private void DrawBulldozer()
|
private void DrawBulldozer()
|
||||||
{
|
{
|
||||||
@ -82,12 +87,13 @@ namespace Bulldoser
|
|||||||
switch (e.Data?.GetData(DataFormats.Text).ToString())
|
switch (e.Data?.GetData(DataFormats.Text).ToString())
|
||||||
{
|
{
|
||||||
case "labelModifiedObject":
|
case "labelModifiedObject":
|
||||||
_bulldozer = new DrawingBulldoser((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxSeifBatteries.Checked,
|
_bulldozer = new DrawingBulldoser((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White,
|
||||||
checkBoxOtval.Checked, pictureBoxObject.Width, pictureBoxObject.Height);
|
Color.Black, checkBoxSeifBatteries.Checked,checkBoxOtval.Checked,
|
||||||
|
PictureWidth, PictureHeight);
|
||||||
break;
|
break;
|
||||||
case "labelSimpleObject":
|
case "labelSimpleObject":
|
||||||
_bulldozer = new DrawingTractor((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
|
_bulldozer = new DrawingTractor((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White,
|
||||||
pictureBoxObject.Height);
|
PictureWidth, PictureHeight);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
DrawBulldozer();
|
DrawBulldozer();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using Bulldoser.Drawings;
|
using Bulldoser.Drawings;
|
||||||
using Bulldoser.MovementStrategy;
|
using Bulldoser.MovementStrategy;
|
||||||
|
using Microsoft.VisualBasic;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -20,7 +21,6 @@ namespace Bulldoser.Generic
|
|||||||
private readonly SetGeneric<T> _collection;
|
private readonly SetGeneric<T> _collection;
|
||||||
public TractorGenericCollection(int picWidth, int picHeight)
|
public TractorGenericCollection(int picWidth, int picHeight)
|
||||||
{
|
{
|
||||||
|
|
||||||
// высчитываем размер массива для setgeneric
|
// высчитываем размер массива для setgeneric
|
||||||
int width = picWidth / _placeSizeWidth;
|
int width = picWidth / _placeSizeWidth;
|
||||||
int height = picHeight / _placeSizeHeight;
|
int height = picHeight / _placeSizeHeight;
|
||||||
@ -29,13 +29,13 @@ namespace Bulldoser.Generic
|
|||||||
_collection = new SetGeneric<T>(width * height);
|
_collection = new SetGeneric<T>(width * height);
|
||||||
}
|
}
|
||||||
/// Перегрузка оператора сложения
|
/// Перегрузка оператора сложения
|
||||||
public static int operator +(TractorGenericCollection<T, U> collect, T tract)
|
public static bool operator +(TractorGenericCollection<T, U> collect, T tract)
|
||||||
{
|
{
|
||||||
if (tract == null)
|
if (tract == null)
|
||||||
{
|
{
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
return collect._collection.Insert(tract);
|
return collect?._collection.Insert(tract)??false;
|
||||||
}
|
}
|
||||||
public static T? operator -(TractorGenericCollection<T, U> collect, int
|
public static T? operator -(TractorGenericCollection<T, U> collect, int
|
||||||
pos)
|
pos)
|
||||||
@ -78,18 +78,18 @@ namespace Bulldoser.Generic
|
|||||||
{
|
{
|
||||||
int width = _pictureWidth / _placeSizeWidth;
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
int height = _pictureHeight / _placeSizeHeight;
|
int height = _pictureHeight / _placeSizeHeight;
|
||||||
for (int i = 0; i < _collection.Count; i++)
|
int i = 0;
|
||||||
{
|
foreach (var tractor in _collection.GetTractors()) {
|
||||||
// Получение объекта
|
if (tractor != null) {
|
||||||
var obj = _collection[i];
|
// Получение объекта
|
||||||
// Установка позиции
|
// Установка позиции
|
||||||
obj?.SetPosition(
|
int row = height - 1 - (i / width);
|
||||||
//переделать позиции
|
int col = width - 1 - (i % width);
|
||||||
(int)((width - 1) * _placeSizeWidth - (i % width * _placeSizeWidth)),
|
tractor.SetPosition(col * _placeSizeWidth, row * _placeSizeHeight);
|
||||||
(int)((height - 1) * _placeSizeHeight - (i / width * _placeSizeHeight))
|
// Прорисовка объекта
|
||||||
) ;
|
tractor?.DrawTransport(g);
|
||||||
// Прорисовка объекта
|
}
|
||||||
obj?.DrawTransport(g);
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,15 +16,17 @@ namespace Bulldoser.Generic
|
|||||||
_places = new List<T?>(count);
|
_places = new List<T?>(count);
|
||||||
_maxCount = count;
|
_maxCount = count;
|
||||||
}
|
}
|
||||||
public int Insert(T tract)
|
public bool Insert(T tract)
|
||||||
{
|
{
|
||||||
return Insert(tract, 0);
|
if (_places.Count == _maxCount) return false;
|
||||||
|
Insert(tract, 0 );
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
public int Insert(T tract, int position)
|
public bool Insert(T tract, int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= _maxCount) return -1;
|
if (!(position >= 0 && position <= Count && _places.Count < _maxCount)) return false;
|
||||||
_places.Insert(position, tract);
|
_places.Insert(position, tract);
|
||||||
return position;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T? Remove(int position)
|
public T? Remove(int position)
|
||||||
@ -41,15 +43,16 @@ namespace Bulldoser.Generic
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= Count) return null;
|
if (!(position >= 0 && position < Count))
|
||||||
|
return null;
|
||||||
return _places[position];
|
return _places[position];
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= Count || Count == _maxCount) return;
|
if (!(position >= 0 && position < Count && _places.Count < _maxCount))
|
||||||
|
return;
|
||||||
_places.Insert(position, value);
|
_places.Insert(position, value);
|
||||||
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public IEnumerable<T?> GetTractors(int? maxTracts = null)
|
public IEnumerable<T?> GetTractors(int? maxTracts = null)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user