lab1-good

This commit is contained in:
Shtyrkin_Egor 2024-02-15 10:41:33 +04:00
parent e0c1010701
commit 095509189a
4 changed files with 58 additions and 68 deletions

View File

@ -32,7 +32,7 @@ public class DrawingElectroTrans
/// <summary>
/// Ширина прорисовки автомобиля
/// </summary>
private readonly int _drawningTransWidth = 110;
private readonly int _drawningTransWidth = 80;
/// <summary>
/// Высота прорисовки автомобиля
@ -49,7 +49,7 @@ public class DrawingElectroTrans
/// <param name="horns">Признак активности усов</param>
/// <param name="wheels">Признак колличества колес</param>
/// <param name="battery">Признак наличия бптпрей</param>
public void Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool horns, int wheels, bool battery)
{
@ -68,15 +68,18 @@ public class DrawingElectroTrans
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
public bool SetPictureSize(int width, int height)
{
if (width < 100 || height < 100)
if (width >= _drawningTransWidth || height >= _drawningTransWidth)
{
_pictureWidth = Config.screenSize.Width;
_pictureHeight = Config.screenSize.Height;
return false;
_pictureWidth = width;
_pictureHeight = height;
if (_startPosX.HasValue && _startPosY.HasValue){
SetPosition(_startPosX.Value, _startPosY.Value);
}
return true;
}
_pictureWidth = width;
_pictureHeight = height;
return true;
return false;
}
/// <summary>
@ -91,21 +94,21 @@ public class DrawingElectroTrans
return;
}
if (x < 40)
if (x < 0)
{
x = 40;
}else if (x > _pictureWidth - 40)
x = 0;
}else if (x > _pictureWidth - _drawningTransWidth)
{
x = _pictureWidth.Value - 40;
x = _pictureWidth.Value - _drawningTransWidth;
}
if (y < 40)
if (y < 0)
{
y = 40;
y = 0;
}
else if (y > _pictureHeight - 40)
else if (y > _pictureHeight - _drawningTransHeight)
{
y = _pictureHeight.Value - 40;
y = _pictureHeight.Value - _drawningTransHeight;
}
_startPosX = x;
@ -124,7 +127,7 @@ public class DrawingElectroTrans
{
return false;
}
if (_startPosX.Value < 40 || _startPosY.Value < 40 || _startPosX > _pictureWidth - 40 || _startPosY > _pictureHeight - 40)
if (_startPosX.Value < 0 || _startPosY.Value < 0 || _startPosX > _pictureWidth - _drawningTransWidth || _startPosY > _pictureHeight - _drawningTransHeight)
{
return false;
}
@ -132,7 +135,7 @@ public class DrawingElectroTrans
{
//влево
case DirectionType.Left:
if (_startPosX.Value - EntityElectroTrans.Step > 40)
if (_startPosX.Value - EntityElectroTrans.Step > 0)
{
_startPosX -= (int)EntityElectroTrans.Step;
}
@ -140,7 +143,7 @@ public class DrawingElectroTrans
return true;
//вверх
case DirectionType.Up:
if (_startPosY.Value - EntityElectroTrans.Step > 40)
if (_startPosY.Value - EntityElectroTrans.Step > 0)
{
_startPosY -= (int)EntityElectroTrans.Step;
}
@ -148,14 +151,14 @@ public class DrawingElectroTrans
return true;
// вправо
case DirectionType.Right:
if (_startPosX.Value + EntityElectroTrans.Step < _pictureWidth - 40)
if (_startPosX.Value + EntityElectroTrans.Step < _pictureWidth - _drawningTransWidth)
{
_startPosX += (int)EntityElectroTrans.Step;
}
return true;
//вниз
case DirectionType.Down:
if (_startPosY.Value + EntityElectroTrans.Step < _pictureHeight - 40)
if (_startPosY.Value + EntityElectroTrans.Step < _pictureHeight - _drawningTransHeight)
{
_startPosY += (int)EntityElectroTrans.Step;
}
@ -181,59 +184,61 @@ public class DrawingElectroTrans
Pen additionalPen = new(EntityElectroTrans.AdditionalColor);
Brush brush = new SolidBrush(EntityElectroTrans.BodyColor);
Brush additionalBrush = new SolidBrush(EntityElectroTrans.AdditionalColor);
int _centerPosX = _startPosX.Value + _drawningTransWidth / 2;
int _centerPosY = _startPosY.Value + _drawningTransHeight / 2;
g.DrawPolygon(pen, new Point[] {
new Point(_startPosX.Value - 40, _startPosY.Value),
new Point(_startPosX.Value - 30, _startPosY.Value - 20),
new Point(_startPosX.Value + 30, _startPosY.Value - 20),
new Point(_startPosX.Value + 40, _startPosY.Value),
new Point(_startPosX.Value + 40, _startPosY.Value + 20),
new Point(_startPosX.Value - 40, _startPosY.Value + 20),
new Point(_centerPosX - 40, _centerPosY),
new Point(_centerPosX - 30, _centerPosY - 20),
new Point(_centerPosX + 30, _centerPosY - 20),
new Point(_centerPosX + 40, _centerPosY),
new Point(_centerPosX + 40, _centerPosY + 20),
new Point(_centerPosX - 40, _centerPosY + 20),
});
for (int i = 0; i < EntityElectroTrans.Wheels; i++)
{
g.FillEllipse(additionalBrush, new Rectangle((_startPosX.Value - 40) + (70 / EntityElectroTrans.Wheels) * (i + 1) + -4, _startPosY.Value + 16, 8, 8));
g.FillEllipse(additionalBrush, new Rectangle((_centerPosX - 40) + (70 / EntityElectroTrans.Wheels) * (i + 1) + -4, _centerPosY + 16, 8, 8));
}
g.FillPolygon(additionalBrush, new Point[] {
new Point(_startPosX.Value - 38, _startPosY.Value),
new Point(_startPosX.Value - 30, _startPosY.Value - 17),
new Point(_startPosX.Value + 30, _startPosY.Value - 17),
new Point(_startPosX.Value + 38, _startPosY.Value),
new Point(_centerPosX - 38, _centerPosY),
new Point(_centerPosX - 30, _centerPosY - 17),
new Point(_centerPosX + 30, _centerPosY - 17),
new Point(_centerPosX + 38, _centerPosY),
});
if (EntityElectroTrans.Horns)
{
g.DrawPolygon(additionalPen, new Point[] {
new Point(_startPosX.Value, _startPosY.Value - 20),
new Point(_startPosX.Value - 20, _startPosY.Value - 30),
new Point(_startPosX.Value + 20, _startPosY.Value - 30),
new Point(_centerPosX, _centerPosY - 20),
new Point(_centerPosX - 20, _centerPosY - 30),
new Point(_centerPosX + 20, _centerPosY - 30),
});
}
else
{
g.DrawPolygon(additionalPen, new Point[] {
new Point(_startPosX.Value, _startPosY.Value - 20),
new Point(_startPosX.Value - 20, _startPosY.Value - 23),
new Point(_startPosX.Value + 20, _startPosY.Value - 23),
new Point(_centerPosX, _centerPosY - 20),
new Point(_centerPosX - 20, _centerPosY - 23),
new Point(_centerPosX + 20, _centerPosY - 23),
});
}
if (EntityElectroTrans.Battery){
g.FillPolygon(additionalBrush, new Point[] {
new Point(_startPosX.Value - 15, _startPosY.Value + 2),
new Point(_startPosX.Value - 15, _startPosY.Value + 6),
new Point(_startPosX.Value - 18, _startPosY.Value + 6),
new Point(_startPosX.Value - 18, _startPosY.Value + 10),
new Point(_startPosX.Value - 15, _startPosY.Value + 10),
new Point(_startPosX.Value - 15, _startPosY.Value + 16),
new Point(_startPosX.Value + 18, _startPosY.Value + 16),
new Point(_startPosX.Value + 18, _startPosY.Value + 2),
new Point(_centerPosX - 15, _centerPosY + 2),
new Point(_centerPosX - 15, _centerPosY + 6),
new Point(_centerPosX - 18, _centerPosY + 6),
new Point(_centerPosX - 18, _centerPosY + 10),
new Point(_centerPosX - 15, _centerPosY + 10),
new Point(_centerPosX - 15, _centerPosY + 16),
new Point(_centerPosX + 18, _centerPosY + 16),
new Point(_centerPosX + 18, _centerPosY + 2),
});
}
}
}

View File

@ -53,7 +53,7 @@
buttonCreateSportCar.Name = "buttonCreateSportCar";
buttonCreateSportCar.Size = new Size(75, 23);
buttonCreateSportCar.TabIndex = 1;
buttonCreateSportCar.Text = pictureBoxSportCar.ClientSize.ToString();
buttonCreateSportCar.Text = "Create";
buttonCreateSportCar.UseVisualStyleBackColor = true;
buttonCreateSportCar.Click += ButtonCreateElectroTrans_Click;
//
@ -117,7 +117,7 @@
Controls.Add(buttonCreateSportCar);
Controls.Add(pictureBoxSportCar);
Name = "FormElectroTrans";
Text = "Элетропоезд";
Text = "ElectroTrans";
((System.ComponentModel.ISupportInitialize)pictureBoxSportCar).EndInit();
ResumeLayout(false);
}

View File

@ -35,26 +35,11 @@ namespace Lab1
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)), random.Next(3, 8), Convert.ToBoolean(random.Next(0, 2)));
SetSize();
_drawningElectroTrans.SetPosition(50, 50);
Resize += Form1_Resize;
_drawningElectroTrans.SetPictureSize(pictureBoxSportCar.Size.Width, pictureBoxSportCar.Size.Height);
_drawningElectroTrans.SetPosition(random.Next(0, 5), random.Next(0, 5));
Draw();
}
private void Form1_Resize(object? sender, EventArgs e)
{
SetSize();
}
private void SetSize()
{
if (!_drawningElectroTrans.SetPictureSize(ClientSize.Width, ClientSize.Height))
{
Size = Config.screenSize;
}
pictureBoxSportCar.Size = ClientSize;
buttonCreateSportCar.Text = ClientSize.ToString();
}
/// <summary>
/// Ïåðåìåùåíèå îáúåêòà ïî ôîðìå (íàæàòèå êíîïîê íàâèãàöèè)
/// </summary>

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>