LabWork03 PIbd-21 Zacharchenko #3

Closed
shadowik wants to merge 4 commits from LabWork03 into master
4 changed files with 49 additions and 22 deletions
Showing only changes of commit fc9a0ce177 - Show all commits

View File

@ -22,7 +22,13 @@ namespace DoubleDeckerBus
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
_bus = new DrawingBus(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_bus = new DrawingBus(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
SetData();
Draw();
}
@ -63,9 +69,19 @@ namespace DoubleDeckerBus
private void ButtonÑreateExtra_Click(object sender, EventArgs e)
{
Random rnd = new();
_bus = new DrawingDDB(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialogDop = new();
if (dialogDop.ShowDialog() == DialogResult.OK)
{
dopColor = dialogDop.Color;
}
_bus = new DrawingDDB(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor,
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData();
Draw();

View File

@ -63,7 +63,7 @@ namespace DoubleDeckerBus
DrawingObjectBus bus = new(form.SelectedBus);
if (_mapBusesCollectionGeneric + bus)
if (_mapBusesCollectionGeneric + bus != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapBusesCollectionGeneric.ShowSet();
@ -86,7 +86,7 @@ namespace DoubleDeckerBus
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapBusesCollectionGeneric - pos)
if (_mapBusesCollectionGeneric - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapBusesCollectionGeneric.ShowSet();

View File

@ -28,12 +28,12 @@ namespace DoubleDeckerBus
_map = map;
}
public static bool operator +(MapWithSetBusesGeneric<T, U> map, T bus)
public static int operator +(MapWithSetBusesGeneric<T, U> map, T bus)
{
return map._setBuses.Insert(bus);
}
public static bool operator -(MapWithSetBusesGeneric<T, U> map, int position)
public static T operator -(MapWithSetBusesGeneric<T, U> map, int position)
{
return map._setBuses.Remove(position);
}
@ -98,11 +98,21 @@ namespace DoubleDeckerBus
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
Brush pointColor = new SolidBrush(Color.Orange);
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 + _placeSizeWidth / 2, j * _placeSizeHeight,
i * _placeSizeWidth + _placeSizeWidth / 2, (int)((j * _placeSizeHeight) - (40)));
g.FillPolygon(pointColor, new Point[] {
new Point(i * _placeSizeWidth + _placeSizeWidth / 2, (int)((j * _placeSizeHeight) - (40))),
new Point(i * _placeSizeWidth + _placeSizeWidth / 2 - 10, (int)((j * _placeSizeHeight) - (50))),
new Point(i * _placeSizeWidth + _placeSizeWidth / 2, (int)((j * _placeSizeHeight) - (60))),
new Point(i * _placeSizeWidth + _placeSizeWidth / 2 + 10, (int)((j * _placeSizeHeight) - (50)))
});
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
}
@ -113,7 +123,7 @@ namespace DoubleDeckerBus
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
int currentWidth = 0;
int currentWidth = width - 1;
int currentHeight = 0;
for (int i = 0; i < _setBuses.Count; i++) {
@ -123,14 +133,14 @@ namespace DoubleDeckerBus
_pictureWidth, _pictureHeight);
_setBuses.Get(i)?.DrawingObject(g);
if (currentHeight < height)
currentHeight++;
if (currentWidth > 0)
currentWidth--;
else
{
currentHeight = 0;
currentWidth++;
currentWidth = width - 1;
currentHeight++;
}
if (currentWidth > width) return;
if (currentHeight > height) return;
}
}
}

View File

@ -19,14 +19,14 @@ namespace DoubleDeckerBus
_places = new T[count];
}
public bool Insert(T bus)
public int Insert(T bus)
{
return Insert(bus, 0);
}
public bool Insert(T bus, int position)
public int Insert(T bus, int position)
{
if (position < 0 || position >= _places.Length || BusyPlaces == _places.Length) return false;
if (position < 0 || position >= _places.Length || BusyPlaces == _places.Length) return -1;
BusyPlaces++;
while (_places[position] != null) {
@ -38,14 +38,15 @@ namespace DoubleDeckerBus
}
}
_places[position] = bus;
return true;
return position;
}
public bool Remove(int position)
public T Remove(int position)
{
if (position < 0 || position >= _places.Length) return false;
if (position < 0 || position >= _places.Length) return null;
T savedBus = _places[position];
_places[position] = null;
return true;
return savedBus;
}
public T Get(int position)