diff --git a/AccordionBus/AccordionBus/DrawningAccordionBus.cs b/AccordionBus/AccordionBus/DrawningAccordionBus.cs index 30e7e5f..d862537 100644 --- a/AccordionBus/AccordionBus/DrawningAccordionBus.cs +++ b/AccordionBus/AccordionBus/DrawningAccordionBus.cs @@ -50,11 +50,10 @@ namespace AccordionBus /// /// public void Init(int speed, double weight, Color bodyColor, Color - additionalColor, bool threeDoors, bool fourDoors, bool fiveDoors) + additionalColor, bool onePart, bool fiveDoors) { EntityAccordionBus = new EntityAccordionBus(); - EntityAccordionBus.Init(speed, weight, bodyColor, additionalColor, - threeDoors, fourDoors, fiveDoors); + EntityAccordionBus.Init(speed, weight, bodyColor, additionalColor, onePart, fiveDoors); _pictureWeight = null; _pictureHeight = null; _startPosX = null; @@ -73,12 +72,20 @@ namespace AccordionBus return false; } - else + _pictureWeight = weight; + _pictureHeight = height; + + if (_startPosX.HasValue && _startPosX.Value + _drawningBusWeight > _pictureWeight) { - _pictureWeight = weight; - _pictureHeight = height; - return true; + _startPosX -= _startPosX.Value + _drawningBusWeight - _pictureWeight; } + else if (_startPosY.HasValue && _startPosY.Value + _drawningBusHeight > _pictureHeight) + { + _startPosY -= _startPosY.Value + _drawningBusHeight - _pictureHeight; + } + return true; + + } /// /// Установка позиции @@ -94,15 +101,27 @@ namespace AccordionBus if (x + _drawningBusWeight > _pictureWeight) { - x -= (int)_pictureWeight - x - _drawningBusWeight; + _startPosX = x - ( x + _drawningBusWeight - _pictureWeight); } - else if (y + _drawningBusHeight > _pictureHeight) + else if (x < 0) { - y -= (int)_pictureHeight - y - _drawningBusHeight; + _startPosX = 0; } else { _startPosX = x; + } + + if (y + _drawningBusHeight > _pictureHeight) + { + _startPosY = y - ( y + _drawningBusHeight - _pictureHeight); + } + else if (y < 0) + { + _startPosY = 0; + } + else + { _startPosY = y; } } @@ -127,6 +146,10 @@ namespace AccordionBus { _startPosX -= (int)EntityAccordionBus.Step; } + else + { + _startPosX = 0; + } return true; case DirectionType.Right: @@ -134,6 +157,10 @@ namespace AccordionBus { _startPosX += (int)EntityAccordionBus.Step; } + else + { + _startPosX = _pictureWeight - _drawningBusWeight; + } return true; case DirectionType.Up: @@ -141,6 +168,10 @@ namespace AccordionBus { _startPosY -= (int)EntityAccordionBus.Step; } + else + { + _startPosY = 0; + } return true; case DirectionType.Down: @@ -148,6 +179,10 @@ namespace AccordionBus { _startPosY += (int)EntityAccordionBus.Step; } + else + { + _startPosY = _pictureHeight - _drawningBusHeight; + } return true; default: @@ -172,18 +207,12 @@ namespace AccordionBus //корпус Brush br = new SolidBrush(EntityAccordionBus.BodyColor); g.FillRectangle(br, _startPosX.Value, _startPosY.Value, 60, 15); - g.FillRectangle(br, _startPosX.Value + 70, _startPosY.Value, 60, 15); g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value, 60, 15); - g.DrawRectangle(pen, _startPosX.Value + 70, _startPosY.Value, 60, 15); //колёса Brush brWhite = new SolidBrush(Color.White); g.FillEllipse(brWhite, _startPosX.Value + 5, _startPosY.Value + 10, 10, 10); g.FillEllipse(brWhite, _startPosX.Value + 40, _startPosY.Value + 10, 10, 10); - g.FillEllipse(brWhite, _startPosX.Value + 75, _startPosY.Value + 10, 10, 10); - g.FillEllipse(brWhite, _startPosX.Value + 110, _startPosY.Value + 10, 10, 10); - g.DrawEllipse(pen, _startPosX.Value + 110, _startPosY.Value + 10, 10, 10); - g.DrawEllipse(pen, _startPosX.Value + 75, _startPosY.Value + 10, 10, 10); g.DrawEllipse(pen, _startPosX.Value + 40, _startPosY.Value + 10, 10, 10); g.DrawEllipse(pen, _startPosX.Value + 5, _startPosY.Value + 10, 10, 10); @@ -197,49 +226,60 @@ namespace AccordionBus g.DrawRectangle(pen, _startPosX.Value + 32, _startPosY.Value + 3, 5, 5); g.FillRectangle(brBlue, _startPosX.Value + 42, _startPosY.Value + 3, 5, 5); g.DrawRectangle(pen, _startPosX.Value + 42, _startPosY.Value + 3, 5, 5); - g.FillRectangle(brBlue, _startPosX.Value + 72, _startPosY.Value + 3, 5, 5); - g.DrawRectangle(pen, _startPosX.Value + 72, _startPosY.Value + 3, 5, 5); - g.FillRectangle(brBlue, _startPosX.Value + 82, _startPosY.Value + 3, 5, 5); - g.DrawRectangle(pen, _startPosX.Value + 82, _startPosY.Value + 3, 5, 5); - g.FillRectangle(brBlue, _startPosX.Value + 92, _startPosY.Value + 3, 5, 5); - g.DrawRectangle(pen, _startPosX.Value + 92, _startPosY.Value + 3, 5, 5); - g.FillRectangle(brBlue, _startPosX.Value + 102, _startPosY.Value + 3, 5, 5); - g.DrawRectangle(pen, _startPosX.Value + 102, _startPosY.Value + 3, 5, 5); - g.FillRectangle(brBlue, _startPosX.Value + 112, _startPosY.Value + 3, 5, 5); - g.DrawRectangle(pen, _startPosX.Value + 112, _startPosY.Value + 3, 5, 5); - //гормошка - g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value, _startPosX.Value + 62, _startPosY.Value + 3); - g.DrawLine(pen, _startPosX.Value + 62, _startPosY.Value + 3, _startPosX.Value + 65, _startPosY.Value); - g.DrawLine(pen, _startPosX.Value + 65, _startPosY.Value, _startPosX.Value + 67, _startPosY.Value + 3); - g.DrawLine(pen, _startPosX.Value + 67, _startPosY.Value + 3, _startPosX.Value + 70, _startPosY.Value); - g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 15, _startPosX.Value + 62, _startPosY.Value + 12); - g.DrawLine(pen, _startPosX.Value + 62, _startPosY.Value + 12, _startPosX.Value + 65, _startPosY.Value + 15); - g.DrawLine(pen, _startPosX.Value + 65, _startPosY.Value + 15, _startPosX.Value + 67, _startPosY.Value + 12); - g.DrawLine(pen, _startPosX.Value + 67, _startPosY.Value + 12, _startPosX.Value + 70, _startPosY.Value + 15); - g.DrawLine(pen, _startPosX.Value + 62, _startPosY.Value + 3, _startPosX.Value + 62, _startPosY.Value + 12); - g.DrawLine(pen, _startPosX.Value + 67, _startPosY.Value + 3, _startPosX.Value + 67, _startPosY.Value + 12); - g.DrawLine(pen, _startPosX.Value + 65, _startPosY.Value, _startPosX.Value + 65, _startPosY.Value + 15); - - //двери + //дверь g.FillRectangle(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 5, 5, 10); g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 5, 5, 10); - g.FillRectangle(additionalBrush, _startPosX.Value + 123, _startPosY.Value + 5, 5, 10); - g.DrawRectangle(pen, _startPosX.Value + 123, _startPosY.Value + 5, 5, 10); - if (EntityAccordionBus.ThreeDoors) + + if (!EntityAccordionBus.OnePart) { - g.FillRectangle(additionalBrush, _startPosX.Value + 53, _startPosY.Value + 5, 5, 10); - g.DrawRectangle(pen, _startPosX.Value + 53, _startPosY.Value + 5, 5, 10); - } - if (EntityAccordionBus.FourDoors) - { - g.FillRectangle(additionalBrush, _startPosX.Value + 87, _startPosY.Value + 9, 21, 5); - g.DrawRectangle(pen, _startPosX.Value + 87, _startPosY.Value + 9, 21, 5); - } - if (EntityAccordionBus.FiveDoors) - { - g.FillRectangle(additionalBrush, _startPosX.Value + 27, _startPosY.Value + 9, 11, 5); - g.DrawRectangle(pen, _startPosX.Value + 27, _startPosY.Value + 9, 11, 5); + //корпус + g.FillRectangle(br, _startPosX.Value + 70, _startPosY.Value, 60, 15); + g.DrawRectangle(pen, _startPosX.Value + 70, _startPosY.Value, 60, 15); + + //колёса + g.FillEllipse(brWhite, _startPosX.Value + 75, _startPosY.Value + 10, 10, 10); + g.FillEllipse(brWhite, _startPosX.Value + 110, _startPosY.Value + 10, 10, 10); + g.DrawEllipse(pen, _startPosX.Value + 110, _startPosY.Value + 10, 10, 10); + g.DrawEllipse(pen, _startPosX.Value + 75, _startPosY.Value + 10, 10, 10); + + //стёкла + g.FillRectangle(brBlue, _startPosX.Value + 72, _startPosY.Value + 3, 5, 5); + g.DrawRectangle(pen, _startPosX.Value + 72, _startPosY.Value + 3, 5, 5); + g.FillRectangle(brBlue, _startPosX.Value + 82, _startPosY.Value + 3, 5, 5); + g.DrawRectangle(pen, _startPosX.Value + 82, _startPosY.Value + 3, 5, 5); + g.FillRectangle(brBlue, _startPosX.Value + 92, _startPosY.Value + 3, 5, 5); + g.DrawRectangle(pen, _startPosX.Value + 92, _startPosY.Value + 3, 5, 5); + g.FillRectangle(brBlue, _startPosX.Value + 102, _startPosY.Value + 3, 5, 5); + g.DrawRectangle(pen, _startPosX.Value + 102, _startPosY.Value + 3, 5, 5); + g.FillRectangle(brBlue, _startPosX.Value + 112, _startPosY.Value + 3, 5, 5); + g.DrawRectangle(pen, _startPosX.Value + 112, _startPosY.Value + 3, 5, 5); + + //гормошка + g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value, _startPosX.Value + 62, _startPosY.Value + 3); + g.DrawLine(pen, _startPosX.Value + 62, _startPosY.Value + 3, _startPosX.Value + 65, _startPosY.Value); + g.DrawLine(pen, _startPosX.Value + 65, _startPosY.Value, _startPosX.Value + 67, _startPosY.Value + 3); + g.DrawLine(pen, _startPosX.Value + 67, _startPosY.Value + 3, _startPosX.Value + 70, _startPosY.Value); + g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 15, _startPosX.Value + 62, _startPosY.Value + 12); + g.DrawLine(pen, _startPosX.Value + 62, _startPosY.Value + 12, _startPosX.Value + 65, _startPosY.Value + 15); + g.DrawLine(pen, _startPosX.Value + 65, _startPosY.Value + 15, _startPosX.Value + 67, _startPosY.Value + 12); + g.DrawLine(pen, _startPosX.Value + 67, _startPosY.Value + 12, _startPosX.Value + 70, _startPosY.Value + 15); + g.DrawLine(pen, _startPosX.Value + 62, _startPosY.Value + 3, _startPosX.Value + 62, _startPosY.Value + 12); + g.DrawLine(pen, _startPosX.Value + 67, _startPosY.Value + 3, _startPosX.Value + 67, _startPosY.Value + 12); + g.DrawLine(pen, _startPosX.Value + 65, _startPosY.Value, _startPosX.Value + 65, _startPosY.Value + 15); + + //двери + g.FillRectangle(additionalBrush, _startPosX.Value + 123, _startPosY.Value + 5, 5, 10); + g.DrawRectangle(pen, _startPosX.Value + 123, _startPosY.Value + 5, 5, 10); + if (EntityAccordionBus.FiveDoors) + { + g.FillRectangle(additionalBrush, _startPosX.Value + 87, _startPosY.Value + 9, 21, 5); + g.DrawRectangle(pen, _startPosX.Value + 87, _startPosY.Value + 9, 21, 5); + g.FillRectangle(additionalBrush, _startPosX.Value + 53, _startPosY.Value + 5, 5, 10); + g.DrawRectangle(pen, _startPosX.Value + 53, _startPosY.Value + 5, 5, 10); + g.FillRectangle(additionalBrush, _startPosX.Value + 27, _startPosY.Value + 9, 11, 5); + g.DrawRectangle(pen, _startPosX.Value + 27, _startPosY.Value + 9, 11, 5); + } } } } diff --git a/AccordionBus/AccordionBus/EntityAccordionBus.cs b/AccordionBus/AccordionBus/EntityAccordionBus.cs index fabb4c2..b6c06a7 100644 --- a/AccordionBus/AccordionBus/EntityAccordionBus.cs +++ b/AccordionBus/AccordionBus/EntityAccordionBus.cs @@ -28,13 +28,9 @@ namespace AccordionBus /// public Color AdditionalColor { get; set; } /// - /// 3 двери + /// Одна часть /// - public bool ThreeDoors { get; set; } - /// - /// 4 двери - /// - public bool FourDoors { get; set; } + public bool OnePart { get; set; } /// /// 5 дверей /// @@ -54,14 +50,13 @@ namespace AccordionBus /// 4 двери /// 5 дверей public void Init(int speed, double weight, Color bodyColor, Color - additionalColor, bool threeDoors, bool fourDoors, bool fiveDoors) + additionalColor, bool onePart, bool fiveDoors) { Speed = speed; Weight = weight; BodyColor = bodyColor; AdditionalColor = additionalColor; - ThreeDoors = threeDoors; - FourDoors = fourDoors; + OnePart = onePart; FiveDoors = fiveDoors; } } diff --git a/AccordionBus/AccordionBus/FormAccordionBus.cs b/AccordionBus/AccordionBus/FormAccordionBus.cs index 8716c21..99ee87b 100644 --- a/AccordionBus/AccordionBus/FormAccordionBus.cs +++ b/AccordionBus/AccordionBus/FormAccordionBus.cs @@ -36,8 +36,7 @@ namespace AccordionBus _drawningAccordionBus = new DrawningAccordionBus(); _drawningAccordionBus.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)), - Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)), - Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); + Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); _drawningAccordionBus.SetPictureSize(pictureBoxAccordionBus.Width, pictureBoxAccordionBus.Height); _drawningAccordionBus.SetPosition(random.Next(50, 300), random.Next(50, 300)); Draw();