Пибд-23 Тихоненков Алексей Лабораторная №1 #2

Closed
YourDax wants to merge 6 commits from Lab1 into main
2 changed files with 14 additions and 49 deletions
Showing only changes of commit 4bc51728fe - Show all commits

View File

@ -72,7 +72,7 @@ namespace AntiAircraftGun
if (AntiAircraftGun == null) return;
_startPosX = x;
_startPosY = y;
if (x + _zenitWidth >= _pictureWidth || y + _zenitHeight>= _pictureHeight)
if (x < 0 || y < 0 ||x + _zenitWidth >= _pictureWidth || y + _zenitHeight>= _pictureHeight)
Outdated
Review

Не учтены все условия, при которых объект может выйти за границы

Не учтены все условия, при которых объект может выйти за границы
{
_startPosX = 1;
_startPosY = 1;
@ -106,14 +106,14 @@ namespace AntiAircraftGun
break;
// вправо
case DirectionType.Right:
if (_startPosX + AntiAircraftGun.Step < _pictureWidth-110)
if (_startPosX + AntiAircraftGun.Step + _zenitWidth < _pictureWidth)
Outdated
Review

Что за 110?

Что за 110?
{
_startPosX += (int)AntiAircraftGun.Step;
}
break;
//вниз
case DirectionType.Down:
if (_startPosY + AntiAircraftGun.Step < _pictureHeight-60)
if (_startPosY + AntiAircraftGun.Step + _zenitHeight < _pictureHeight)
{
_startPosY += (int)AntiAircraftGun.Step;
}

View File

@ -5,63 +5,28 @@ namespace AntiAircraftGun
/// <summary>
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
/// </summary>
private DrawingAntiAirCraftGun? _drawing;
private DrawingAntiAirCraftGun? _drawingAntiAirCraftGun;
Outdated
Review

Класс DrawingAntiAirCraftGun, а объект _drawing?

Класс DrawingAntiAirCraftGun, а объект _drawing?
public FormAntiAirCraftGun()
{
InitializeComponent();
}
private void Move_Click(object sender, EventArgs e)
{
if (_drawing == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_drawing.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
_drawing.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
_drawing.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
_drawing.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
private void pictureBoxZenit_Click(object sender, EventArgs e)
{
}
/// <summary>
Review

Не используемый метод

Не используемый метод
/// Ìåòîä ïðîðèñîâêè ìàøèíû
/// </summary>
private void Draw()
{
if (_drawing == null)
if (_drawingAntiAirCraftGun == null)
{
return;
}
Bitmap bmp = new(pictureBoxAntiAircraftGun.Width,pictureBoxAntiAircraftGun.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawing.DrawTransport(gr);
_drawingAntiAirCraftGun.DrawTransport(gr);
pictureBoxAntiAircraftGun.Image = bmp;
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawing == null)
if (_drawingAntiAirCraftGun == null)
{
return;
}
@ -69,16 +34,16 @@ namespace AntiAircraftGun
switch (name)
{
case "buttonUp":
_drawing.MoveTransport(DirectionType.Up);
_drawingAntiAirCraftGun.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
_drawing.MoveTransport(DirectionType.Down);
_drawingAntiAirCraftGun.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
Review

Пустых методов быть не должно

Пустых методов быть не должно
_drawing.MoveTransport(DirectionType.Left);
_drawingAntiAirCraftGun.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
_drawing.MoveTransport(DirectionType.Right);
_drawingAntiAirCraftGun.MoveTransport(DirectionType.Right);
break;
}
Draw();
@ -86,8 +51,8 @@ namespace AntiAircraftGun
private void buttonCreate_Click(object sender, EventArgs e)
{
Random random = new();
_drawing = new DrawingAntiAirCraftGun();
_drawing.Init(random.Next(100, 300),//cêîðîñòü
_drawingAntiAirCraftGun = new DrawingAntiAirCraftGun();
_drawingAntiAirCraftGun.Init(random.Next(100, 300),//cêîðîñòü
random.Next(1000, 3000), //âåñ
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),//îñíîâíîé öâåò
random.Next(0, 256)),
@ -99,7 +64,7 @@ namespace AntiAircraftGun
Convert.ToBoolean(random.Next(2)), // Radar
pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
_drawing.SetPosition(random.Next(10, 100),
_drawingAntiAirCraftGun.SetPosition(random.Next(10, 100),
random.Next(10, 100));