+Бульдозер
This commit is contained in:
parent
2737314d41
commit
3e58001f7e
57
Traktor/Traktor/DrawField.Designer.cs
generated
57
Traktor/Traktor/DrawField.Designer.cs
generated
@ -38,6 +38,7 @@
|
||||
this.buttonRIGHT = new System.Windows.Forms.Button();
|
||||
this.buttonDOWN = new System.Windows.Forms.Button();
|
||||
this.buttonUP = new System.Windows.Forms.Button();
|
||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTraktor)).BeginInit();
|
||||
this.statusStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -46,8 +47,9 @@
|
||||
//
|
||||
this.pictureBoxTraktor.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxTraktor.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxTraktor.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.pictureBoxTraktor.Name = "pictureBoxTraktor";
|
||||
this.pictureBoxTraktor.Size = new System.Drawing.Size(800, 425);
|
||||
this.pictureBoxTraktor.Size = new System.Drawing.Size(700, 316);
|
||||
this.pictureBoxTraktor.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBoxTraktor.TabIndex = 0;
|
||||
this.pictureBoxTraktor.TabStop = false;
|
||||
@ -60,35 +62,37 @@
|
||||
this.toolStripStatusLabelSpeed,
|
||||
this.toolStripStatusLabelWeight,
|
||||
this.toolStripStatusLabelBodyColor});
|
||||
this.statusStrip.Location = new System.Drawing.Point(0, 425);
|
||||
this.statusStrip.Location = new System.Drawing.Point(0, 316);
|
||||
this.statusStrip.Name = "statusStrip";
|
||||
this.statusStrip.Size = new System.Drawing.Size(800, 26);
|
||||
this.statusStrip.Padding = new System.Windows.Forms.Padding(1, 0, 12, 0);
|
||||
this.statusStrip.Size = new System.Drawing.Size(700, 22);
|
||||
this.statusStrip.TabIndex = 1;
|
||||
//
|
||||
// toolStripStatusLabelSpeed
|
||||
//
|
||||
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
|
||||
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(80, 20);
|
||||
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(65, 17);
|
||||
this.toolStripStatusLabelSpeed.Text = "Скорость: ";
|
||||
//
|
||||
// toolStripStatusLabelWeight
|
||||
//
|
||||
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
|
||||
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(40, 20);
|
||||
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(32, 17);
|
||||
this.toolStripStatusLabelWeight.Text = "Вес: ";
|
||||
//
|
||||
// toolStripStatusLabelBodyColor
|
||||
//
|
||||
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
|
||||
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(95, 20);
|
||||
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(75, 17);
|
||||
this.toolStripStatusLabelBodyColor.Text = "Цвет кузова:";
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreate.Location = new System.Drawing.Point(29, 363);
|
||||
this.buttonCreate.Location = new System.Drawing.Point(25, 272);
|
||||
this.buttonCreate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonCreate.Name = "buttonCreate";
|
||||
this.buttonCreate.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonCreate.Size = new System.Drawing.Size(82, 22);
|
||||
this.buttonCreate.TabIndex = 2;
|
||||
this.buttonCreate.Text = "Создать";
|
||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||
@ -99,9 +103,10 @@
|
||||
this.buttonLEFT.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLEFT.BackgroundImage = global::Traktor.Properties.Resources.arrowLeft;
|
||||
this.buttonLEFT.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLEFT.Location = new System.Drawing.Point(673, 361);
|
||||
this.buttonLEFT.Location = new System.Drawing.Point(589, 271);
|
||||
this.buttonLEFT.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonLEFT.Name = "buttonLEFT";
|
||||
this.buttonLEFT.Size = new System.Drawing.Size(30, 29);
|
||||
this.buttonLEFT.Size = new System.Drawing.Size(26, 22);
|
||||
this.buttonLEFT.TabIndex = 3;
|
||||
this.buttonLEFT.UseVisualStyleBackColor = true;
|
||||
this.buttonLEFT.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
@ -111,9 +116,10 @@
|
||||
this.buttonRIGHT.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRIGHT.BackgroundImage = global::Traktor.Properties.Resources.arrowRight;
|
||||
this.buttonRIGHT.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRIGHT.Location = new System.Drawing.Point(745, 361);
|
||||
this.buttonRIGHT.Location = new System.Drawing.Point(652, 271);
|
||||
this.buttonRIGHT.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonRIGHT.Name = "buttonRIGHT";
|
||||
this.buttonRIGHT.Size = new System.Drawing.Size(30, 29);
|
||||
this.buttonRIGHT.Size = new System.Drawing.Size(26, 22);
|
||||
this.buttonRIGHT.TabIndex = 4;
|
||||
this.buttonRIGHT.UseVisualStyleBackColor = true;
|
||||
this.buttonRIGHT.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
@ -123,9 +129,10 @@
|
||||
this.buttonDOWN.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDOWN.BackgroundImage = global::Traktor.Properties.Resources.arrowDown;
|
||||
this.buttonDOWN.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDOWN.Location = new System.Drawing.Point(709, 379);
|
||||
this.buttonDOWN.Location = new System.Drawing.Point(620, 284);
|
||||
this.buttonDOWN.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonDOWN.Name = "buttonDOWN";
|
||||
this.buttonDOWN.Size = new System.Drawing.Size(30, 29);
|
||||
this.buttonDOWN.Size = new System.Drawing.Size(26, 22);
|
||||
this.buttonDOWN.TabIndex = 5;
|
||||
this.buttonDOWN.UseVisualStyleBackColor = true;
|
||||
this.buttonDOWN.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
@ -135,18 +142,30 @@
|
||||
this.buttonUP.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUP.BackgroundImage = global::Traktor.Properties.Resources.arrowUp;
|
||||
this.buttonUP.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUP.Location = new System.Drawing.Point(709, 343);
|
||||
this.buttonUP.Location = new System.Drawing.Point(620, 257);
|
||||
this.buttonUP.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonUP.Name = "buttonUP";
|
||||
this.buttonUP.Size = new System.Drawing.Size(30, 29);
|
||||
this.buttonUP.Size = new System.Drawing.Size(26, 22);
|
||||
this.buttonUP.TabIndex = 6;
|
||||
this.buttonUP.UseVisualStyleBackColor = true;
|
||||
this.buttonUP.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonCreateModif
|
||||
//
|
||||
this.buttonCreateModif.Location = new System.Drawing.Point(113, 272);
|
||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||
this.buttonCreateModif.Size = new System.Drawing.Size(110, 22);
|
||||
this.buttonCreateModif.TabIndex = 7;
|
||||
this.buttonCreateModif.Text = "Модификация";
|
||||
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
|
||||
//
|
||||
// DrawField
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 451);
|
||||
this.ClientSize = new System.Drawing.Size(700, 338);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.buttonUP);
|
||||
this.Controls.Add(this.buttonDOWN);
|
||||
this.Controls.Add(this.buttonRIGHT);
|
||||
@ -154,6 +173,7 @@
|
||||
this.Controls.Add(this.buttonCreate);
|
||||
this.Controls.Add(this.pictureBoxTraktor);
|
||||
this.Controls.Add(this.statusStrip);
|
||||
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.Name = "DrawField";
|
||||
this.Text = "Трактор";
|
||||
this.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
@ -177,5 +197,6 @@
|
||||
private Button buttonRIGHT;
|
||||
private Button buttonDOWN;
|
||||
private Button buttonUP;
|
||||
private Button buttonCreateModif;
|
||||
}
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
using System;
|
||||
|
||||
namespace Traktor
|
||||
{
|
||||
public partial class DrawField : Form
|
||||
@ -18,15 +20,22 @@ namespace Traktor
|
||||
pictureBoxTraktor.Image = bmp;
|
||||
}
|
||||
|
||||
//Ìåñòî óñòàíîâêè äàííûõ
|
||||
private void SetData()
|
||||
{
|
||||
Random random = new();
|
||||
_Traktor.SetPosition(random.Next(10, 50), random.Next(10, 50), pictureBoxTraktor.Width, pictureBoxTraktor.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_Traktor.Traktor.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_Traktor.Traktor.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò êóçîâà: {_Traktor.Traktor.BodyColor.Name}";
|
||||
}
|
||||
|
||||
//Ëîãèêà êíîïêè Ñîçäàòü
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new Random();
|
||||
_Traktor = new TraktorDraw(random.Next(100, 200), random.Next(2500, 5000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
||||
_Traktor.SetPosition(random.Next(10, 50), random.Next(10, 50), pictureBoxTraktor.Width, pictureBoxTraktor.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_Traktor.Traktor.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_Traktor.Traktor.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò êóçîâà: {_Traktor.Traktor.BodyColor.Name}";
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
|
||||
@ -57,5 +66,17 @@ namespace Traktor
|
||||
_Traktor?.ChangeBorders(pictureBoxTraktor.Width, pictureBoxTraktor.Height);
|
||||
Draw();
|
||||
}
|
||||
|
||||
// Îáðàáîòêà íàæàòèÿ êíîïêè "Ìîäèôèêàöèÿ"
|
||||
private void buttonCreateModif_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new Random();
|
||||
_Traktor = new MultiTraktorDraw(random.Next(100, 200), random.Next(2500, 5000),
|
||||
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)));
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
}
|
32
Traktor/Traktor/MultiTraktor.cs
Normal file
32
Traktor/Traktor/MultiTraktor.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Traktor
|
||||
{
|
||||
// Класс сущности "многофункциональный трактор"
|
||||
internal class MultiTraktor : EntityTraktor
|
||||
{
|
||||
/// Дополнительный цвет
|
||||
public Color DopColor { get; private set; }
|
||||
/// Признак наличия ковша спереди
|
||||
public bool KovshFront { get; private set; }
|
||||
/// Признак наличия ковша сзади
|
||||
public bool KovshBack { get; private set; }
|
||||
/// Инициализация свойств
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес трактора</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="kovshFront">Признак наличия ковша спереди</param>
|
||||
/// <param name="kovshBack">Признак наличия ковша сзади</param>
|
||||
public MultiTraktor(int speed, float weight, Color bodyColor, Color dopColor, bool kovshFront, bool kovshBack) : base(speed, weight, bodyColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
KovshFront = kovshFront;
|
||||
KovshBack = kovshBack;
|
||||
}
|
||||
}
|
||||
}
|
109
Traktor/Traktor/MultiTraktorDraw.cs
Normal file
109
Traktor/Traktor/MultiTraktorDraw.cs
Normal file
@ -0,0 +1,109 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Traktor
|
||||
{
|
||||
// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
internal class MultiTraktorDraw : TraktorDraw
|
||||
{
|
||||
/// Инициализация свойств
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес трактора</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="kovshFront">Признак наличия ковша спереди</param>
|
||||
/// <param name="kovshBack">Признак наличия ковша сзади</param>
|
||||
/// <param name="trktrWidth">Ширина отрисовки автомобиля</param>
|
||||
/// <param name="trktrHeight">Высота отрисовки автомобиля</param>
|
||||
public MultiTraktorDraw(int speed, float weight, Color bodyColor, Color dopColor, bool kovshFront, bool kovshBack) : base(speed, weight, bodyColor, 188, 100)
|
||||
{
|
||||
Traktor = new MultiTraktor(speed, weight, bodyColor, dopColor, kovshFront, kovshBack);
|
||||
}
|
||||
|
||||
public override void DrawEntity(Graphics g)
|
||||
{
|
||||
if (Traktor is not MultiTraktor multiTraktor)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen_Black_1pxl = new Pen(Color.Black, 1);
|
||||
Pen pen_Black_2pxl = new Pen(Color.Black, 2);
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
Brush dopBrush = new SolidBrush(multiTraktor.DopColor);
|
||||
|
||||
PointF point1;
|
||||
PointF point2;
|
||||
PointF point3;
|
||||
PointF point4;
|
||||
|
||||
bool Draw = false;
|
||||
if (multiTraktor.KovshBack)
|
||||
{
|
||||
g.DrawRectangle(pen_Black_1pxl, startPosX, startPosY + 8, 4, 35);
|
||||
g.DrawRectangle(pen_Black_1pxl, startPosX + 33, startPosY + 34, 10, 15);
|
||||
|
||||
point1 = new PointF(startPosX, startPosY + 8);
|
||||
point2 = new PointF(startPosX + 33, startPosY + 41);
|
||||
point3 = new PointF(startPosX + 33, startPosY + 34);
|
||||
point4 = new PointF(startPosX + 7, startPosY + 8);
|
||||
PointF[] curvePoints =
|
||||
{
|
||||
point1,
|
||||
point2,
|
||||
point3,
|
||||
point4
|
||||
};
|
||||
g.FillPolygon(dopBrush, curvePoints);
|
||||
g.DrawPolygon(pen_Black_1pxl, curvePoints);
|
||||
|
||||
point1 = new PointF(startPosX + 6, startPosY + 8 + 15);
|
||||
point2 = new PointF(startPosX + 6, startPosY + 8 + 35);
|
||||
point3 = new PointF(startPosX + 26, startPosY + 8 + 35);
|
||||
PointF[] curvePoints2 =
|
||||
{
|
||||
point1,
|
||||
point2,
|
||||
point3
|
||||
};
|
||||
g.FillPolygon(dopBrush, curvePoints2);
|
||||
g.DrawPolygon(pen_Black_1pxl, curvePoints2);
|
||||
|
||||
startPosX += 43;
|
||||
base.DrawEntity(g);
|
||||
startPosX -= 43;
|
||||
Draw = true;
|
||||
}
|
||||
|
||||
if (multiTraktor.KovshFront)
|
||||
{
|
||||
if (Draw)
|
||||
{
|
||||
point1 = new PointF(startPosX + 43 + 102, startPosY + 30);
|
||||
point2 = new PointF(startPosX + 43 + 102, startPosY + 65);
|
||||
point3 = new PointF(startPosX + 43 + 137, startPosY + 65);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
point1 = new PointF(startPosX + 102, startPosY + 30);
|
||||
point2 = new PointF(startPosX + 102, startPosY + 65);
|
||||
point3 = new PointF(startPosX + 137, startPosY + 65);
|
||||
base.DrawEntity(g);
|
||||
}
|
||||
PointF[] curvePoints =
|
||||
{
|
||||
point1,
|
||||
point2,
|
||||
point3
|
||||
};
|
||||
g.FillPolygon(dopBrush, curvePoints);
|
||||
g.DrawPolygon(pen_Black_1pxl, curvePoints);
|
||||
}
|
||||
if (!Draw) { base.DrawEntity(g); }
|
||||
}
|
||||
}
|
||||
}
|
@ -12,17 +12,17 @@ namespace Traktor
|
||||
internal class TraktorDraw
|
||||
{
|
||||
//Сущность
|
||||
public EntityTraktor Traktor { get; private set; }
|
||||
public EntityTraktor Traktor { get; protected set; }
|
||||
/// Левая координата отрисовки сущности
|
||||
private float startPosX;
|
||||
protected float startPosX;
|
||||
/// Верхняя кооридната отрисовки сущности
|
||||
private float startPosY;
|
||||
protected float startPosY;
|
||||
/// Ширина окна отрисовки
|
||||
private int? pictureWidth = null;
|
||||
/// Высота окна отрисовки
|
||||
private int? pictureHeight = null;
|
||||
/// Ширина отрисовки сущности
|
||||
private readonly int entWidth = 130;
|
||||
private readonly int entWidth = 115;
|
||||
/// Высота отрисовки сущности
|
||||
private readonly int entHeight = 100;
|
||||
|
||||
@ -30,6 +30,17 @@ namespace Traktor
|
||||
{
|
||||
Traktor = new EntityTraktor(speed, weight, bodycolor);
|
||||
}
|
||||
/// Инициализация свойств
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="trktrWidth">Ширина отрисовки автомобиля</param>
|
||||
/// <param name="trktrHeight">Высота отрисовки автомобиля</param>
|
||||
protected TraktorDraw(int speed, float weight, Color bodyColor, int trktrWidth, int trktrHeight) : this(speed, weight, bodyColor)
|
||||
{
|
||||
entWidth = trktrWidth;
|
||||
entHeight = trktrHeight;
|
||||
}
|
||||
|
||||
//Установка позиции сущности
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
@ -83,7 +94,7 @@ namespace Traktor
|
||||
}
|
||||
|
||||
//Отрисовка сущности
|
||||
public void DrawEntity(Graphics g)
|
||||
public virtual void DrawEntity(Graphics g)
|
||||
{
|
||||
if (startPosX < 0 || startPosY < 0 || !pictureHeight.HasValue || !pictureWidth.HasValue)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user