PIbd-12 Timochkin V.V. LabWork01 Simple #1
@ -35,7 +35,7 @@ public class DrawingAntiAircraftGun
|
||||
/// <summary>
|
||||
/// Длина прорисовки зенитки
|
||||
/// </summary>
|
||||
private readonly int _drawingAntiAircraftGunWidth = 110;
|
||||
private readonly int _drawingAntiAircraftGunWidth = 100;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки зенитки
|
||||
@ -70,8 +70,8 @@ public class DrawingAntiAircraftGun
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
||||
if (_drawingAntiAircraftGunHeight > height || _drawingAntiAircraftGunWidth > width) return false;
|
||||
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
return true;
|
||||
@ -89,9 +89,9 @@ public class DrawingAntiAircraftGun
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
_startPosX = x;
|
||||
if (x < 0 || y < 0 || x + _drawingAntiAircraftGunWidth > _pictureWidth || y + _drawingAntiAircraftGunHeight > _pictureHeight) return;
|
||||
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ public class DrawingAntiAircraftGun
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityAntiAircraftGun == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -151,61 +151,61 @@ public class DrawingAntiAircraftGun
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityAntiAircraftGun == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(EntityAntiAircraftGun.AdditionalColor);
|
||||
Pen pen = new(EntityAntiAircraftGun.BodyColor);
|
||||
Pen additionalPen = new(EntityAntiAircraftGun.AdditionalColor);
|
||||
|
||||
|
||||
|
||||
//зенитные орудия
|
||||
if (EntityAntiAircraftGun.AAG)
|
||||
{
|
||||
g.DrawLine(pen, _startPosX.Value + 90, _startPosY.Value + 15, _startPosX.Value + 40, _startPosY.Value + 3);
|
||||
g.DrawLine(pen, _startPosX.Value + 88, _startPosY.Value + 13, _startPosX.Value + 38, _startPosY.Value + 1);
|
||||
g.DrawLine(pen, _startPosX.Value + 89, _startPosY.Value + 14, _startPosX.Value + 39, _startPosY.Value + 2);
|
||||
|
||||
g.DrawLine(additionalPen, _startPosX.Value + 85, _startPosY.Value + 15, _startPosX.Value + 40, _startPosY.Value + 3);
|
||||
g.DrawLine(additionalPen, _startPosX.Value + 83, _startPosY.Value + 13, _startPosX.Value + 38, _startPosY.Value + 1);
|
||||
g.DrawLine(additionalPen, _startPosX.Value + 84, _startPosY.Value + 14, _startPosX.Value + 39, _startPosY.Value + 2);
|
||||
}
|
||||
//радар
|
||||
if (EntityAntiAircraftGun.Radar)
|
||||
{
|
||||
g.DrawArc(pen, _startPosX.Value + 10, _startPosY.Value + 5, 20, 20, -45, 180);
|
||||
g.DrawArc(pen, _startPosX.Value + 9, _startPosY.Value + 4, 20, 20, -45, 180);
|
||||
g.DrawArc(pen, _startPosX.Value + 11, _startPosY.Value + 6, 20, 20, -45, 180);
|
||||
g.DrawArc(additionalPen, _startPosX.Value + 5, _startPosY.Value + 5, 20, 20, -45, 180);
|
||||
g.DrawArc(additionalPen, _startPosX.Value + 4, _startPosY.Value + 4, 20, 20, -45, 180);
|
||||
g.DrawArc(additionalPen, _startPosX.Value + 6, _startPosY.Value + 6, 20, 20, -45, 180);
|
||||
}
|
||||
|
||||
|
||||
//гусеница
|
||||
g.DrawEllipse(pen, _startPosX.Value + 5, _startPosY.Value + 30, 100,
|
||||
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 30, 100,
|
||||
30);
|
||||
|
||||
//колеса для гусеницы
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
g.FillEllipse(brBlack, _startPosX.Value + 10, _startPosY.Value + 35, 20,
|
||||
Brush brBlack = new SolidBrush(EntityAntiAircraftGun.BodyColor);
|
||||
g.FillEllipse(brBlack, _startPosX.Value + 5, _startPosY.Value + 35, 20,
|
||||
20);
|
||||
|
||||
g.FillEllipse(brBlack, _startPosX.Value + 80, _startPosY.Value + 35, 20,
|
||||
g.FillEllipse(brBlack, _startPosX.Value + 75, _startPosY.Value + 35, 20,
|
||||
20);
|
||||
|
||||
|
||||
g.FillEllipse(brBlack, _startPosX.Value + 30, _startPosY.Value + 45, 10,
|
||||
g.FillEllipse(brBlack, _startPosX.Value + 25, _startPosY.Value + 45, 10,
|
||||
10);
|
||||
g.FillEllipse(brBlack, _startPosX.Value + 60, _startPosY.Value + 45, 10,
|
||||
g.FillEllipse(brBlack, _startPosX.Value + 55, _startPosY.Value + 45, 10,
|
||||
10);
|
||||
g.FillEllipse(brBlack, _startPosX.Value + 40, _startPosY.Value + 45, 10,
|
||||
g.FillEllipse(brBlack, _startPosX.Value + 35, _startPosY.Value + 45, 10,
|
||||
10);
|
||||
g.FillEllipse(brBlack, _startPosX.Value + 50, _startPosY.Value + 45, 10,
|
||||
g.FillEllipse(brBlack, _startPosX.Value + 45, _startPosY.Value + 45, 10,
|
||||
10);
|
||||
g.FillEllipse(brBlack, _startPosX.Value + 70, _startPosY.Value + 45, 10,
|
||||
g.FillEllipse(brBlack, _startPosX.Value + 65, _startPosY.Value + 45, 10,
|
||||
10);
|
||||
//корпус+башня
|
||||
Brush brGreen = new SolidBrush(Color.DarkGreen);
|
||||
g.FillRectangle(brGreen, _startPosX.Value + 10, _startPosY.Value + 25, 90,
|
||||
g.FillRectangle(brBlack, _startPosX.Value + 5, _startPosY.Value + 25, 90,
|
||||
10);
|
||||
|
||||
g.FillRectangle(brGreen, _startPosX.Value + 35, _startPosY.Value + 9, 30,
|
||||
g.FillRectangle(brBlack, _startPosX.Value + 30, _startPosY.Value + 9, 30,
|
||||
15);
|
||||
}
|
||||
}
|
||||
|
@ -13,14 +13,14 @@ namespace ProjectAntiAircraftGun
|
||||
public partial class FormAntiAircraftGun : Form
|
||||
{
|
||||
|
||||
private DrawingAntiAircraftGun? _drawingAntiAitcraftGun;
|
||||
private DrawingAntiAircraftGun? _drawingAntiAircraftGun;
|
||||
public FormAntiAircraftGun()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawingAntiAitcraftGun == null)
|
||||
if (_drawingAntiAircraftGun == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -28,7 +28,7 @@ namespace ProjectAntiAircraftGun
|
||||
Bitmap bmp = new(pictureBoxAntiAircraftGun.Width,
|
||||
pictureBoxAntiAircraftGun.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawingAntiAitcraftGun.DrawTransport(gr);
|
||||
_drawingAntiAircraftGun.DrawTransport(gr);
|
||||
pictureBoxAntiAircraftGun.Image = bmp;
|
||||
}
|
||||
|
||||
@ -40,25 +40,25 @@ namespace ProjectAntiAircraftGun
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawingAntiAitcraftGun = new DrawingAntiAircraftGun();
|
||||
_drawingAntiAircraftGun = new DrawingAntiAircraftGun();
|
||||
|
||||
|
||||
|
||||
_drawingAntiAitcraftGun.Init(random.Next(100, 300), random.Next(1000,
|
||||
_drawingAntiAircraftGun.Init(random.Next(100, 300), random.Next(1000,
|
||||
3000),
|
||||
Color.FromArgb(random.Next(0, 256)),
|
||||
Color.FromArgb(random.Next(0, 256)),
|
||||
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)));
|
||||
_drawingAntiAitcraftGun.SetPictureSize(pictureBoxAntiAircraftGun.Width,
|
||||
_drawingAntiAircraftGun.SetPictureSize(pictureBoxAntiAircraftGun.Width,
|
||||
pictureBoxAntiAircraftGun.Height);
|
||||
_drawingAntiAitcraftGun.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
_drawingAntiAircraftGun.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
Draw();
|
||||
}
|
||||
private void buttonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingAntiAitcraftGun == null)
|
||||
if (_drawingAntiAircraftGun == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -69,19 +69,19 @@ Convert.ToBoolean(random.Next(0, 2)));
|
||||
{
|
||||
case "buttonUp":
|
||||
result =
|
||||
_drawingAntiAitcraftGun.MoveTransport(DirectionType.Up);
|
||||
_drawingAntiAircraftGun.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result =
|
||||
_drawingAntiAitcraftGun.MoveTransport(DirectionType.Down);
|
||||
_drawingAntiAircraftGun.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result =
|
||||
_drawingAntiAitcraftGun.MoveTransport(DirectionType.Left);
|
||||
_drawingAntiAircraftGun.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result =
|
||||
_drawingAntiAitcraftGun.MoveTransport(DirectionType.Right);
|
||||
_drawingAntiAircraftGun.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user