From 9a45e3fab973ef3b69419936d1ae859a03d67778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D0=B8=D1=80=20=D0=9D=D1=83=D0=B3=D0=B0?= =?UTF-8?q?=D0=B5=D0=B2?= Date: Tue, 25 Oct 2022 13:43:41 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B0=D0=BD=D0=BD=D0=B0=D1=8F=203?= =?UTF-8?q?=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bus/Bus/DrawingBus.cs | 3 +- Bus/Bus/DrawingSportBus.cs | 9 ++-- Bus/Bus/EntitySportBus.cs | 2 + Bus/Bus/FormBus.cs | 28 +++++++++++-- .../FormMapWithSetDoubleDeckerBus.Designer.cs | 18 +++++++- Bus/Bus/FormMapWithSetDoubleDeckerBus.cs | 32 +++++++++------ Bus/Bus/MapWithSetDoubleDeckerBusGeneric.cs | 41 ++++++++++++++++--- Bus/Bus/SetDoubleDeckerBusGeneric.cs | 33 ++++++++++++--- 8 files changed, 129 insertions(+), 37 deletions(-) diff --git a/Bus/Bus/DrawingBus.cs b/Bus/Bus/DrawingBus.cs index b4a7bb8..f8924a1 100644 --- a/Bus/Bus/DrawingBus.cs +++ b/Bus/Bus/DrawingBus.cs @@ -91,7 +91,8 @@ namespace Bus //кузов Brush br = new SolidBrush(Bus?.BodyColor ?? Color.Black); - g.FillRectangle(br, _startPosX+11, _startPosY+11, 149, 49); + g.FillRectangle(br, _startPosX+ 11, _startPosY + 11, 149, 49); + //колеса Brush brBlack = new SolidBrush(Color.Black); g.FillEllipse(brBlack, _startPosX + 20, _startPosY + 50, 20, 20); diff --git a/Bus/Bus/DrawingSportBus.cs b/Bus/Bus/DrawingSportBus.cs index b1ebefb..aca2b36 100644 --- a/Bus/Bus/DrawingSportBus.cs +++ b/Bus/Bus/DrawingSportBus.cs @@ -26,13 +26,10 @@ namespace Bus if (sportBus.BodyKit) { Brush br = new SolidBrush(Bus?.BodyColor ?? Color.Black); - Brush fireBrush = new SolidBrush(Color.Red); Pen pen1 = new(Color.Black); + g.DrawRectangle(pen1, _startPosX + 20, _startPosY, 150, 50); g.FillRectangle(br, _startPosX + 21, _startPosY+1, 149, 49); - - - } _startPosX += 10; @@ -44,10 +41,10 @@ namespace Bus if (sportBus.Sportline) { Brush brBlue = new SolidBrush(Color.LightBlue); - g.FillRectangle(brBlue, _startPosX + 30, _startPosY + 5, 10, 14); + g.FillRectangle(dopBrush, _startPosX + 30, _startPosY + 5, 10, 14); g.DrawRectangle(pen, _startPosX + 29, _startPosY + 4, 10, 15); - g.FillRectangle(brBlue, _startPosX + 60, _startPosY + 5, 10, 14); + g.FillRectangle(dopBrush, _startPosX + 60, _startPosY + 5, 10, 14); g.DrawRectangle(pen, _startPosX + 59, _startPosY + 4, 10, 15); } diff --git a/Bus/Bus/EntitySportBus.cs b/Bus/Bus/EntitySportBus.cs index cdc78e8..21b2b44 100644 --- a/Bus/Bus/EntitySportBus.cs +++ b/Bus/Bus/EntitySportBus.cs @@ -9,6 +9,7 @@ namespace Bus internal class EntitySportBus : EntityBus { public Color DopColor { get; private set; } + public Color DopColor1 { get; private set; } public bool BodyKit { get; private set; } public bool Wing { get; private set; } public bool Sportline { get; private set; } @@ -17,6 +18,7 @@ namespace Bus base(speed, weight, bodyColor) { DopColor = dopColor; + DopColor1 = bodyColor; BodyKit = bodyKit = true; Wing = wing = true; Sportline = sportline = true; diff --git a/Bus/Bus/FormBus.cs b/Bus/Bus/FormBus.cs index e956c61..b0137a3 100644 --- a/Bus/Bus/FormBus.cs +++ b/Bus/Bus/FormBus.cs @@ -33,7 +33,13 @@ namespace Bus 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(); } @@ -67,10 +73,24 @@ namespace Bus private void ButtonCreateModif_Click(object sender, EventArgs e) { Random rnd = new(); - _bus = new DrawingSportBus(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 DrawingSportBus(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor, Convert.ToBoolean(rnd.Next(0, 1)), Convert.ToBoolean(rnd.Next(0,1)), Convert.ToBoolean(rnd.Next(0,1))); + SetData(); Draw(); } diff --git a/Bus/Bus/FormMapWithSetDoubleDeckerBus.Designer.cs b/Bus/Bus/FormMapWithSetDoubleDeckerBus.Designer.cs index 7a23312..4a7771e 100644 --- a/Bus/Bus/FormMapWithSetDoubleDeckerBus.Designer.cs +++ b/Bus/Bus/FormMapWithSetDoubleDeckerBus.Designer.cs @@ -62,7 +62,7 @@ this.groupBox1.Size = new System.Drawing.Size(250, 450); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; - this.groupBox1.Text = "groupBox1"; + this.groupBox1.Text = "Инструменты"; // // buttonRight // @@ -74,6 +74,7 @@ this.buttonRight.Size = new System.Drawing.Size(40, 40); this.buttonRight.TabIndex = 10; this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); // // buttonDown // @@ -85,6 +86,7 @@ this.buttonDown.Size = new System.Drawing.Size(40, 40); this.buttonDown.TabIndex = 9; this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); // // buttonLeft // @@ -96,6 +98,7 @@ this.buttonLeft.Size = new System.Drawing.Size(40, 40); this.buttonLeft.TabIndex = 8; this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); // // buttonUp // @@ -107,6 +110,7 @@ this.buttonUp.Size = new System.Drawing.Size(40, 40); this.buttonUp.TabIndex = 7; this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); // // buttonShowOnMap // @@ -128,6 +132,13 @@ this.buttonShowStorage.UseVisualStyleBackColor = true; this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click); // + // maskedTextBoxPosition + // + this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 122); + this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + this.maskedTextBoxPosition.Size = new System.Drawing.Size(100, 27); + this.maskedTextBoxPosition.TabIndex = 11; + // // buttonRemoveBus // this.buttonRemoveBus.Location = new System.Drawing.Point(6, 155); @@ -151,6 +162,9 @@ // comboBoxSelectorMap // this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Простая карта", + "Водная карта"}); this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 26); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.comboBoxSelectorMap.Size = new System.Drawing.Size(151, 28); @@ -174,7 +188,7 @@ this.Controls.Add(this.pictureBox); this.Controls.Add(this.groupBox1); this.Name = "FormMapWithSetDoubleDeckerBus"; - this.Text = "FormMapWithSetDoubleDeckerBus"; + this.Text = "Автобус"; this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); diff --git a/Bus/Bus/FormMapWithSetDoubleDeckerBus.cs b/Bus/Bus/FormMapWithSetDoubleDeckerBus.cs index cbd5779..f10d972 100644 --- a/Bus/Bus/FormMapWithSetDoubleDeckerBus.cs +++ b/Bus/Bus/FormMapWithSetDoubleDeckerBus.cs @@ -14,11 +14,16 @@ namespace Bus { private MapWithSetDoubleDeckerBusGeneric _mapBusCollectionGeneric; + //DrawingBus SelectedBus { get; private set; } + public FormMapWithSetDoubleDeckerBus() { InitializeComponent(); - } + AbstractMap map = new SimpleMap(); + _mapBusCollectionGeneric = new MapWithSetDoubleDeckerBusGeneric( + pictureBox.Width, pictureBox.Height, map); + } private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) { @@ -28,6 +33,9 @@ namespace Bus case "Простая карта": map = new SimpleMap(); break; + case "Водная карта": + map = new MyMap(); + break; } if(map != null) @@ -39,8 +47,6 @@ namespace Bus { _mapBusCollectionGeneric = null; } - - } private void ButtonAddBus_Click(object sender, EventArgs e) @@ -52,8 +58,15 @@ namespace Bus FormBus form = new(); if (form.ShowDialog() == DialogResult.OK) { + if (form.SelectedBus == null) + { + MessageBox.Show("Сначала создайте объект"); + return; + } + DrawingObjectBus bus = new(form.SelectedBus); - if (_mapBusCollectionGeneric + bus) + + if (_mapBusCollectionGeneric + bus != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _mapBusCollectionGeneric.ShowSet(); @@ -72,12 +85,12 @@ namespace Bus return; } if (MessageBox.Show("Удалить объект?", "Удаление", - MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapBusCollectionGeneric - pos) + if (_mapBusCollectionGeneric - pos != null) { MessageBox.Show("Объект удален"); pictureBox.Image = _mapBusCollectionGeneric.ShowSet(); @@ -86,13 +99,8 @@ namespace Bus { MessageBox.Show("Не удалось удалить объект"); } - } - - - - private void ButtonShowStorage_Click(object sender, EventArgs e) { if (_mapBusCollectionGeneric == null) @@ -136,6 +144,6 @@ namespace Bus break; } pictureBox.Image = _mapBusCollectionGeneric.MoveObject(dir); - } + } } } diff --git a/Bus/Bus/MapWithSetDoubleDeckerBusGeneric.cs b/Bus/Bus/MapWithSetDoubleDeckerBusGeneric.cs index ab07a4f..83cb173 100644 --- a/Bus/Bus/MapWithSetDoubleDeckerBusGeneric.cs +++ b/Bus/Bus/MapWithSetDoubleDeckerBusGeneric.cs @@ -27,12 +27,12 @@ namespace Bus _map = map; } - public static bool operator +(MapWithSetDoubleDeckerBusGeneric map, T bus) + public static int operator +(MapWithSetDoubleDeckerBusGeneric map, T bus) { return map._setBus.Insert(bus); } - public static bool operator -(MapWithSetDoubleDeckerBusGeneric map, int position) + public static T operator -(MapWithSetDoubleDeckerBusGeneric map, int position) { return map._setBus.Remove(position); } @@ -97,20 +97,49 @@ namespace Bus private void DrawBackground(Graphics g) { Pen pen = new(Color.Black, 3); - for (int i = 0; i < _pictureWidth/_placeSizeWidth; i++) + Brush pointColor = new SolidBrush(Color.Orange); + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) { - for (int j = 0; j < _pictureHeight/_placeSizeHeight; j++) + for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) { - // TODO + 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); } } private void DrawBus(Graphics g) { - for (int i = 0; i<_setBus.Count; i++) + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + + int currentWidth = width - 1; + int currentHeight = 0; + + for (int i = 0; i < _setBus.Count; i++) { + _setBus.Get(i)?.SetObject(currentWidth * _placeSizeWidth, + currentHeight * _placeSizeHeight, + _pictureWidth, _pictureHeight); _setBus.Get(i)?.DrawingObject(g); + + if (currentWidth > 0) + currentWidth--; + else + { + currentWidth = width - 1; + currentHeight++; + } + if (currentHeight > height) return; } } } diff --git a/Bus/Bus/SetDoubleDeckerBusGeneric.cs b/Bus/Bus/SetDoubleDeckerBusGeneric.cs index 7d06c08..70c05f7 100644 --- a/Bus/Bus/SetDoubleDeckerBusGeneric.cs +++ b/Bus/Bus/SetDoubleDeckerBusGeneric.cs @@ -11,25 +11,46 @@ namespace Bus { private readonly T[] _places; public int Count => _places.Length; + private int BusPlaces = 0; + public SetDoubleDeckerBusGeneric(int count) { _places = new T[count]; } - public bool Insert(T bus) + public int Insert(T bus) { - return true; + return Insert(bus, 0); } - public bool Insert(T bus, int position) + public int Insert(T bus, int position) { + if (position < 0 || position >= _places.Length || BusPlaces == _places.Length) + { + return -1; + } + BusPlaces++; + 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; + return position; } - public bool Remove(int position) + public T Remove(int position) { - return true; + if (position < 0 || position >= _places.Length) return null; + T savedBus = _places[position]; + _places[position] = null; + return savedBus; } public T Get(int position)