Лаба 1

This commit is contained in:
GokaPek 2023-10-03 14:57:43 +04:00
parent 7c0c9c0917
commit 4d50d2fa27
4 changed files with 15 additions and 38 deletions

View File

@ -10,7 +10,7 @@ namespace SelfPropelledArtilleryUnit
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawningSPAU
public class DrawingSPAU
{
/// <summary>
/// Класс-сущность
@ -47,14 +47,12 @@ namespace SelfPropelledArtilleryUnit
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Цвет кузова</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="bodyKit">Признак наличия обвеса</param>
/// <param name="wing">Признак наличия антикрыла</param>
/// <param name="sportLine">Признак наличия гоночной полосы</param>
/// <param name="bodyKit">Признак наличия залповой установки</param>
/// <param name="width">Ширина картинки</param>
/// <param name="height">Высота картинки</param>
/// <returns>true - объект создан, false - проверка не пройдена,нельзя создать объект в этих размерах</returns>
public bool Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height)
additionalColor, bool bodyKit, int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
@ -68,7 +66,7 @@ namespace SelfPropelledArtilleryUnit
}
EntitySPAU = new EntitySPAU();
EntitySPAU.Init(speed, weight, bodyColor, additionalColor,
bodyKit, wing, sportLine);
bodyKit);
return true;
}
/// <summary>
@ -78,7 +76,6 @@ namespace SelfPropelledArtilleryUnit
/// <param name="y">Координата Y</param>
public void SetPosition(int x, int y)
{
// TODO: Изменение x, y @
if (x < 0 || x > _pictureWidth - _carWidth)
{
x = 0;
@ -153,7 +150,7 @@ namespace SelfPropelledArtilleryUnit
}
//гусеницы
Brush brBlack = new SolidBrush(Color.Black);
Brush br = new SolidBrush(EntitySPAU.BodyColor);
Brush brBody = new SolidBrush(EntitySPAU.BodyColor);
g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 50, 20, 20);
g.FillEllipse(brBlack, _startPosX + 30, _startPosY + 50, 20, 20);
g.FillEllipse(brBlack, _startPosX + 55, _startPosY + 50, 20, 20);
@ -166,7 +163,7 @@ namespace SelfPropelledArtilleryUnit
pointsGun[1].X = _startPosX + 40; pointsGun[1].Y = _startPosY + 45;
pointsGun[2].X = _startPosX + 135; pointsGun[2].Y = _startPosY + 5;
pointsGun[3].X = _startPosX + 130; pointsGun[3].Y = _startPosY + 0;
g.FillPolygon(br, pointsGun);
g.FillPolygon(brBody, pointsGun);
g.DrawPolygon(penBlack, pointsGun);
//корпус
Point[] pointsCorp = new Point[4];
@ -174,7 +171,7 @@ namespace SelfPropelledArtilleryUnit
pointsCorp[1].X = _startPosX + 10; pointsCorp[1].Y = _startPosY + 30;
pointsCorp[2].X = _startPosX + 130; pointsCorp[2].Y = _startPosY + 30;
pointsCorp[3].X = _startPosX + 135; pointsCorp[3].Y = _startPosY + 60;
g.FillPolygon(br, pointsCorp);
g.FillPolygon(brBody, pointsCorp);
g.DrawPolygon(penBlack, pointsCorp);
//башня
Point[] pointsHead = new Point[4];
@ -182,7 +179,7 @@ namespace SelfPropelledArtilleryUnit
pointsHead[1].X = _startPosX + 45; pointsHead[1].Y = _startPosY + 15;
pointsHead[2].X = _startPosX + 70; pointsHead[2].Y = _startPosY + 15;
pointsHead[3].X = _startPosX + 75; pointsHead[3].Y = _startPosY + 30;
g.FillPolygon(br, pointsHead);
g.FillPolygon(brBody, pointsHead);
g.DrawPolygon(penBlack, pointsHead);
}
}

View File

@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SelfPropelledArtilleryUnit
namespace SelfPropelledArtilleryUnit
{
public class EntitySPAU
{
@ -25,19 +19,11 @@ namespace SelfPropelledArtilleryUnit
/// </summary>
public Color AdditionalColor { get; private set; }
/// <summary>
/// Признак (опция) наличия обвеса
/// Признак (опция) наличия залповой установки
/// </summary>
public bool BodyKit { get; private set; }
/// <summary>
/// Признак (опция) наличия антикрыла
/// </summary>
public bool Wing { get; private set; }
/// <summary>
/// Признак (опция) наличия гоночной полосы
/// </summary>
public bool SportLine { get; private set; }
/// <summary>
/// Шаг перемещения автомобиля
/// Шаг перемещения САУ
/// </summary>
public double Step => (double)Speed * 100 / Weight;
/// <summary>
@ -51,15 +37,13 @@ namespace SelfPropelledArtilleryUnit
/// <param name="wing">Признак наличия антикрыла</param>
/// <param name="sportLine">Признак наличия гоночной полосы</param>
public void Init(int speed, double weight, Color bodyColor, Color
additionalColor, bool bodyKit, bool wing, bool sportLine)
additionalColor, bool bodyKit)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor;
BodyKit = bodyKit;
Wing = wing;
SportLine = sportLine;
}
}
}

View File

@ -5,7 +5,7 @@ namespace SelfPropelledArtilleryUnit
/// <summary>
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
/// </summary>
private DrawningSPAU? _drawningSPAU;
private DrawingSPAU? _drawningSPAU;
/// <summary>
/// Èíèöèàëèçàöèÿ ôîðìû
/// </summary>
@ -38,7 +38,7 @@ namespace SelfPropelledArtilleryUnit
private void buttonCreate_Click(object sender, EventArgs e)
{
Random random = new();
_drawningSPAU = new DrawningSPAU();
_drawningSPAU = new DrawingSPAU();
_drawningSPAU.Init(random.Next(100, 300),
random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
@ -46,8 +46,6 @@ namespace SelfPropelledArtilleryUnit
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)),
Convert.ToBoolean(random.Next(0, 2)),
pictureBoxSPAU.Width, pictureBoxSPAU.Height);
_drawningSPAU.SetPosition(random.Next(10, 100),
random.Next(10, 100));
@ -57,7 +55,7 @@ namespace SelfPropelledArtilleryUnit
private void buttonMove_Click(object sender, EventArgs e)
{
if(_drawningSPAU == null)
{
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;

View File

@ -8,8 +8,6 @@ namespace SelfPropelledArtilleryUnit
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form());
}