Дописаны проверки

This commit is contained in:
a.puchkina 2023-09-26 12:36:23 +04:00
parent 04aff8ea2a
commit b7dcc0892e
2 changed files with 20 additions and 20 deletions

View File

@ -52,12 +52,12 @@ namespace AirplaneWithRadar
Random random = new();
_drawningAirplane = new DrawningAirplane();
_drawningAirplane.Init(random.Next(100, 300),
random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxAirplane.Width, pictureBoxAirplane.Height);
_drawningAirplane.SetPosition(random.Next(10, 100), random.Next(10, 100));
random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxAirplane.Width, pictureBoxAirplane.Height);
_drawningAirplane.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
@ -89,9 +89,6 @@ namespace AirplaneWithRadar
break;
}
Draw();
}
}
}

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using System.Threading.Tasks;
@ -54,9 +55,12 @@ namespace AirplaneWithRadar
public bool Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool radar, bool tank, bool pin, int width, int height)
{
// TODO: Продумать проверки
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth < _airplaneWidth || _pictureHeight < _airplaneHeight)
{
return false;
}
EntityAirplaneWithRadar = new EntityAirplaneWithRadar();
EntityAirplaneWithRadar.Init(speed, weight, bodyColor, additionalColor, radar, tank, pin);
return true;
@ -68,9 +72,8 @@ namespace AirplaneWithRadar
/// <param name="y">Координата Y</param>
public void SetPosition(int x, int y)
{
// TODO: Изменение x, y
_startPosX = x;
_startPosY = y;
_startPosX = Math.Min(x, _pictureWidth - _airplaneWidth);
_startPosY = Math.Min(y, _pictureHeight - _airplaneHeight);
}
/// <summary>
/// Изменение направления перемещения
@ -127,6 +130,7 @@ namespace AirplaneWithRadar
Pen penBlack = new(Color.Black);
Brush additionalBrush = new SolidBrush(EntityAirplaneWithRadar.AdditionalColor);
Brush bodyBrush = new SolidBrush(EntityAirplaneWithRadar.BodyColor);
// радар
if (EntityAirplaneWithRadar.Radar)
{
@ -134,7 +138,6 @@ namespace AirplaneWithRadar
g.DrawEllipse(penBlack, _startPosX + 65, _startPosY + 25, 50, 10);
g.FillRectangle(additionalBrush, _startPosX + 85, _startPosY + 35, 10, 5);
g.DrawRectangle(penBlack, _startPosX + 85, _startPosY + 35, 10, 5);
}
//фюзеляж
g.FillRectangle(bodyBrush, _startPosX + 4, _startPosY + 40, 150, 30);
@ -164,13 +167,13 @@ namespace AirplaneWithRadar
//кабина
Brush brLightBlue = new SolidBrush(Color.LightBlue);
Pen penBlue = new Pen(Color.CadetBlue);
g.FillPolygon(additionalBrush, new Point[] { new Point(_startPosX + 150, _startPosY + 55), new Point(_startPosX + 190, _startPosY + 55), new Point(_startPosX + 150, _startPosY + 75) });
g.FillPolygon(brLightBlue, new Point[] { new Point(_startPosX + 150, _startPosY + 55), new Point(_startPosX + 150, _startPosY + 35), new Point(_startPosX + 190, _startPosY + 55) });
g.DrawLine(penBlack, new Point(_startPosX + 150, _startPosY + 55), new Point(_startPosX + 150, _startPosY + 35));
g.DrawLine(penBlack, new Point(_startPosX + 150, _startPosY + 35), new Point(_startPosX + 190, _startPosY + 55));
g.FillPolygon(additionalBrush, new Point[] { new Point(_startPosX + 150, _startPosY + 55), new Point(_startPosX + 190, _startPosY + 55), new Point(_startPosX + 150, _startPosY + 72) });
g.FillPolygon(brLightBlue, new Point[] { new Point(_startPosX + 150, _startPosY + 55), new Point(_startPosX + 150, _startPosY + 38), new Point(_startPosX + 190, _startPosY + 55) });
g.DrawLine(penBlack, new Point(_startPosX + 150, _startPosY + 55), new Point(_startPosX + 150, _startPosY + 38));
g.DrawLine(penBlack, new Point(_startPosX + 150, _startPosY + 38), new Point(_startPosX + 190, _startPosY + 55));
g.DrawLine(penBlue, new Point(_startPosX + 190, _startPosY + 55), new Point(_startPosX + 150, _startPosY + 55));
g.DrawLine(penBlack, new Point(_startPosX + 150, _startPosY + 75), new Point(_startPosX + 150, _startPosY + 55));
g.DrawLine(penBlack, new Point(_startPosX + 150, _startPosY + 75), new Point(_startPosX + 190, _startPosY + 55));
g.DrawLine(penBlack, new Point(_startPosX + 150, _startPosY + 72), new Point(_startPosX + 150, _startPosY + 55));
g.DrawLine(penBlack, new Point(_startPosX + 150, _startPosY + 72), new Point(_startPosX + 190, _startPosY + 55));
// Штырь
if (EntityAirplaneWithRadar.Pin)