лаб - 3

This commit is contained in:
Daniya_Youdakova 2022-12-15 21:57:40 +04:00
parent e1db93a2e7
commit ef7807d6fd
3 changed files with 58 additions and 32 deletions

View File

@ -10,42 +10,38 @@ namespace AircraftCarrier
{
public DrawningModernAircraftCarrier(int speed, float weight, Color bodyColor, Color
dopColor, bool flightDeck, bool hangarDeck, bool route) :
base(speed, weight, bodyColor, 270, 150)
base(speed, weight, bodyColor, 230, 80)
{
AircraftCarrier = new EntityModernAircraftCarrier(speed, weight, bodyColor, dopColor, flightDeck, hangarDeck, route);
}
public override void DrawTransport(Graphics g)
{
if (AircraftCarrier is not EntityModernAircraftCarrier ModernAircraftCarrier)
if (AircraftCarrier is not EntityModernAircraftCarrier modernAircraftCarrier)
{
return;
}
Pen pen = new(Color.Black);
Brush dopBrush = new SolidBrush(ModernAircraftCarrier.DopColor);
Brush dopBrush = new SolidBrush(modernAircraftCarrier.DopColor);
if (ModernAircraftCarrier.FlightDeck)
if (modernAircraftCarrier.FlightDeck)
{
g.DrawRectangle(pen, _startPosX+10, _startPosY+5, 160, 10);
g.DrawRectangle(pen, _startPosX+10, _startPosY + 75, 160, 10);
g.FillRectangle(dopBrush, _startPosX+10, _startPosY + 5, 160, 10);
g.FillRectangle(dopBrush, _startPosX+10, _startPosY + 75, 160, 10);
g.DrawRectangle(pen, _startPosX + 10, _startPosY, 160, 10);
g.DrawRectangle(pen, _startPosX + 10, _startPosY + 70, 160, 10);
g.FillRectangle(dopBrush, _startPosX + 10, _startPosY, 160, 10);
g.FillRectangle(dopBrush, _startPosX + 10, _startPosY + 70, 160, 10);
}
_startPosX += 10;
_startPosY += 5;
base.DrawTransport(g);
_startPosX -= 10;
_startPosY -= 5;
if (ModernAircraftCarrier.HangarDeck)
if (modernAircraftCarrier.HangarDeck)
{
g.DrawRectangle(pen, _startPosX + 20, _startPosY + 29, 20, 30);
g.FillRectangle(dopBrush, _startPosX + 20, _startPosY + 29, 20, 30);
g.DrawRectangle(pen, _startPosX + 20, _startPosY + 24, 20, 30);
g.FillRectangle(dopBrush, _startPosX + 20, _startPosY + 24, 20, 30);
}
if (ModernAircraftCarrier.Route)
if (modernAircraftCarrier.Route)
{
g.DrawRectangle(pen, _startPosX, _startPosY + 19, 10, 5);
g.DrawRectangle(pen, _startPosX, _startPosY + 74, 10, 5);
g.FillRectangle(dopBrush, _startPosX, _startPosY + 19, 10, 5);
g.FillRectangle(dopBrush, _startPosX , _startPosY + 74, 10, 5);
g.DrawRectangle(pen, _startPosX, _startPosY + 14, 10, 5);
g.DrawRectangle(pen, _startPosX, _startPosY + 69, 10, 5);
g.FillRectangle(dopBrush, _startPosX, _startPosY + 14, 10, 5);
g.FillRectangle(dopBrush, _startPosX, _startPosY + 69, 10, 5);
}
}
}

View File

@ -6,12 +6,16 @@ using System.Threading.Tasks;
namespace AircraftCarrier
{
internal class EntityAircraftCarrier
public class EntityAircraftCarrier
{
public int Speed { get; private set; }
public float Weight { get; private set; }
public Color BodyColor { get; private set; }
public float Step => Speed * 100 / Weight;
public EntityAircraftCarrier(int speed, float weight, Color bodyColor)
{
Random rnd = new Random();
@ -19,5 +23,6 @@ namespace AircraftCarrier
Weight = weight <= 0 ? rnd.Next(40, 70) : weight;
BodyColor = bodyColor;
}
}
}

View File

@ -13,6 +13,7 @@ namespace AircraftCarrier
public partial class FormAircraftCarrier : Form
{
private DrawningAircraftCarrier _aircraftcarrier;
public DrawningAircraftCarrier SelectedAircraftCarrier { get; private set; }
public FormAircraftCarrier()
{
InitializeComponent();
@ -24,6 +25,7 @@ namespace AircraftCarrier
_aircraftcarrier?.DrawTransport(gr);
pictureBoxAircraftCarrier.Image = bmp;
}
private void SetData()
{
Random rnd = new();
@ -35,8 +37,14 @@ namespace AircraftCarrier
}
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
_aircraftcarrier = new DrawningAircraftCarrier(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
Random rnd = new Random();
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_aircraftcarrier = new DrawningAircraftCarrier(rnd.Next(100, 300), rnd.Next(4000, 5000), color);
SetData();
Draw();
}
@ -60,19 +68,36 @@ namespace AircraftCarrier
}
Draw();
}
private void ButtonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new();
_aircraftcarrier = new DrawningAircraftCarrier(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), Color.FromArgb(rnd.Next(0, 256),rnd.Next(0, 256), rnd.Next(0, 256))));
SetData();
Draw();
}
private void PictureBoxAircraftCarrier_Resize(object sender, EventArgs e)
{
/// Изменение размеров формы
_aircraftcarrier?.ChangeBorders(pictureBoxAircraftCarrier.Width, pictureBoxAircraftCarrier.Height);
Draw();
}
private void ButtonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new Random();
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialogDop = new();
if (dialogDop.ShowDialog() == DialogResult.OK)
{
dopColor = dialogDop.Color;
}
_aircraftcarrier = new DrawningModernAircraftCarrier(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor,
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData();
Draw();
}
private void ButtonSelectAircraftCarrier_Click(object sender, EventArgs e)
{
SelectedAircraftCarrier = _aircraftcarrier;
DialogResult = DialogResult.OK;
}
}
}