lab1-good
This commit is contained in:
parent
e0c1010701
commit
095509189a
@ -32,7 +32,7 @@ public class DrawingElectroTrans
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина прорисовки автомобиля
|
/// Ширина прорисовки автомобиля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _drawningTransWidth = 110;
|
private readonly int _drawningTransWidth = 80;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота прорисовки автомобиля
|
/// Высота прорисовки автомобиля
|
||||||
@ -68,17 +68,20 @@ public class DrawingElectroTrans
|
|||||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||||
public bool SetPictureSize(int width, int height)
|
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;
|
_pictureWidth = width;
|
||||||
_pictureHeight = height;
|
_pictureHeight = height;
|
||||||
|
if (_startPosX.HasValue && _startPosY.HasValue){
|
||||||
|
SetPosition(_startPosX.Value, _startPosY.Value);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка позиции
|
/// Установка позиции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -91,21 +94,21 @@ public class DrawingElectroTrans
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (x < 40)
|
if (x < 0)
|
||||||
{
|
{
|
||||||
x = 40;
|
x = 0;
|
||||||
}else if (x > _pictureWidth - 40)
|
}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;
|
_startPosX = x;
|
||||||
@ -124,7 +127,7 @@ public class DrawingElectroTrans
|
|||||||
{
|
{
|
||||||
return false;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
@ -132,7 +135,7 @@ public class DrawingElectroTrans
|
|||||||
{
|
{
|
||||||
//влево
|
//влево
|
||||||
case DirectionType.Left:
|
case DirectionType.Left:
|
||||||
if (_startPosX.Value - EntityElectroTrans.Step > 40)
|
if (_startPosX.Value - EntityElectroTrans.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosX -= (int)EntityElectroTrans.Step;
|
_startPosX -= (int)EntityElectroTrans.Step;
|
||||||
}
|
}
|
||||||
@ -140,7 +143,7 @@ public class DrawingElectroTrans
|
|||||||
return true;
|
return true;
|
||||||
//вверх
|
//вверх
|
||||||
case DirectionType.Up:
|
case DirectionType.Up:
|
||||||
if (_startPosY.Value - EntityElectroTrans.Step > 40)
|
if (_startPosY.Value - EntityElectroTrans.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosY -= (int)EntityElectroTrans.Step;
|
_startPosY -= (int)EntityElectroTrans.Step;
|
||||||
}
|
}
|
||||||
@ -148,14 +151,14 @@ public class DrawingElectroTrans
|
|||||||
return true;
|
return true;
|
||||||
// вправо
|
// вправо
|
||||||
case DirectionType.Right:
|
case DirectionType.Right:
|
||||||
if (_startPosX.Value + EntityElectroTrans.Step < _pictureWidth - 40)
|
if (_startPosX.Value + EntityElectroTrans.Step < _pictureWidth - _drawningTransWidth)
|
||||||
{
|
{
|
||||||
_startPosX += (int)EntityElectroTrans.Step;
|
_startPosX += (int)EntityElectroTrans.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
//вниз
|
//вниз
|
||||||
case DirectionType.Down:
|
case DirectionType.Down:
|
||||||
if (_startPosY.Value + EntityElectroTrans.Step < _pictureHeight - 40)
|
if (_startPosY.Value + EntityElectroTrans.Step < _pictureHeight - _drawningTransHeight)
|
||||||
{
|
{
|
||||||
_startPosY += (int)EntityElectroTrans.Step;
|
_startPosY += (int)EntityElectroTrans.Step;
|
||||||
}
|
}
|
||||||
@ -181,59 +184,61 @@ public class DrawingElectroTrans
|
|||||||
Pen additionalPen = new(EntityElectroTrans.AdditionalColor);
|
Pen additionalPen = new(EntityElectroTrans.AdditionalColor);
|
||||||
Brush brush = new SolidBrush(EntityElectroTrans.BodyColor);
|
Brush brush = new SolidBrush(EntityElectroTrans.BodyColor);
|
||||||
Brush additionalBrush = new SolidBrush(EntityElectroTrans.AdditionalColor);
|
Brush additionalBrush = new SolidBrush(EntityElectroTrans.AdditionalColor);
|
||||||
|
int _centerPosX = _startPosX.Value + _drawningTransWidth / 2;
|
||||||
|
int _centerPosY = _startPosY.Value + _drawningTransHeight / 2;
|
||||||
g.DrawPolygon(pen, new Point[] {
|
g.DrawPolygon(pen, new Point[] {
|
||||||
new Point(_startPosX.Value - 40, _startPosY.Value),
|
new Point(_centerPosX - 40, _centerPosY),
|
||||||
new Point(_startPosX.Value - 30, _startPosY.Value - 20),
|
new Point(_centerPosX - 30, _centerPosY - 20),
|
||||||
new Point(_startPosX.Value + 30, _startPosY.Value - 20),
|
new Point(_centerPosX + 30, _centerPosY - 20),
|
||||||
new Point(_startPosX.Value + 40, _startPosY.Value),
|
new Point(_centerPosX + 40, _centerPosY),
|
||||||
new Point(_startPosX.Value + 40, _startPosY.Value + 20),
|
new Point(_centerPosX + 40, _centerPosY + 20),
|
||||||
new Point(_startPosX.Value - 40, _startPosY.Value + 20),
|
new Point(_centerPosX - 40, _centerPosY + 20),
|
||||||
});
|
});
|
||||||
|
|
||||||
for (int i = 0; i < EntityElectroTrans.Wheels; i++)
|
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[] {
|
g.FillPolygon(additionalBrush, new Point[] {
|
||||||
new Point(_startPosX.Value - 38, _startPosY.Value),
|
new Point(_centerPosX - 38, _centerPosY),
|
||||||
new Point(_startPosX.Value - 30, _startPosY.Value - 17),
|
new Point(_centerPosX - 30, _centerPosY - 17),
|
||||||
new Point(_startPosX.Value + 30, _startPosY.Value - 17),
|
new Point(_centerPosX + 30, _centerPosY - 17),
|
||||||
new Point(_startPosX.Value + 38, _startPosY.Value),
|
new Point(_centerPosX + 38, _centerPosY),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (EntityElectroTrans.Horns)
|
if (EntityElectroTrans.Horns)
|
||||||
{
|
{
|
||||||
g.DrawPolygon(additionalPen, new Point[] {
|
g.DrawPolygon(additionalPen, new Point[] {
|
||||||
new Point(_startPosX.Value, _startPosY.Value - 20),
|
new Point(_centerPosX, _centerPosY - 20),
|
||||||
new Point(_startPosX.Value - 20, _startPosY.Value - 30),
|
new Point(_centerPosX - 20, _centerPosY - 30),
|
||||||
new Point(_startPosX.Value + 20, _startPosY.Value - 30),
|
new Point(_centerPosX + 20, _centerPosY - 30),
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g.DrawPolygon(additionalPen, new Point[] {
|
g.DrawPolygon(additionalPen, new Point[] {
|
||||||
new Point(_startPosX.Value, _startPosY.Value - 20),
|
new Point(_centerPosX, _centerPosY - 20),
|
||||||
new Point(_startPosX.Value - 20, _startPosY.Value - 23),
|
new Point(_centerPosX - 20, _centerPosY - 23),
|
||||||
new Point(_startPosX.Value + 20, _startPosY.Value - 23),
|
new Point(_centerPosX + 20, _centerPosY - 23),
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (EntityElectroTrans.Battery){
|
if (EntityElectroTrans.Battery){
|
||||||
g.FillPolygon(additionalBrush, new Point[] {
|
g.FillPolygon(additionalBrush, new Point[] {
|
||||||
new Point(_startPosX.Value - 15, _startPosY.Value + 2),
|
new Point(_centerPosX - 15, _centerPosY + 2),
|
||||||
new Point(_startPosX.Value - 15, _startPosY.Value + 6),
|
new Point(_centerPosX - 15, _centerPosY + 6),
|
||||||
new Point(_startPosX.Value - 18, _startPosY.Value + 6),
|
new Point(_centerPosX - 18, _centerPosY + 6),
|
||||||
new Point(_startPosX.Value - 18, _startPosY.Value + 10),
|
new Point(_centerPosX - 18, _centerPosY + 10),
|
||||||
new Point(_startPosX.Value - 15, _startPosY.Value + 10),
|
new Point(_centerPosX - 15, _centerPosY + 10),
|
||||||
new Point(_startPosX.Value - 15, _startPosY.Value + 16),
|
new Point(_centerPosX - 15, _centerPosY + 16),
|
||||||
new Point(_startPosX.Value + 18, _startPosY.Value + 16),
|
new Point(_centerPosX + 18, _centerPosY + 16),
|
||||||
new Point(_startPosX.Value + 18, _startPosY.Value + 2),
|
new Point(_centerPosX + 18, _centerPosY + 2),
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
4
Lab1/Form1.Designer.cs
generated
4
Lab1/Form1.Designer.cs
generated
@ -53,7 +53,7 @@
|
|||||||
buttonCreateSportCar.Name = "buttonCreateSportCar";
|
buttonCreateSportCar.Name = "buttonCreateSportCar";
|
||||||
buttonCreateSportCar.Size = new Size(75, 23);
|
buttonCreateSportCar.Size = new Size(75, 23);
|
||||||
buttonCreateSportCar.TabIndex = 1;
|
buttonCreateSportCar.TabIndex = 1;
|
||||||
buttonCreateSportCar.Text = pictureBoxSportCar.ClientSize.ToString();
|
buttonCreateSportCar.Text = "Create";
|
||||||
buttonCreateSportCar.UseVisualStyleBackColor = true;
|
buttonCreateSportCar.UseVisualStyleBackColor = true;
|
||||||
buttonCreateSportCar.Click += ButtonCreateElectroTrans_Click;
|
buttonCreateSportCar.Click += ButtonCreateElectroTrans_Click;
|
||||||
//
|
//
|
||||||
@ -117,7 +117,7 @@
|
|||||||
Controls.Add(buttonCreateSportCar);
|
Controls.Add(buttonCreateSportCar);
|
||||||
Controls.Add(pictureBoxSportCar);
|
Controls.Add(pictureBoxSportCar);
|
||||||
Name = "FormElectroTrans";
|
Name = "FormElectroTrans";
|
||||||
Text = "Элетропоезд";
|
Text = "ElectroTrans";
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxSportCar).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxSportCar).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
|
@ -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)),
|
||||||
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)));
|
Convert.ToBoolean(random.Next(0, 2)), random.Next(3, 8), Convert.ToBoolean(random.Next(0, 2)));
|
||||||
SetSize();
|
_drawningElectroTrans.SetPictureSize(pictureBoxSportCar.Size.Width, pictureBoxSportCar.Size.Height);
|
||||||
_drawningElectroTrans.SetPosition(50, 50);
|
_drawningElectroTrans.SetPosition(random.Next(0, 5), random.Next(0, 5));
|
||||||
Resize += Form1_Resize;
|
|
||||||
Draw();
|
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>
|
||||||
/// Ïåðåìåùåíèå îáúåêòà ïî ôîðìå (íàæàòèå êíîïîê íàâèãàöèè)
|
/// Ïåðåìåùåíèå îáúåêòà ïî ôîðìå (íàæàòèå êíîïîê íàâèãàöèè)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<TargetFramework>net8.0-windows</TargetFramework>
|
<TargetFramework>net7.0-windows</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<UseWindowsForms>true</UseWindowsForms>
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
Loading…
Reference in New Issue
Block a user