From fc9a0ce177d66cf3606ab10d72845d6ebd646175 Mon Sep 17 00:00:00 2001 From: shadowik Date: Tue, 4 Oct 2022 06:49:55 +0400 Subject: [PATCH] Fix --- DoubleDeckerBus/DoubleDeckerBus/FormBus.cs | 24 +++++++++++++--- .../DoubleDeckerBus/FormMapWithSetBuses.cs | 4 +-- .../DoubleDeckerBus/MapWithSetBusesGeneric.cs | 28 +++++++++++++------ .../DoubleDeckerBus/SetBusesGeneric.cs | 15 +++++----- 4 files changed, 49 insertions(+), 22 deletions(-) diff --git a/DoubleDeckerBus/DoubleDeckerBus/FormBus.cs b/DoubleDeckerBus/DoubleDeckerBus/FormBus.cs index 8359977..70dc27b 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/FormBus.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/FormBus.cs @@ -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(); diff --git a/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.cs b/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.cs index 065d4ca..1d5818d 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.cs @@ -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(); diff --git a/DoubleDeckerBus/DoubleDeckerBus/MapWithSetBusesGeneric.cs b/DoubleDeckerBus/DoubleDeckerBus/MapWithSetBusesGeneric.cs index eb7aff9..39696a7 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/MapWithSetBusesGeneric.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/MapWithSetBusesGeneric.cs @@ -28,12 +28,12 @@ namespace DoubleDeckerBus _map = map; } - public static bool operator +(MapWithSetBusesGeneric map, T bus) + public static int operator +(MapWithSetBusesGeneric map, T bus) { return map._setBuses.Insert(bus); } - public static bool operator -(MapWithSetBusesGeneric map, int position) + public static T operator -(MapWithSetBusesGeneric 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; } } } diff --git a/DoubleDeckerBus/DoubleDeckerBus/SetBusesGeneric.cs b/DoubleDeckerBus/DoubleDeckerBus/SetBusesGeneric.cs index 86b939c..9bcd653 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/SetBusesGeneric.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/SetBusesGeneric.cs @@ -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)