Lab3_DONE

This commit is contained in:
Itos 2024-10-03 00:40:53 +03:00
parent f0605b226a
commit c3152e4c34
21 changed files with 760 additions and 107 deletions

View File

@ -1,16 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectGasolineTanker
{
public enum DirectionType
{
Up = 1,
Down = 2,
Left = 3,
Right = 4
}
}

View File

@ -1,5 +1,4 @@
using ProjectGasolineTanker.DrawingObjects; using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -7,16 +6,19 @@ using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using ProjectGasolineTanker.Entities; using ProjectGasolineTanker.Entities;
namespace ProjectGasolineTanker namespace ProjectGasolineTanker.Drawings
{ {
public class DrawingGasolineTanker : DrawingTruck public class DrawingGasolineTanker : DrawingTruck
{ {
public DrawingGasolineTanker(int speed, double weight, Color bodyColor, Color additionalColor, bool tank, bool wheel, int width, int height) : base(speed, weight, bodyColor, width, height, 130, 70) public DrawingGasolineTanker(int speed, double weight, Color bodyColor, Color additionalColor, bool tank, bool wheel, int width, int height) : base(speed, weight, bodyColor, width, height, 130, 70)
{ {
if (EntityTruck != null) if (EntityTruck != null)
{ {
EntityTruck = new EntityGasolineTanker(speed, weight, bodyColor, additionalColor, tank, wheel); EntityTruck = new EntityGasolineTanker(speed, weight, bodyColor, additionalColor, tank, wheel);
} }
} }
public override void DrawTransport(Graphics g) public override void DrawTransport(Graphics g)
{ {
@ -25,15 +27,17 @@ namespace ProjectGasolineTanker
return; return;
} }
Pen pen = new(Color.Black); Pen pen = new(Color.Black);
Pen additionalPen = new(GasolineTanker.Body); Pen additionalPen = new(GasolineTanker.Add_Color);
Brush additionalBrush = new SolidBrush(GasolineTanker.Body); Brush additionalBrush = new SolidBrush(GasolineTanker.Add_Color);
base.DrawTransport(g); base.DrawTransport(g);
if (GasolineTanker.Tank) if (GasolineTanker.Tank)
{ {
g.FillRectangle(additionalBrush, _startPosX + 45, _startPosY + 53, 35, 20); g.FillRectangle(additionalBrush, _startPosX + 45, _startPosY + 53, 35, 20);
g.DrawLine(pen, _startPosX + 45, _startPosY + 53, _startPosX + 80, _startPosY + 73); g.DrawLine(pen, _startPosX + 45, _startPosY + 53, _startPosX + 80, _startPosY + 73);
g.DrawLine(pen, _startPosX + 80, _startPosY + 53, _startPosX + 45, _startPosY + 73); g.DrawLine(pen, _startPosX + 80, _startPosY + 53, _startPosX + 45, _startPosY + 73);
} }
if (GasolineTanker.Wheel) if (GasolineTanker.Wheel)
{ {
Brush gr = new SolidBrush(Color.Gray); Brush gr = new SolidBrush(Color.Gray);
@ -44,3 +48,4 @@ namespace ProjectGasolineTanker
} }
} }
} }

View File

@ -5,24 +5,40 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ProjectGasolineTanker.Entities; using ProjectGasolineTanker.Entities;
using ProjectGasolineTanker.MovementStratg;
namespace ProjectGasolineTanker.DrawingObjects namespace ProjectGasolineTanker.Drawings
{ {
public class DrawingTruck public class DrawingTruck
{ {
public IMoveableObject GetMoveableObject => new DrawingObjectTruck(this);
public EntityTruck? EntityTruck { get; protected set; } public EntityTruck? EntityTruck { get; protected set; }
private int _pictureWidth; private int _pictureWidth;
private int _pictureHeight; private int _pictureHeight;
protected int _startPosX; protected int _startPosX;
protected int _startPosY; protected int _startPosY;
protected readonly int _tankerWidth = 130; protected readonly int _tankerWidth = 130;
protected readonly int _tankerHeight = 70; protected readonly int _tankerHeight = 70;
public int GetPosX => _startPosX; public int GetPosX => _startPosX;
public int GetPosY => _startPosY; public int GetPosY => _startPosY;
public int GetWidth => _tankerWidth; public int GetWidth => _tankerWidth;
public int GetHeight => _tankerHeight; public int GetHeight => _tankerHeight;
public DrawingTruck(int speed, double weight, Color bodyColor, int width, int height) public DrawingTruck(int speed, double weight, Color bodyColor, int width, int height)
{ {
if (width < _tankerWidth || height < _tankerHeight) if (width < _tankerWidth || height < _tankerHeight)
{ {
return; return;
@ -31,8 +47,10 @@ namespace ProjectGasolineTanker.DrawingObjects
_pictureHeight = height; _pictureHeight = height;
EntityTruck = new EntityTruck(speed, weight, bodyColor); EntityTruck = new EntityTruck(speed, weight, bodyColor);
} }
protected DrawingTruck(int speed, double weight, Color bodyColor, int width, int height, int tankerWidth, int tankerHeight) protected DrawingTruck(int speed, double weight, Color bodyColor, int width, int height, int tankerWidth, int tankerHeight)
{ {
// TODO: Продумать проверки
if (width < _tankerWidth || height < _tankerHeight) if (width < _tankerWidth || height < _tankerHeight)
{ {
return; return;
@ -43,6 +61,7 @@ namespace ProjectGasolineTanker.DrawingObjects
_tankerHeight = tankerHeight; _tankerHeight = tankerHeight;
EntityTruck = new EntityTruck(speed, weight, bodyColor); EntityTruck = new EntityTruck(speed, weight, bodyColor);
} }
public void SetPosition(int x, int y) public void SetPosition(int x, int y)
{ {
if (x > _pictureWidth || y > _pictureHeight) if (x > _pictureWidth || y > _pictureHeight)
@ -52,6 +71,7 @@ namespace ProjectGasolineTanker.DrawingObjects
_startPosX = x; _startPosX = x;
_startPosY = y; _startPosY = y;
} }
public void MoveTransport(DirectionType direction) public void MoveTransport(DirectionType direction)
{ {
if (!CanMove(direction) || EntityTruck == null) if (!CanMove(direction) || EntityTruck == null)
@ -60,24 +80,28 @@ namespace ProjectGasolineTanker.DrawingObjects
} }
switch (direction) switch (direction)
{ {
//влево
case DirectionType.Left: case DirectionType.Left:
if (_startPosX - EntityTruck.Step > 0) if (_startPosX - EntityTruck.Step > 0)
{ {
_startPosX -= (int)EntityTruck.Step; _startPosX -= (int)EntityTruck.Step;
} }
break; break;
//вверх
case DirectionType.Up: case DirectionType.Up:
if (_startPosY - EntityTruck.Step > 0) if (_startPosY - EntityTruck.Step > 0)
{ {
_startPosY -= (int)EntityTruck.Step; _startPosY -= (int)EntityTruck.Step;
} }
break; break;
// вправо
case DirectionType.Right: case DirectionType.Right:
if (_startPosX + _tankerWidth + EntityTruck.Step < _pictureWidth) if (_startPosX + _tankerWidth + EntityTruck.Step < _pictureWidth)
{ {
_startPosX += (int)EntityTruck.Step; _startPosX += (int)EntityTruck.Step;
} }
break; break;
//вниз
case DirectionType.Down: case DirectionType.Down:
if (_startPosY + _tankerHeight + EntityTruck.Step < _pictureHeight) if (_startPosY + _tankerHeight + EntityTruck.Step < _pictureHeight)
{ {
@ -86,37 +110,54 @@ namespace ProjectGasolineTanker.DrawingObjects
break; break;
} }
} }
public virtual void DrawTransport(Graphics g) public virtual void DrawTransport(Graphics g)
{ {
Pen pen = new(Color.Black); Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(EntityTruck.BodyColor); Brush additionalBrush = new SolidBrush(EntityTruck.BodyColor);
g.FillRectangle(additionalBrush, _startPosX + 29, _startPosY + 11, 71, 28);
g.FillRectangle(additionalBrush, _startPosX + 29, _startPosY + 20, 71, 9); g.FillRectangle(additionalBrush, _startPosX + 29, _startPosY + 11, 71, 28); //канистра-бак
g.DrawRectangle(pen, _startPosX + 29, _startPosY + 11, 71, 28); g.FillRectangle(additionalBrush, _startPosX + 29, _startPosY + 20, 71, 9); //полосы
g.DrawRectangle(pen, _startPosX + 29, _startPosY + 20, 71, 9);
g.DrawRectangle(pen, _startPosX + 29, _startPosY + 11, 71, 28); //канистра-бак
g.DrawRectangle(pen, _startPosX + 29, _startPosY + 20, 71, 9); //полосы
Brush additionalBrush1 = new Brush additionalBrush1 = new
SolidBrush(EntityTruck.BodyColor); SolidBrush(EntityTruck.BodyColor);
//кабина
g.FillRectangle(additionalBrush1, _startPosX + 100, _startPosY + 10, 24, 16); g.FillRectangle(additionalBrush1, _startPosX + 100, _startPosY + 10, 24, 16);
g.FillRectangle(additionalBrush1, _startPosX + 124, _startPosY + 10, 9, 16); g.FillRectangle(additionalBrush1, _startPosX + 124, _startPosY + 10, 9, 16);
g.FillRectangle(additionalBrush1, _startPosX + 100, _startPosY + 10, 33, 16); g.FillRectangle(additionalBrush1, _startPosX + 100, _startPosY + 10, 33, 16);
g.FillRectangle(additionalBrush1, _startPosX + 100, _startPosY + 26, 33, 13); g.FillRectangle(additionalBrush1, _startPosX + 100, _startPosY + 26, 33, 13);
g.DrawLine(pen, _startPosX + 100, _startPosY + 26, _startPosX + 133, _startPosY + 39); g.DrawLine(pen, _startPosX + 100, _startPosY + 26, _startPosX + 133, _startPosY + 39);
g.DrawRectangle(pen, _startPosX + 100, _startPosY + 10, 24, 16); g.DrawRectangle(pen, _startPosX + 100, _startPosY + 10, 24, 16);
g.DrawRectangle(pen, _startPosX + 124, _startPosY + 10, 9, 16); g.DrawRectangle(pen, _startPosX + 124, _startPosY + 10, 9, 16);
g.DrawRectangle(pen, _startPosX + 100, _startPosY + 10, 33, 16); g.DrawRectangle(pen, _startPosX + 100, _startPosY + 10, 33, 16);
g.DrawRectangle(pen, _startPosX + 100, _startPosY + 26, 33, 13); g.DrawRectangle(pen, _startPosX + 100, _startPosY + 26, 33, 13);
Brush additionalBrush2 = new Brush additionalBrush2 = new
SolidBrush(EntityTruck.BodyColor); SolidBrush(EntityTruck.BodyColor);
g.FillRectangle(additionalBrush2, _startPosX + 4, _startPosY + 40, 130, 25); g.FillRectangle(additionalBrush2, _startPosX + 4, _startPosY + 40, 130, 25);
g.DrawLine(pen, _startPosX + 4, _startPosY + 65, _startPosX + 25, _startPosY + 40); g.DrawLine(pen, _startPosX + 4, _startPosY + 65, _startPosX + 25, _startPosY + 40);
//колёса
Brush gr = new SolidBrush(Color.Gray); Brush gr = new SolidBrush(Color.Gray);
g.FillEllipse(additionalBrush, _startPosX + 15, _startPosY + 50, 26, 26); g.FillEllipse(additionalBrush, _startPosX + 15, _startPosY + 50, 26, 26);
g.FillEllipse(additionalBrush, _startPosX + 110, _startPosY + 55, 22, 22); g.FillEllipse(additionalBrush, _startPosX + 110, _startPosY + 55, 22, 22);
g.FillEllipse(gr, _startPosX + 18, _startPosY + 53, 20, 20); g.FillEllipse(gr, _startPosX + 18, _startPosY + 53, 20, 20);
g.FillEllipse(gr, _startPosX + 112, _startPosY + 57, 18, 18); g.FillEllipse(gr, _startPosX + 112, _startPosY + 57, 18, 18);
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 50, 26, 26); g.DrawEllipse(pen, _startPosX + 15, _startPosY + 50, 26, 26);
g.DrawEllipse(pen, _startPosX + 110, _startPosY + 55, 22, 22); g.DrawEllipse(pen, _startPosX + 110, _startPosY + 55, 22, 22);
} }
public bool CanMove(DirectionType direction) public bool CanMove(DirectionType direction)
{ {
if (EntityTruck == null) if (EntityTruck == null)
@ -125,12 +166,17 @@ namespace ProjectGasolineTanker.DrawingObjects
} }
return direction switch return direction switch
{ {
//влево
DirectionType.Left => _startPosX - EntityTruck.Step > 0, DirectionType.Left => _startPosX - EntityTruck.Step > 0,
//вверх
DirectionType.Up => _startPosY - EntityTruck.Step > 0, DirectionType.Up => _startPosY - EntityTruck.Step > 0,
DirectionType.Right => _startPosX + _tankerWidth + EntityTruck.Step < _pictureWidth, // вправо
DirectionType.Down => _startPosY + _tankerHeight + EntityTruck.Step < _pictureHeight, DirectionType.Right => _startPosX + _tankerWidth + EntityTruck.Step < _pictureWidth,// TODO: Продумать логику
//вниз
DirectionType.Down => _startPosY + _tankerHeight + EntityTruck.Step < _pictureHeight,// TODO: Продумать логику
_ => false, _ => false,
}; };
} }
} }
} }

View File

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectGasolineTanker.Entities
{
/// <summary>
/// Направление перемещения
/// </summary>
public enum DirectionType
{
/// <summary>
/// Вверх
/// </summary>
Up = 1,
/// <summary>
/// Вниз
/// </summary>
Down = 2,
/// <summary>
/// Влево
/// </summary>
Left = 3,
/// <summary>
/// Вправо
/// </summary>
Right = 4
}
}

View File

@ -7,16 +7,22 @@ using System.Threading.Tasks;
namespace ProjectGasolineTanker.Entities namespace ProjectGasolineTanker.Entities
{ {
public class EntityGasolineTanker : EntityTruck public class EntityGasolineTanker : EntityTruck
{ {
public Color Body { get; private set; }
public Color Add_Color { get; private set; }
public bool Tank { get; private set; } public bool Tank { get; private set; }
public bool Wheel { get; private set; } public bool Wheel { get; private set; }
public EntityGasolineTanker(int speed, double weight, Color bodyColor, Color additionalColor, bool tank, bool wheel) : base(speed, weight, bodyColor) public EntityGasolineTanker(int speed, double weight, Color bodyColor, Color additionalColor, bool tank, bool wheel) : base(speed, weight, bodyColor)
{ {
Body = additionalColor; Add_Color = additionalColor;
Tank = tank; Tank = tank;
Wheel = wheel; Wheel = wheel;
} }
} }
} }

View File

@ -6,17 +6,24 @@ using System.Threading.Tasks;
namespace ProjectGasolineTanker.Entities namespace ProjectGasolineTanker.Entities
{ {
public class EntityTruck public class EntityTruck
{ {
public int Speed { get; private set; } public int Speed { get; private set; }
public double Weight { get; private set; } public double Weight { get; private set; }
public Color BodyColor { get; private set; } public Color BodyColor { get; private set; }
public double Step => (double)Speed * 100 / Weight; public double Step => (double)Speed * 100 / Weight;
public EntityTruck(int speed, double weight, Color bodyColor) public EntityTruck(int speed, double weight, Color bodyColor)
{ {
Speed = speed; Speed = speed;
Weight = weight; Weight = weight;
BodyColor = bodyColor; BodyColor = bodyColor;
} }
} }
} }

View File

@ -37,6 +37,7 @@
this.comboBoxStrategy = new System.Windows.Forms.ComboBox(); this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
this.buttonStep = new System.Windows.Forms.Button(); this.buttonStep = new System.Windows.Forms.Button();
this.buttonCreateTruck = new System.Windows.Forms.Button(); this.buttonCreateTruck = new System.Windows.Forms.Button();
this.buttonSelect = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxGasolineTanker)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxGasolineTanker)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
@ -44,9 +45,8 @@
// //
this.pictureBoxGasolineTanker.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBoxGasolineTanker.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxGasolineTanker.Location = new System.Drawing.Point(0, 0); this.pictureBoxGasolineTanker.Location = new System.Drawing.Point(0, 0);
this.pictureBoxGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.pictureBoxGasolineTanker.Name = "pictureBoxGasolineTanker"; this.pictureBoxGasolineTanker.Name = "pictureBoxGasolineTanker";
this.pictureBoxGasolineTanker.Size = new System.Drawing.Size(772, 340); this.pictureBoxGasolineTanker.Size = new System.Drawing.Size(882, 453);
this.pictureBoxGasolineTanker.TabIndex = 5; this.pictureBoxGasolineTanker.TabIndex = 5;
this.pictureBoxGasolineTanker.TabStop = false; this.pictureBoxGasolineTanker.TabStop = false;
// //
@ -54,24 +54,22 @@
// //
this.buttonCreateGasolineTanker.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonCreateGasolineTanker.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreateGasolineTanker.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); this.buttonCreateGasolineTanker.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.buttonCreateGasolineTanker.Location = new System.Drawing.Point(10, 274); this.buttonCreateGasolineTanker.Location = new System.Drawing.Point(11, 365);
this.buttonCreateGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonCreateGasolineTanker.Name = "buttonCreateGasolineTanker"; this.buttonCreateGasolineTanker.Name = "buttonCreateGasolineTanker";
this.buttonCreateGasolineTanker.Size = new System.Drawing.Size(105, 55); this.buttonCreateGasolineTanker.Size = new System.Drawing.Size(120, 73);
this.buttonCreateGasolineTanker.TabIndex = 6; this.buttonCreateGasolineTanker.TabIndex = 6;
this.buttonCreateGasolineTanker.Text = "Создать газовоз"; this.buttonCreateGasolineTanker.Text = "Создать газовоз";
this.buttonCreateGasolineTanker.UseVisualStyleBackColor = true; this.buttonCreateGasolineTanker.UseVisualStyleBackColor = true;
this.buttonCreateGasolineTanker.Click += new System.EventHandler(this.buttonCreateGasolineTanker_Click); this.buttonCreateGasolineTanker.Click += new System.EventHandler(this.buttonCreateProjectGasolineTanker_Click);
// //
// buttonUp // buttonUp
// //
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::ProjectGasolineTanker.Properties.Resources.стрелка_вверх; this.buttonUp.BackgroundImage = global::ProjectGasolineTanker.Properties.Resources.стрелка_вверх;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonUp.Location = new System.Drawing.Point(710, 283); this.buttonUp.Location = new System.Drawing.Point(811, 377);
this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonUp.Name = "buttonUp"; this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(26, 22); this.buttonUp.Size = new System.Drawing.Size(30, 29);
this.buttonUp.TabIndex = 7; this.buttonUp.TabIndex = 7;
this.buttonUp.UseVisualStyleBackColor = true; this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click); this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
@ -81,10 +79,9 @@
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::ProjectGasolineTanker.Properties.Resources.стрелка_влево; this.buttonLeft.BackgroundImage = global::ProjectGasolineTanker.Properties.Resources.стрелка_влево;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonLeft.Location = new System.Drawing.Point(679, 310); this.buttonLeft.Location = new System.Drawing.Point(776, 413);
this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(26, 22); this.buttonLeft.Size = new System.Drawing.Size(30, 29);
this.buttonLeft.TabIndex = 8; this.buttonLeft.TabIndex = 8;
this.buttonLeft.UseVisualStyleBackColor = true; this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click); this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click);
@ -94,10 +91,9 @@
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::ProjectGasolineTanker.Properties.Resources.стрелка_вниз; this.buttonDown.BackgroundImage = global::ProjectGasolineTanker.Properties.Resources.стрелка_вниз;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonDown.Location = new System.Drawing.Point(710, 310); this.buttonDown.Location = new System.Drawing.Point(811, 413);
this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonDown.Name = "buttonDown"; this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(26, 22); this.buttonDown.Size = new System.Drawing.Size(30, 29);
this.buttonDown.TabIndex = 9; this.buttonDown.TabIndex = 9;
this.buttonDown.UseVisualStyleBackColor = true; this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click); this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
@ -107,10 +103,9 @@
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::ProjectGasolineTanker.Properties.Resources.стрелка_вправо; this.buttonRight.BackgroundImage = global::ProjectGasolineTanker.Properties.Resources.стрелка_вправо;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonRight.Location = new System.Drawing.Point(742, 310); this.buttonRight.Location = new System.Drawing.Point(848, 413);
this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonRight.Name = "buttonRight"; this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(26, 22); this.buttonRight.Size = new System.Drawing.Size(30, 29);
this.buttonRight.TabIndex = 10; this.buttonRight.TabIndex = 10;
this.buttonRight.UseVisualStyleBackColor = true; this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click); this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
@ -123,19 +118,17 @@
this.comboBoxStrategy.Items.AddRange(new object[] { this.comboBoxStrategy.Items.AddRange(new object[] {
"В центр", "В центр",
"В правый нижний угол"}); "В правый нижний угол"});
this.comboBoxStrategy.Location = new System.Drawing.Point(629, 9); this.comboBoxStrategy.Location = new System.Drawing.Point(719, 12);
this.comboBoxStrategy.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.comboBoxStrategy.Name = "comboBoxStrategy"; this.comboBoxStrategy.Name = "comboBoxStrategy";
this.comboBoxStrategy.Size = new System.Drawing.Size(133, 23); this.comboBoxStrategy.Size = new System.Drawing.Size(151, 28);
this.comboBoxStrategy.TabIndex = 11; this.comboBoxStrategy.TabIndex = 11;
// //
// buttonStep // buttonStep
// //
this.buttonStep.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.buttonStep.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonStep.Location = new System.Drawing.Point(654, 34); this.buttonStep.Location = new System.Drawing.Point(747, 45);
this.buttonStep.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonStep.Name = "buttonStep"; this.buttonStep.Name = "buttonStep";
this.buttonStep.Size = new System.Drawing.Size(82, 22); this.buttonStep.Size = new System.Drawing.Size(94, 29);
this.buttonStep.TabIndex = 12; this.buttonStep.TabIndex = 12;
this.buttonStep.Text = "Шаг"; this.buttonStep.Text = "Шаг";
this.buttonStep.UseVisualStyleBackColor = true; this.buttonStep.UseVisualStyleBackColor = true;
@ -144,20 +137,31 @@
// buttonCreateTruck // buttonCreateTruck
// //
this.buttonCreateTruck.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonCreateTruck.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreateTruck.Location = new System.Drawing.Point(121, 291); this.buttonCreateTruck.Location = new System.Drawing.Point(138, 388);
this.buttonCreateTruck.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonCreateTruck.Name = "buttonCreateTruck"; this.buttonCreateTruck.Name = "buttonCreateTruck";
this.buttonCreateTruck.Size = new System.Drawing.Size(105, 38); this.buttonCreateTruck.Size = new System.Drawing.Size(120, 51);
this.buttonCreateTruck.TabIndex = 13; this.buttonCreateTruck.TabIndex = 13;
this.buttonCreateTruck.Text = "Создать грузовик"; this.buttonCreateTruck.Text = "Создать грузовик";
this.buttonCreateTruck.UseVisualStyleBackColor = true; this.buttonCreateTruck.UseVisualStyleBackColor = true;
this.buttonCreateTruck.Click += new System.EventHandler(this.buttonCreateTruck_Click); this.buttonCreateTruck.Click += new System.EventHandler(this.buttonCreateTruck_Click);
// //
// buttonSelect
//
this.buttonSelect.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonSelect.Location = new System.Drawing.Point(264, 365);
this.buttonSelect.Name = "buttonSelect";
this.buttonSelect.Size = new System.Drawing.Size(120, 74);
this.buttonSelect.TabIndex = 14;
this.buttonSelect.Text = "Выбрать грузовик";
this.buttonSelect.UseVisualStyleBackColor = true;
this.buttonSelect.Click += new System.EventHandler(this.ButtonSelectTruck_Click);
//
// FormGasolineTanker // FormGasolineTanker
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(772, 340); this.ClientSize = new System.Drawing.Size(882, 453);
this.Controls.Add(this.buttonSelect);
this.Controls.Add(this.buttonCreateTruck); this.Controls.Add(this.buttonCreateTruck);
this.Controls.Add(this.buttonStep); this.Controls.Add(this.buttonStep);
this.Controls.Add(this.comboBoxStrategy); this.Controls.Add(this.comboBoxStrategy);
@ -167,7 +171,6 @@
this.Controls.Add(this.buttonUp); this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonCreateGasolineTanker); this.Controls.Add(this.buttonCreateGasolineTanker);
this.Controls.Add(this.pictureBoxGasolineTanker); this.Controls.Add(this.pictureBoxGasolineTanker);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FormGasolineTanker"; this.Name = "FormGasolineTanker";
this.Text = "GasolineTanker"; this.Text = "GasolineTanker";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxGasolineTanker)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxGasolineTanker)).EndInit();
@ -186,5 +189,6 @@
private ComboBox comboBoxStrategy; private ComboBox comboBoxStrategy;
private Button buttonStep; private Button buttonStep;
private Button buttonCreateTruck; private Button buttonCreateTruck;
private Button buttonSelect;
} }
} }

View File

@ -1,16 +1,26 @@
using ProjectGasolineTanker.DrawingObjects; using ProjectGasolineTanker.Drawings;
using ProjectGasolineTanker.MovementStrategy; using ProjectGasolineTanker.Entities;
using ProjectGasolineTanker.MovementStratg;
namespace ProjectGasolineTanker namespace ProjectGasolineTanker
{ {
public partial class FormGasolineTanker : Form public partial class FormGasolineTanker : Form
{ {
private DrawingTruck? _drawingTruck; private DrawingTruck? _drawingTruck;
private AbstractStrategy? _abstractStrategy; private AbstractStrategy? _abstractStrategy;
public DrawingTruck? SelectedTruck { get; private set; }
public FormGasolineTanker() public FormGasolineTanker()
{ {
InitializeComponent(); InitializeComponent();
_abstractStrategy = null;
SelectedTruck = null;
} }
private void Draw() private void Draw()
{ {
if (_drawingTruck == null) if (_drawingTruck == null)
@ -21,34 +31,51 @@ namespace ProjectGasolineTanker
Graphics gr = Graphics.FromImage(bmp); Graphics gr = Graphics.FromImage(bmp);
_drawingTruck.DrawTransport(gr); _drawingTruck.DrawTransport(gr);
pictureBoxGasolineTanker.Image = bmp; pictureBoxGasolineTanker.Image = bmp;
} }
private void buttonCreateGasolineTanker_Click(object sender, EventArgs e)
private void buttonCreateProjectGasolineTanker_Click(object sender, EventArgs e)
{ {
Random random = new(); Random random = new();
Color color = Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256));
Color color1 = Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
ColorDialog dialog1 = new();
if (dialog.ShowDialog() == DialogResult.OK && dialog1.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
color1 = dialog1.Color;
}
_drawingTruck = new DrawingGasolineTanker(random.Next(100, 300), _drawingTruck = new DrawingGasolineTanker(random.Next(100, 300),
random.Next(1000, 3000), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), color, color1,
random.Next(0, 256)), true, true,
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)),
pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height); pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height);
_drawingTruck.SetPosition(random.Next(10, 100), random.Next(10, 100)); _drawingTruck.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw(); Draw();
} }
private void buttonCreateTruck_Click(object sender, EventArgs e) private void buttonCreateTruck_Click(object sender, EventArgs e)
{ {
Random random = new(); Random random = new();
Color color = Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_drawingTruck = new DrawingTruck(random.Next(100, 300), _drawingTruck = new DrawingTruck(random.Next(100, 300),
random.Next(1000, 3000), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), color,
random.Next(0, 256)),
pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height); pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height);
_drawingTruck.SetPosition(random.Next(10, 100), random.Next(10, 100)); _drawingTruck.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw(); Draw();
} }
private void buttonMove_Click(object sender, EventArgs e) private void buttonMove_Click(object sender, EventArgs e)
{ {
if (_drawingTruck == null) if (_drawingTruck == null)
@ -73,6 +100,7 @@ namespace ProjectGasolineTanker
} }
Draw(); Draw();
} }
private void buttonStep_Click(object sender, EventArgs e) private void buttonStep_Click(object sender, EventArgs e)
{ {
if (_drawingTruck == null) if (_drawingTruck == null)
@ -107,5 +135,10 @@ namespace ProjectGasolineTanker
_abstractStrategy = null; _abstractStrategy = null;
} }
} }
private void ButtonSelectTruck_Click(object sender, EventArgs e)
{
SelectedTruck = _drawingTruck;
DialogResult = DialogResult.OK;
}
} }
} }

View File

@ -0,0 +1,128 @@
namespace ProjectGasolineTanker
{
partial class FormTruckCollection
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
this.labelInstruments = new System.Windows.Forms.Label();
this.buttonAdd = new System.Windows.Forms.Button();
this.maskedTextBoxNumber = new System.Windows.Forms.TextBox();
this.buttonDelete = new System.Windows.Forms.Button();
this.buttonUpdate = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
this.SuspendLayout();
//
// pictureBoxCollection
//
this.pictureBoxCollection.Location = new System.Drawing.Point(2, 1);
this.pictureBoxCollection.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.pictureBoxCollection.Name = "pictureBoxCollection";
this.pictureBoxCollection.Size = new System.Drawing.Size(803, 376);
this.pictureBoxCollection.TabIndex = 0;
this.pictureBoxCollection.TabStop = false;
//
// labelInstruments
//
this.labelInstruments.AutoSize = true;
this.labelInstruments.Location = new System.Drawing.Point(852, 22);
this.labelInstruments.Name = "labelInstruments";
this.labelInstruments.Size = new System.Drawing.Size(83, 15);
this.labelInstruments.TabIndex = 1;
this.labelInstruments.Text = "Инструменты";
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(840, 64);
this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(161, 44);
this.buttonAdd.TabIndex = 2;
this.buttonAdd.Text = "Добавить грузовик";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAddTruck_Click);
//
// maskedTextBoxNumber
//
this.maskedTextBoxNumber.Location = new System.Drawing.Point(874, 140);
this.maskedTextBoxNumber.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
this.maskedTextBoxNumber.Size = new System.Drawing.Size(110, 23);
this.maskedTextBoxNumber.TabIndex = 3;
//
// buttonDelete
//
this.buttonDelete.Location = new System.Drawing.Point(840, 167);
this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonDelete.Name = "buttonDelete";
this.buttonDelete.Size = new System.Drawing.Size(165, 45);
this.buttonDelete.TabIndex = 4;
this.buttonDelete.Text = "Удалить грузовик";
this.buttonDelete.UseVisualStyleBackColor = true;
this.buttonDelete.Click += new System.EventHandler(this.ButtonRemoveTruck_Click);
//
// buttonUpdate
//
this.buttonUpdate.Location = new System.Drawing.Point(840, 260);
this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonUpdate.Name = "buttonUpdate";
this.buttonUpdate.Size = new System.Drawing.Size(165, 45);
this.buttonUpdate.TabIndex = 5;
this.buttonUpdate.Text = "Обновить";
this.buttonUpdate.UseVisualStyleBackColor = true;
this.buttonUpdate.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
//
// FormTruckCollection
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1152, 382);
this.Controls.Add(this.buttonUpdate);
this.Controls.Add(this.buttonDelete);
this.Controls.Add(this.maskedTextBoxNumber);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.labelInstruments);
this.Controls.Add(this.pictureBoxCollection);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FormTruckCollection";
this.Text = "Грузовик";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private PictureBox pictureBoxCollection;
private Label labelInstruments;
private Button buttonAdd;
private TextBox maskedTextBoxNumber;
private Button buttonDelete;
private Button buttonUpdate;
}
}

View File

@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ProjectGasolineTanker.Drawings;
using ProjectGasolineTanker.Generic;
using ProjectGasolineTanker.MovementStratg;
namespace ProjectGasolineTanker
{
public partial class FormTruckCollection : Form
{
private readonly TruckGenericCollection<DrawingTruck, DrawingObjectTruck> _truck;
public FormTruckCollection()
{
InitializeComponent();
_truck = new TruckGenericCollection<DrawingTruck, DrawingObjectTruck>(pictureBoxCollection.Width, pictureBoxCollection.Height);
}
private void ButtonAddTruck_Click(object sender, EventArgs e)
{
FormGasolineTanker form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (_truck + form.SelectedTruck != -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = _truck.ShowTruck();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
private void ButtonRemoveTruck_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = 0;
try
{
pos = Convert.ToInt32(maskedTextBoxNumber.Text) ;
}
catch
{
MessageBox.Show("Ошибка ввода данных");
return;
}
if (_truck - (_truck.ReturnLength() - pos))
{
MessageBox.Show("Объект удален");
pictureBoxCollection.Image = _truck.ShowTruck();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
private void ButtonRefreshCollection_Click(object sender, EventArgs
e)
{
pictureBoxCollection.Image = _truck.ShowTruck();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,106 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectGasolineTanker.Generic
{
internal class SetGeneric<T>
where T : class
{
private readonly T?[] _places;
public int Count => _places.Length - 1;
public SetGeneric(int count)
{
_places = new T?[count];
}
public int Insert(T truck)
{
int pos = Count - 1;
if (_places[Count] != null)
{
for (int i = pos; i > 0; --i)
{
if (_places[i] == null)
{
pos = i;
break;
}
}
for (int i = pos + 1; i <= Count; ++i)
{
_places[i - 1] = _places[i];
}
}
_places[Count] = truck;
return pos;
}
public bool Insert(T truck, int position)
{
// TODO проверка позиции
if (position < 0 || position > Count)
{
return false;
}
if (_places[Count] != null)
{
int pos = Count;
for (int i = Count; i > 0; --i)
{
if (_places[i] == null)
{
pos = i;
break;
}
}
for (int i = Count; i >= pos; --i)
{
_places[i - 1] = _places[i];
}
}
_places[Count] = truck;
return true;
}
public bool Remove(int position)
{
if (position < 0 || position > Count)
{
return false;
}
_places[position] = null;
return true;
}
public T? Get(int position)
{
if (position < 0 || position > Count)
{
return null;
}
return _places[position];
}
}
}

View File

@ -0,0 +1,120 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectGasolineTanker.Drawings;
using ProjectGasolineTanker.MovementStratg;
namespace ProjectGasolineTanker.Generic
{
internal class TruckGenericCollection<T, U>
where T : DrawingTruck
where U : IMoveableObject
{
private readonly int _pictureWidth;
private readonly int _pictureHeight;
private readonly int _placeSizeWidth = 200;
private readonly int _placeSizeHeight = 80;
private readonly SetGeneric<T> _collection;
public TruckGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = new SetGeneric<T>(width * height);
}
public static int operator +(TruckGenericCollection<T, U> collect, T? obj)
{
if (obj != null)
{
return collect._collection.Insert(obj);
}
return -1;
}
public static bool operator -(TruckGenericCollection<T, U> collect, int pos)
{
if (collect._collection.Get(pos) == null)
{
return false;
}
return collect?._collection.Remove(pos) ?? false;
}
public int ReturnLength()
{
return _collection.Count;
}
public U? GetU(int pos)
{
return (U?)_collection.Get(pos)?.GetMoveableObject;
}
public Bitmap ShowTruck()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawObjects(gr);
return bmp;
}
private void DrawBackground(Graphics gr)
{
Pen pen = new(Color.Black, 3);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; ++i)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
{
gr.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
gr.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
}
private void DrawObjects(Graphics g)
{
int x = 0;
int y = 0;
int index = -1;
for (int i = 0; i <= _collection.Count; ++i)
{
DrawingTruck _truck = _collection.Get(i);
x = 0;
y = 0;
if (_truck != null)
{
index = i;
while (index - _pictureWidth / _placeSizeWidth >= 0)
{
y++;
index -= _pictureWidth / _placeSizeWidth;
}
if (index > 0)
{
x += index;
}
x = _pictureWidth / _placeSizeWidth - 1 - x;
_truck.SetPosition(_placeSizeWidth * x, _placeSizeHeight * y);
_truck.DrawTransport(g);
}
}
}
}
}

View File

@ -1,22 +1,27 @@
using ProjectGasolineTanker.MovementStrategy; using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using static System.Windows.Forms.VisualStyles.VisualStyleElement; using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using ProjectGasolineTanker.Drawings;
using ProjectGasolineTanker.Entities;
using ProjectGasolineTanker.DrawingObjects; namespace ProjectGasolineTanker.MovementStratg
namespace ProjectGasolineTanker.MovementStrategy
{ {
public abstract class AbstractStrategy public abstract class AbstractStrategy
{ {
private IMoveableObject? _moveableObject; private IMoveableObject? _moveableObject;
private Status _state = Status.NotInit; private Status _state = Status.NotInit;
protected int FieldWidth { get; private set; } protected int FieldWidth { get; private set; }
protected int FieldHeight { get; private set; } protected int FieldHeight { get; private set; }
public Status GetStatus() { return _state; } public Status GetStatus() { return _state; }
public void SetData(IMoveableObject moveableObject, int width, int height) public void SetData(IMoveableObject moveableObject, int width, int height)
{ {
if (moveableObject == null) if (moveableObject == null)
@ -29,6 +34,7 @@ namespace ProjectGasolineTanker.MovementStrategy
FieldWidth = width; FieldWidth = width;
FieldHeight = height; FieldHeight = height;
} }
public void MakeStep() public void MakeStep()
{ {
if (_state != Status.InProgress) if (_state != Status.InProgress)
@ -42,11 +48,17 @@ namespace ProjectGasolineTanker.MovementStrategy
} }
MoveToTarget(); MoveToTarget();
} }
protected bool MoveLeft() => MoveTo(DirectionType.Left); protected bool MoveLeft() => MoveTo(DirectionType.Left);
protected bool MoveRight() => MoveTo(DirectionType.Right); protected bool MoveRight() => MoveTo(DirectionType.Right);
protected bool MoveUp() => MoveTo(DirectionType.Up); protected bool MoveUp() => MoveTo(DirectionType.Up);
protected bool MoveDown() => MoveTo(DirectionType.Down); protected bool MoveDown() => MoveTo(DirectionType.Down);
protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition; protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
protected int? GetStep() protected int? GetStep()
{ {
if (_state != Status.InProgress) if (_state != Status.InProgress)
@ -55,8 +67,11 @@ namespace ProjectGasolineTanker.MovementStrategy
} }
return _moveableObject?.GetStep; return _moveableObject?.GetStep;
} }
protected abstract void MoveToTarget(); protected abstract void MoveToTarget();
protected abstract bool IsTargetDestinaion(); protected abstract bool IsTargetDestinaion();
private bool MoveTo(DirectionType directionType) private bool MoveTo(DirectionType directionType)
{ {
if (_state != Status.InProgress) if (_state != Status.InProgress)
@ -71,4 +86,8 @@ namespace ProjectGasolineTanker.MovementStrategy
return false; return false;
} }
} }
} }

View File

@ -1,15 +1,15 @@
using ProjectGasolineTanker.MovementStrategy; using System;
using ProjectGasolineTanker;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ProjectGasolineTanker.Drawings;
using ProjectGasolineTanker.Entities;
using ProjectGasolineTanker.DrawingObjects; namespace ProjectGasolineTanker.MovementStratg
namespace ProjectGasolineTanker.MovementStrategy
{ {
public class DrawingObjectTruck : IMoveableObject public class DrawingObjectTruck : IMoveableObject
{ {
private readonly DrawingTruck? _drawingTruck = null; private readonly DrawingTruck? _drawingTruck = null;
@ -25,7 +25,7 @@ namespace ProjectGasolineTanker.MovementStrategy
{ {
return null; return null;
} }
return new ObjectParameters(_drawingTruck.GetPosX,_drawingTruck.GetPosY, _drawingTruck.GetWidth, _drawingTruck.GetHeight); return new ObjectParameters(_drawingTruck.GetPosX, _drawingTruck.GetPosY, _drawingTruck.GetWidth, _drawingTruck.GetHeight);
} }
} }
public int GetStep => (int)(_drawingTruck?.EntityTruck?.Step ?? 0); public int GetStep => (int)(_drawingTruck?.EntityTruck?.Step ?? 0);
@ -33,3 +33,4 @@ namespace ProjectGasolineTanker.MovementStrategy
public void MoveObject(DirectionType direction) => _drawingTruck?.MoveTransport(direction); public void MoveObject(DirectionType direction) => _drawingTruck?.MoveTransport(direction);
} }
} }

View File

@ -4,15 +4,23 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ProjectGasolineTanker.DrawingObjects; using ProjectGasolineTanker.Drawings;
using ProjectGasolineTanker.Entities;
namespace ProjectGasolineTanker.MovementStrategy namespace ProjectGasolineTanker.MovementStratg
{ {
public interface IMoveableObject public interface IMoveableObject
{ {
ObjectParameters? GetObjectPosition { get; } ObjectParameters? GetObjectPosition { get; }
int GetStep { get; } int GetStep { get; }
bool CheckCanMove(DirectionType direction); bool CheckCanMove(DirectionType direction);
void MoveObject(DirectionType direction); void MoveObject(DirectionType direction);
} }
} }

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ProjectGasolineTanker.MovementStrategy namespace ProjectGasolineTanker.MovementStratg
{ {
internal class MoveToBorder : AbstractStrategy internal class MoveToBorder : AbstractStrategy
{ {

View File

@ -4,8 +4,9 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ProjectGasolineTanker.MovementStrategy namespace ProjectGasolineTanker.MovementStratg
{ {
public class MoveToCenter : AbstractStrategy public class MoveToCenter : AbstractStrategy
{ {
protected override bool IsTargetDestinaion() protected override bool IsTargetDestinaion()

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ProjectGasolineTanker.MovementStrategy namespace ProjectGasolineTanker.MovementStratg
{ {
public class ObjectParameters public class ObjectParameters
{ {
@ -12,12 +12,19 @@ namespace ProjectGasolineTanker.MovementStrategy
private readonly int _y; private readonly int _y;
private readonly int _width; private readonly int _width;
private readonly int _height; private readonly int _height;
public int LeftBorder => _x; public int LeftBorder => _x;
public int TopBorder => _y; public int TopBorder => _y;
public int RightBorder => _x + _width; public int RightBorder => _x + _width;
public int DownBorder => _y + _height; public int DownBorder => _y + _height;
public int ObjectMiddleHorizontal => _x + _width / 2; public int ObjectMiddleHorizontal => _x + _width / 2;
public int ObjectMiddleVertical => _y + _height / 2; public int ObjectMiddleVertical => _y + _height / 2;
public ObjectParameters(int x, int y, int width, int height) public ObjectParameters(int x, int y, int width, int height)
{ {
_x = x; _x = x;

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ProjectGasolineTanker.MovementStrategy namespace ProjectGasolineTanker.MovementStratg
{ {
public enum Status public enum Status
{ {

View File

@ -11,7 +11,7 @@ namespace ProjectGasolineTanker
// To customize application configuration such as set high DPI settings or default font, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new FormGasolineTanker()); Application.Run(new FormTruckCollection());
} }
} }
} }