Komlev_S.I. Lab2 #4
69
GasolineTanker/GasolineTanker/DrawningGasolineTanker.cs
Normal file
69
GasolineTanker/GasolineTanker/DrawningGasolineTanker.cs
Normal file
@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GasolineTanker
|
||||
{
|
||||
internal class DrawningGasolineTanker : DrawningTanker
|
||||
{
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="Cabin">Признак наличия обвеса</param>
|
||||
/// <param name="Signal">Признак наличия антикрыла</param>
|
||||
/// <param name="BenzoBack">Признак наличия гоночной полосы</param>
|
||||
public DrawningGasolineTanker(int speed, float weight, Color bodyColor, Color dopColor, bool Cabin, bool Signal, bool BenzoBack) :
|
||||
base(speed, weight, bodyColor, 160, 125)
|
||||
{
|
||||
Tanker = new EntityGasolineTanker(speed, weight, bodyColor, dopColor, Cabin, Signal, BenzoBack);
|
||||
}
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (Tanker is not EntityGasolineTanker GasolineTanker)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_startPosX += 10;
|
||||
_startPosY += 5;
|
||||
base.DrawTransport(g);
|
||||
_startPosX -= 10;
|
||||
_startPosY -= 5;
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush dopBrush = new SolidBrush(GasolineTanker.DopColor);
|
||||
Brush WindowBrush = new SolidBrush(Color.LightBlue);
|
||||
|
||||
if (GasolineTanker.Cabin)
|
||||
{
|
||||
g.DrawRectangle(pen, _startPosX + 115, _startPosY + 29, 40, 25);
|
||||
g.FillEllipse(dopBrush, _startPosX + 143, _startPosY + 35, 10, 10);
|
||||
g.FillRectangle(WindowBrush, _startPosX + 116, _startPosY + 10, 39, 18);
|
||||
}
|
||||
|
||||
//_startPosX += 10;
|
||||
//_startPosY += 5;
|
||||
//base.DrawTransport(g);
|
||||
//_startPosX -= 10;
|
||||
//_startPosY -= 5;
|
||||
|
||||
//Бензобак
|
||||
if (GasolineTanker.BenzoBack)
|
||||
{
|
||||
g.FillEllipse(dopBrush, _startPosX+10, _startPosY+5, 100, 50);
|
||||
}
|
||||
//Сигналка
|
||||
if (GasolineTanker.Signal)
|
||||
{
|
||||
g.FillRectangle(dopBrush, _startPosX + 122, _startPosY - 1, 25, 6);
|
||||
g.FillEllipse(dopBrush, _startPosX + 124, _startPosY - 16, 20, 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -14,15 +14,15 @@ namespace GasolineTanker
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityTanker Tanker { get; private set; }
|
||||
public EntityTanker Tanker { get; protected set; }
|
||||
/// <summary>
|
||||
/// Левая координата отрисовки танкера
|
||||
/// </summary>
|
||||
private float _startPosX;
|
||||
protected float _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната отрисовки танкер
|
||||
/// </summary>
|
||||
private float _startPosY;
|
||||
protected float _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
@ -56,6 +56,20 @@ namespace GasolineTanker
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
|
||||
protected DrawningTanker(int speed, float weight, Color bodyColor, int carWidth, int carHeight) :
|
||||
this(speed, weight, bodyColor)
|
||||
{
|
||||
_TankerWidth = carWidth;
|
||||
_TankerHeight = carHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции автомобиля
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина картинки</param>
|
||||
/// <param name="height">Высота картинки</param>
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
{
|
||||
if (x + _TankerWidth <= width && y + _TankerHeight <= height && x >= 0 && y >= 0)
|
||||
@ -87,10 +101,6 @@ namespace GasolineTanker
|
||||
break;
|
||||
//влево
|
||||
case Direction.Left:
|
||||
//if (_startPosX + _TankerWidth + Tanker.Step < _pictureWidth)
|
||||
//{
|
||||
// _startPosX -= Tanker.Step;
|
||||
// }
|
||||
if (_startPosX - Tanker.Step > 0)
|
||||
{
|
||||
_startPosX -= Tanker.Step;
|
||||
@ -114,13 +124,11 @@ namespace GasolineTanker
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Отрисовка танкера
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (_startPosX < 0 || _startPosY < 0
|
||||
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
@ -133,22 +141,13 @@ namespace GasolineTanker
|
||||
Brush br = new SolidBrush(Tanker?.BodyColor ?? Color.Gray);
|
||||
g.FillRectangle(br, _startPosX + 100, _startPosY, 50, 60);
|
||||
g.FillRectangle(br, _startPosX, _startPosY+50, 100, 10);
|
||||
//Цесцерна
|
||||
//g.FillEllipse(br, _startPosX, _startPosY, 100, 50);
|
||||
|
||||
//стекла и двери
|
||||
//Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||
//g.FillRectangle(brBlue, _startPosX + 105, _startPosY + 5, 40, 20);
|
||||
//g.FillEllipse(brBlue, _startPosX + 130, _startPosY + 30, 10, 10);
|
||||
|
||||
//Колёса
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
g.FillEllipse(brBlack, _startPosX, _startPosY + 58, 40, 40);
|
||||
g.FillEllipse(brBlack, _startPosX + 40, _startPosY + 58, 40, 40);
|
||||
g.FillEllipse(brBlack, _startPosX + 110, _startPosY + 58, 40, 40);
|
||||
//Дверь
|
||||
//g.DrawRectangle(pen, _startPosX + 105, _startPosY + 25, 40, 25);
|
||||
//выделяем рамкой крышу
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Смена границ формы отрисовки
|
||||
|
46
GasolineTanker/GasolineTanker/EntityGasolineTanker.cs
Normal file
46
GasolineTanker/GasolineTanker/EntityGasolineTanker.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GasolineTanker
|
||||
{
|
||||
internal class EntityGasolineTanker : EntityTanker
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет
|
||||
/// </summary>
|
||||
public Color DopColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия обвеса
|
||||
/// </summary>
|
||||
public bool Cabin { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия антикрыла
|
||||
/// </summary>
|
||||
public bool Signal { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия гоночной полосы
|
||||
/// </summary>
|
||||
public bool BenzoBack { get; private set; }
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
/// <param name="dopColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Признак наличия обвеса</param>
|
||||
/// <param name="Signal">Признак наличия антикрыла</param>
|
||||
/// <param name="benzoBack">Признак наличия гоночной полосы</param>
|
||||
public EntityGasolineTanker(int speed, float weight, Color bodyColor, Color dopColor, bool сabin, bool signal, bool benzoBack) :
|
||||
base(speed, weight, bodyColor)
|
||||
{
|
||||
DopColor = dopColor;
|
||||
Cabin = сabin;
|
||||
Signal = signal;
|
||||
BenzoBack = benzoBack;
|
||||
}
|
||||
}
|
||||
}
|
13
GasolineTanker/GasolineTanker/FormTanker.Designer.cs
generated
13
GasolineTanker/GasolineTanker/FormTanker.Designer.cs
generated
@ -38,6 +38,7 @@
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTanker)).BeginInit();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
@ -143,11 +144,22 @@
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
//
|
||||
// buttonCreateModif
|
||||
//
|
||||
this.buttonCreateModif.Location = new System.Drawing.Point(93, 370);
|
||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||
this.buttonCreateModif.Size = new System.Drawing.Size(97, 32);
|
||||
this.buttonCreateModif.TabIndex = 7;
|
||||
this.buttonCreateModif.Text = "Модификация";
|
||||
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||
this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
|
||||
//
|
||||
// FormTanker
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(821, 429);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
this.Controls.Add(this.buttonLeft);
|
||||
@ -177,5 +189,6 @@
|
||||
private Button buttonLeft;
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonCreateModif;
|
||||
}
|
||||
}
|
@ -18,6 +18,17 @@ namespace GasolineTanker
|
||||
pictureBoxTanker.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Ìåòîä óñòàíîâêè äàííûõ
|
||||
/// </summary>
|
||||
private void SetData()
|
||||
{
|
||||
Random rnd = new();
|
||||
_Tanker.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxTanker.Width, pictureBoxTanker.Height);
|
||||
toolStripStatusSpeed.Text = $"Ñêîðîñòü: {_Tanker.Tanker.Speed}";
|
||||
toolStripStatusWeight.Text = $"Âåñ: {_Tanker.Tanker.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_Tanker.Tanker.BodyColor.Name}";
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
@ -27,10 +38,7 @@ namespace GasolineTanker
|
||||
{
|
||||
Random rnd = new();
|
||||
_Tanker = new DrawningTanker(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
_Tanker.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxTanker.Width, pictureBoxTanker.Height);
|
||||
toolStripStatusSpeed.Text = $"Ñêîðîñòü: {_Tanker.Tanker.Speed}";
|
||||
toolStripStatusWeight.Text = $"Âåñ: {_Tanker.Tanker.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_Tanker.Tanker.BodyColor.Name}";
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
@ -59,11 +67,30 @@ namespace GasolineTanker
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Èçìåíåíèå ðàçìåðîâ ôîðìû
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void pictureBoxTanker_Resize(object sender, EventArgs e)
|
||||
{
|
||||
_Tanker?.ChangeBorders(pictureBoxTanker.Width, pictureBoxTanker.Height);
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ìîäèôèêàöèÿ"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCreateModif_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random rnd = new();
|
||||
_Tanker = new DrawningGasolineTanker(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||
SetData();
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user