Лабораторная работа №2
This commit is contained in:
parent
bd1882b5cf
commit
02957d58e4
@ -1,9 +1,4 @@
|
||||
using AntiAircraftGun.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AntiAircraftGun.Drawnings;
|
||||
|
||||
@ -200,7 +195,7 @@ public class DrawningAircraftGun
|
||||
_startPosY += (int)EntityAircraftGun.Step;
|
||||
}
|
||||
return true;
|
||||
case DirectionType.Up: //вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY - EntityAircraftGun.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityAircraftGun.Step;
|
||||
@ -263,8 +258,6 @@ public class DrawningAircraftGun
|
||||
g.FillRectangle(brDarkSlateGray, _startPosX.Value + 10, _startPosY.Value + 65, 120, 13);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AntiAircraftGun.Entities;
|
||||
namespace AntiAircraftGun.Entities;
|
||||
/// <summary>
|
||||
/// Класс - сущность Бронированная машина
|
||||
/// </summary>
|
||||
|
@ -27,8 +27,7 @@ public class EntityAntiAircraftGun : EntityAircraftGun
|
||||
/// <param name="tower">Наличие башни</param>
|
||||
/// <param name="radar">Наличие радара</param>
|
||||
public EntityAntiAircraftGun(int speed, double weight, Color bodyColor, bool radar, bool tower, Color additionalColor) : base(speed, weight, bodyColor)
|
||||
{
|
||||
|
||||
{
|
||||
Radar = radar;
|
||||
Tower = tower;
|
||||
AdditionalColor = additionalColor;
|
||||
|
@ -1,156 +1,155 @@
|
||||
using AntiAircraftGun.Drawnings;
|
||||
using AntiAircraftGun.MovementStrategy;
|
||||
|
||||
namespace AntiAircraftGun
|
||||
{
|
||||
public partial class FormAntiAircraftGun : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningAircraftGun? _drawningAircraftGun;
|
||||
/// <summary>
|
||||
/// Стратегия перемещения
|
||||
/// </summary>
|
||||
private AbstractStrategy? _strategy;
|
||||
/// <summary>
|
||||
/// конструктор формы
|
||||
/// </summary>
|
||||
public FormAntiAircraftGun()
|
||||
{
|
||||
InitializeComponent();
|
||||
_strategy = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки транспорта
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningAircraftGun == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningAircraftGun.DrawTransport(gr);
|
||||
pictureBoxAntiAircraftGun.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод создания объекта
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningAircraftGun):
|
||||
_drawningAircraftGun = new DrawningAircraftGun(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
||||
break;
|
||||
case nameof(DrawningAntiAircraftGun):
|
||||
_drawningAircraftGun = new DrawningAntiAircraftGun(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)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
namespace AntiAircraftGun;
|
||||
|
||||
_drawningAircraftGun.SetPictureSize(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
|
||||
_drawningAircraftGun.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
_strategy = null;
|
||||
comboBoxStrategy.Enabled = true;
|
||||
public partial class FormAntiAircraftGun : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningAircraftGun? _drawningAircraftGun;
|
||||
/// <summary>
|
||||
/// Стратегия перемещения
|
||||
/// </summary>
|
||||
private AbstractStrategy? _strategy;
|
||||
/// <summary>
|
||||
/// конструктор формы
|
||||
/// </summary>
|
||||
public FormAntiAircraftGun()
|
||||
{
|
||||
InitializeComponent();
|
||||
_strategy = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки транспорта
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningAircraftGun == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningAircraftGun.DrawTransport(gr);
|
||||
pictureBoxAntiAircraftGun.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод создания объекта
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningAircraftGun):
|
||||
_drawningAircraftGun = new DrawningAircraftGun(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
||||
break;
|
||||
case nameof(DrawningAntiAircraftGun):
|
||||
_drawningAircraftGun = new DrawningAntiAircraftGun(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)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
_drawningAircraftGun.SetPictureSize(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
|
||||
_drawningAircraftGun.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
_strategy = null;
|
||||
comboBoxStrategy.Enabled = true;
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка кнопик Создать Зенитную установку
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAntiAircraftGun));
|
||||
/// <summary>
|
||||
/// Обработка кнопик Создать установку
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCreatAircraftGun_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAircraftGun));
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение объекта по форме
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningAircraftGun == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
bool result = false;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result = _drawningAircraftGun.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _drawningAircraftGun.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _drawningAircraftGun.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _drawningAircraftGun.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
{
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка кнопик Создать Зенитную установку
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAntiAircraftGun));
|
||||
/// <summary>
|
||||
/// Обработка кнопик Создать установку
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCreatAircraftGun_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAircraftGun));
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение объекта по форме
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод выбора стратегии
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonStrategyStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningAircraftGun == null)
|
||||
{
|
||||
if (_drawningAircraftGun == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
bool result = false;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result = _drawningAircraftGun.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _drawningAircraftGun.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _drawningAircraftGun.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _drawningAircraftGun.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
{
|
||||
Draw();
|
||||
}
|
||||
return;
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод выбора стратегии
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonStrategyStep_Click(object sender, EventArgs e)
|
||||
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
if (_drawningAircraftGun == null)
|
||||
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_strategy.SetData(new MoveableAircraftGun(_drawningAircraftGun), pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
|
||||
}
|
||||
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_strategy.SetData(new MoveableAircraftGun(_drawningAircraftGun), pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
|
||||
}
|
||||
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
}
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
|
||||
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user