Пибд-23 Тихоненков Алексей Лабораторная №1 #2
@ -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)
|
||||
|
||||
{
|
||||
_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)
|
||||
eegov
commented
Что за 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;
|
||||
}
|
||||
|
@ -5,63 +5,28 @@ namespace AntiAircraftGun
|
||||
/// <summary>
|
||||
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
|
||||
/// </summary>
|
||||
private DrawingAntiAirCraftGun? _drawing;
|
||||
private DrawingAntiAirCraftGun? _drawingAntiAirCraftGun;
|
||||
eegov
commented
Класс 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>
|
||||
eegov
commented
Не используемый метод Не используемый метод
|
||||
/// Ìåòîä ïðîðèñîâêè ìàøèíû
|
||||
/// </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":
|
||||
eegov
commented
Пустых методов быть не должно Пустых методов быть не должно
|
||||
_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));
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user
Не учтены все условия, при которых объект может выйти за границы