diff --git a/Bus/Bus/AbstractMap.cs b/Bus/Bus/AbstractMap.cs index e34b7e1..3e4ceb3 100644 --- a/Bus/Bus/AbstractMap.cs +++ b/Bus/Bus/AbstractMap.cs @@ -32,37 +32,61 @@ namespace Bus } - public Bitmap MoveObject(Direction direction) + public bool CheckBarriers(float Left, float Right, float Top, float Bottom) { - // proverka - _drawingObject.MoveObject(direction); + int startX = (int)(Left / _size_x); + int startY = (int)(Right / _size_y); + int endX = (int)(Top / _size_x); + int endY = (int)(Bottom / _size_y); - bool collision = CheckCollision(); - - if (collision) + for (int i = startX; i <= endX; i++) { - switch (direction) + for (int j = startY; j <= endY; j++) { - case Direction.Left: - _drawingObject.MoveObject(Direction.Right); - break; - case Direction.Right: - _drawingObject.MoveObject(Direction.Left); - break; - case Direction.Up: - _drawingObject.MoveObject(Direction.Down); - break; - case Direction.Down: - _drawingObject.MoveObject(Direction.Up); - break; + if (_map[i, j] == _barrier) + { + return true; + } } } + return false; + } + public Bitmap MoveObject(Direction direction) + { + + _drawingObject.MoveObject(direction); + (float Left, float Right, float Top, float Bottom) = _drawingObject.GetCurrentPosition(); + bool isTrue = true; + bool collision = CheckCollision(); + if (CheckBarriers(Left, Right, Top, Bottom)) + { + _drawingObject.MoveObject(MoveObjectBack(direction)); + } return DrawMapWithObject(); + + + + + } - + private Direction MoveObjectBack(Direction direction) + { + switch (direction) + { + case Direction.Up: + return Direction.Down; + case Direction.Down: + return Direction.Up; + case Direction.Left: + return Direction.Right; + case Direction.Right: + return Direction.Left; + } + return Direction.None; + } private bool SetObjectOnMap() @@ -71,10 +95,10 @@ namespace Bus { return false; } - int x = _random.Next(0, 10); - int y = _random.Next(0, 10); + int x = _random.Next(0, 100); + int y = _random.Next(0, 100); _drawingObject.SetObject(x, y, _width, _height); - //////////////////////////////// proverka + if (!CheckBarriers(0, 0, 0, 0)) return false; return true; } diff --git a/Bus/Bus/DrawingSportBus.cs b/Bus/Bus/DrawingSportBus.cs index 7d20d4c..b1ebefb 100644 --- a/Bus/Bus/DrawingSportBus.cs +++ b/Bus/Bus/DrawingSportBus.cs @@ -25,57 +25,40 @@ namespace Bus if (sportBus.BodyKit) { - - - g.DrawRectangle(pen, _startPosX + 30, _startPosY + 20, 10, 20); - Brush brBlack = new SolidBrush(Color.Black); - g.FillRectangle(brBlack, _startPosX + 30, _startPosY + 20, 10, 20); + 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); + - Brush brBlue = new SolidBrush(Color.Blue); - g.FillEllipse(brBlue, _startPosX + 10, _startPosY + 15, 10, 15); - g.FillEllipse(brBlue, _startPosX + 50, _startPosY + 15, 10, 15); - g.FillEllipse(brBlue, _startPosX + 70, _startPosY + 15, 10, 15); - g.FillEllipse(brBlue, _startPosX + 90, _startPosY + 15, 10, 15); } _startPosX += 10; - _startPosY += 5; + _startPosY += 15; base.DrawTransport(g); _startPosX -= 10; - _startPosY -= 5; + _startPosY -= 15; if (sportBus.Sportline) { - g.DrawRectangle(pen, _startPosX + 30, _startPosY + 20, 10, 20); - Brush brBlack = new SolidBrush(Color.Black); - g.FillRectangle(brBlack, _startPosX + 30, _startPosY + 20, 10, 20); + Brush brBlue = new SolidBrush(Color.LightBlue); + g.FillRectangle(brBlue, _startPosX + 30, _startPosY + 5, 10, 14); + g.DrawRectangle(pen, _startPosX + 29, _startPosY + 4, 10, 15); - - Brush brBlue = new SolidBrush(Color.Blue); - g.FillEllipse(brBlue, _startPosX + 10, _startPosY + 15, 10, 15); - g.FillEllipse(brBlue, _startPosX + 50, _startPosY + 15, 10, 15); - g.FillEllipse(brBlue, _startPosX + 70, _startPosY + 15, 10, 15); - g.FillEllipse(brBlue, _startPosX + 90, _startPosY + 15, 10, 15); + g.FillRectangle(brBlue, _startPosX + 60, _startPosY + 5, 10, 14); + g.DrawRectangle(pen, _startPosX + 59, _startPosY + 4, 10, 15); } if (sportBus.Wing) { - g.DrawRectangle(pen, _startPosX + 30, _startPosY + 20, 10, 20); - Brush brBlack = new SolidBrush(Color.Black); - g.FillRectangle(brBlack, _startPosX + 30, _startPosY + 20, 10, 20); + g.DrawRectangle(pen, _startPosX + 112, _startPosY + 7, 6,50); + g.DrawRectangle(pen, _startPosX + 112, _startPosY + 17, 6, 40); + g.DrawRectangle(pen, _startPosX + 112, _startPosY + 27, 6, 10); + g.DrawRectangle(pen, _startPosX + 112, _startPosY + 37, 6, 10); - - Brush brBlue = new SolidBrush(Color.Blue); - g.FillEllipse(brBlue, _startPosX + 10, _startPosY + 15, 10, 15); - g.FillEllipse(brBlue, _startPosX + 50, _startPosY + 15, 10, 15); - g.FillEllipse(brBlue, _startPosX + 70, _startPosY + 15, 10, 15); - g.FillEllipse(brBlue, _startPosX + 90, _startPosY + 15, 10, 15); } - - - - } } } diff --git a/Bus/Bus/EntitySportBus.cs b/Bus/Bus/EntitySportBus.cs index 8e06a6a..cdc78e8 100644 --- a/Bus/Bus/EntitySportBus.cs +++ b/Bus/Bus/EntitySportBus.cs @@ -17,9 +17,9 @@ namespace Bus base(speed, weight, bodyColor) { DopColor = dopColor; - BodyKit = bodyKit; - Wing = wing; - Sportline = sportline; + BodyKit = bodyKit = true; + Wing = wing = true; + Sportline = sportline = true; } } } diff --git a/Bus/Bus/FormBus.cs b/Bus/Bus/FormBus.cs index 3d0f408..6a98108 100644 --- a/Bus/Bus/FormBus.cs +++ b/Bus/Bus/FormBus.cs @@ -21,7 +21,7 @@ namespace Bus private void SetData() { Random rnd = new(); - _bus.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxBus.Width, pictureBoxBus.Height); + _bus.SetPosition(rnd.Next(20, 100), rnd.Next(20, 100), pictureBoxBus.Width, pictureBoxBus.Height); toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_bus.Bus?.Speed}"; toolStripStatusLabelWeight.Text = $"Âåñ: {_bus.Bus?.Weight}"; toolStripStatusLabelBodyColor.Text = $"Öâåò: {_bus.Bus?.BodyColor.Name}"; diff --git a/Bus/Bus/FormMap.Designer.cs b/Bus/Bus/FormMap.Designer.cs index 499aed8..5e989ab 100644 --- a/Bus/Bus/FormMap.Designer.cs +++ b/Bus/Bus/FormMap.Designer.cs @@ -159,7 +159,8 @@ this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxSelectorMap.FormattingEnabled = true; this.comboBoxSelectorMap.Items.AddRange(new object[] { - "ПроÑÑ‚Ð°Ñ ÐºÐ°Ñ€Ñ‚Ð°"}); + "ПроÑÑ‚Ð°Ñ ÐºÐ°Ñ€Ñ‚Ð°", + "Ðще одна карта"}); this.comboBoxSelectorMap.Location = new System.Drawing.Point(9, 8); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.comboBoxSelectorMap.Size = new System.Drawing.Size(151, 28); diff --git a/Bus/Bus/FormMap.cs b/Bus/Bus/FormMap.cs index 9bbfb0a..f1ee503 100644 --- a/Bus/Bus/FormMap.cs +++ b/Bus/Bus/FormMap.cs @@ -81,6 +81,9 @@ namespace Bus case "ПроÑÑ‚Ð°Ñ ÐºÐ°Ñ€Ñ‚Ð°": _abstractMap = new SimpleMap(); break; + case "Ðще одна карта": + _abstractMap = new MyMap(); + break; } } } diff --git a/Bus/Bus/MyMap.cs b/Bus/Bus/MyMap.cs new file mode 100644 index 0000000..f0f4f79 --- /dev/null +++ b/Bus/Bus/MyMap.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bus +{ + internal class MyMap : AbstractMap + { + + private readonly Brush barrierColor = new SolidBrush(Color.White); + private readonly Brush roadColor = new SolidBrush(Color.SkyBlue); + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y); + + } + protected override void DrawRoadPart(Graphics g, int i, int j) + { + g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y); + } + protected override void GenerateMap() + { + _map = new int[100, 100]; + _size_x = (float)_width / _map.GetLength(0); + _size_y = (float)_height / _map.GetLength(1); + int counter = 0; + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + _map[i, j] = _freeRoad; + } + } + while (counter < 25) + { + int x = _random.Next(0, 100); + int y = _random.Next(0, 100); + if (_map[x, y] == _freeRoad) + { + _map[x, y] = _barrier; + counter++; + } + } + } + + } +}