Compare commits

..

1 Commits

29 changed files with 46 additions and 2406 deletions

View File

@ -1,178 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GasolineTanker
{
internal abstract class AbstractMap : IEquatable<AbstractMap>
{
private IDrawingObject _drawningObject = null;
protected int[,] _map = null;
protected int _width;
protected int _height;
protected float _size_x;
protected float _size_y;
protected readonly Random _random = new();
protected readonly int _freeRoad = 0;
protected readonly int _barrier = 1;
private Direction GetOpositDirection(Direction d)
{
switch (d)
{
case Direction.None:
return Direction.None;
case Direction.Up:
return Direction.Down;
case Direction.Down:
return Direction.Up;
case Direction.Left:
return Direction.Right;
case Direction.Right:
return Direction.Left;
}
return Direction.None;
}
private int CheckCollision(float Left, float Right, float Top, float Bottom)
{
int starCoordinateX = (int)(Left / _size_x);
int starCoordinateY = (int)(Right / _size_y);
int endCoordinateX = (int)(Top / _size_x);
int endCoordinateY = (int)(Bottom / _size_y);
if (starCoordinateX < 0 || starCoordinateY < 0 || endCoordinateX >= _map.GetLength(1) || endCoordinateY >= _map.GetLength(0))
{
return 2;
}
for (int x = starCoordinateX; x <= endCoordinateX; x++)
{
for (int y = starCoordinateY; y <= endCoordinateY; y++)
{
if (_map[x, y] == _barrier)
{
return 1;
}
}
}
return 0;
}
public Bitmap CreateMap(int width, int height, IDrawingObject drawningObject)
{
_width = width;
_height = height;
_drawningObject = drawningObject;
GenerateMap();
while (!SetObjectOnMap())
{
GenerateMap();
}
return DrawMapWithObject();
}
public Bitmap MoveObject(Direction direction)
{
if (true)
{
_drawningObject.MoveObject(direction);
}
(float Left, float Right, float Top, float Bottom) = _drawningObject.GetCurrentPosition();
if (CheckCollision(Left, Right, Top, Bottom) != 0)
{
_drawningObject.MoveObject(GetOpositDirection(direction));
}
return DrawMapWithObject();
}
private bool SetObjectOnMap()
{
if (_drawningObject == null || _map == null)
{
return false;
}
int x = _random.Next(0, 10);
int y = _random.Next(0, 10);
_drawningObject.SetObject(x, y, _width, _height);
(float Left, float Right, float Top, float Bottom) = _drawningObject.GetCurrentPosition();
while (CheckCollision(Left, Right, Top, Bottom) != 2)
{
int resoult;
do
{
resoult = CheckCollision(Left, Right, Top, Bottom);
if (resoult == 0)
{
_drawningObject.SetObject((int)Left, (int)Right, _width, _height);
return true;
}
else
{
Left += _size_x;
}
} while (resoult != 2);
Left = x;
Right += _size_y;
}
return false;
}
private Bitmap DrawMapWithObject()
{
Bitmap bmp = new(_width, _height);
if (_drawningObject == null || _map == null)
{
return bmp;
}
Graphics gr = Graphics.FromImage(bmp);
for (int i = 0; i < _map.GetLength(0); ++i)
{
for (int j = 0; j < _map.GetLength(1); ++j)
{
if (_map[i, j] == _freeRoad)
{
DrawRoadPart(gr, i, j);
}
else if (_map[i, j] == _barrier)
{
DrawBarrierPart(gr, i, j);
}
}
}
_drawningObject.DrawningObject(gr);
return bmp;
}
public bool Equals(AbstractMap? other)
{
if (other == null ||
_map != other._map ||
_width != other._width ||
_size_x != other._size_x ||
_size_y != other._size_y ||
_height != other._height ||
GetType() != other.GetType() ||
_map.GetLength(0) != other._map.GetLength(0) ||
_map.GetLength(1) != other._map.GetLength(1))
{
return false;
}
for (int i = 0; i < _map.GetLength(0); i++)
{
for (int j = 0; j < _map.GetLength(1); j++)
{
if (_map[i, j] != other._map[i, j])
{
return false;
}
}
}
return true;
}
protected abstract void GenerateMap();
protected abstract void DrawRoadPart(Graphics g, int i, int j);
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
}
}

View File

@ -6,9 +6,8 @@ using System.Threading.Tasks;
namespace GasolineTanker
{
public enum Direction
internal enum Direction
{
None = 0,
Up = 1,
Down = 2,
Left = 3,

View File

@ -6,29 +6,20 @@ using System.Threading.Tasks;
namespace GasolineTanker
{
public class DrawingGasolineTanker
internal class DrawingGasolineTanker
{
public EnityGasolineTanker GasolineTanker { get; protected set; }
protected float _startPosX;
protected float _startPosY;
public EnityGasolineTanker GasolineTanker { get; private set; }
private float _startPosX;
private float _startPosY;
private int? _pictureWidth = null;
private int? _pictureHeight = null;
private readonly int _gasolineTankerWidth = 160;
private readonly int _gasolineTankerHeight = 55;
public DrawingGasolineTanker Copy(int? speed = null, float? weight = null, Color? bodyColor = null)
{
return new DrawingGasolineTanker(speed ?? GasolineTanker.Speed, weight ?? GasolineTanker.Weight, bodyColor ?? GasolineTanker.BodyColor);
}
public DrawingGasolineTanker(int speed, float weight, Color bodyColor)
{
GasolineTanker = new EnityGasolineTanker(speed, weight, bodyColor);
}
protected DrawingGasolineTanker(int speed, float weight, Color bodyColor, int gasolineTankerWidth, int gasolineTankerHeight) :
this(speed, weight, bodyColor)
public void Init(int speed, float weight, Color bodyColor)
{
_gasolineTankerWidth = gasolineTankerWidth;
_gasolineTankerHeight = gasolineTankerHeight;
GasolineTanker = new EnityGasolineTanker();
GasolineTanker.Init(speed, weight, bodyColor);
}
public void SetPosition(int x, int y, int width, int height)
@ -80,7 +71,7 @@ namespace GasolineTanker
break;
}
}
public virtual void DrawTransport(Graphics g)
public void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
@ -130,10 +121,5 @@ namespace GasolineTanker
_startPosY = _pictureHeight.Value - _gasolineTankerHeight;
}
}
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return (_startPosX, _startPosY, _startPosX + _gasolineTankerWidth, _startPosY + _gasolineTankerHeight);
}
}
}

View File

@ -1,52 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GasolineTanker
{
internal class DrawingImprovedGasolineTanker : DrawingGasolineTanker
{
public DrawingImprovedGasolineTanker(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool ornamentWheels) :
base(speed, weight, bodyColor, 160, 55)
{
GasolineTanker = new EntityImprovedGasolineTanker(speed, weight, bodyColor, dopColor, bodyKit, ornamentWheels);
}
public DrawingImprovedGasolineTanker Copy(int? speed = null, float? weight = null, Color? bodyColor = null, Color? dopColor = null, bool? hasBombs = null, bool? hasFuelTanks = null)
{
var e = (EntityImprovedGasolineTanker)GasolineTanker;
return new DrawingImprovedGasolineTanker(speed ?? e.Speed, weight ?? e.Weight, bodyColor ?? e.BodyColor, dopColor ?? e.DopColor, hasBombs ?? e.BodyKit, hasFuelTanks ?? e.OrnamentWheels);
}
public override void DrawTransport(Graphics g)
{
if (GasolineTanker is not EntityImprovedGasolineTanker improvedGasolineTanker)
{
return;
}
if (improvedGasolineTanker.BodyKit)
{
Brush dopBrush = new SolidBrush(improvedGasolineTanker.DopColor);
g.FillRectangle(dopBrush, _startPosX + 25, _startPosY + 5, 100, 35);
Brush brRed = new SolidBrush(Color.Red);
g.FillRectangle(brRed, _startPosX + 80, _startPosY, 10, 5);
}
_startPosX += 10;
_startPosY += 5;
base.DrawTransport(g);
_startPosX -= 10;
_startPosY -= 5;
if (improvedGasolineTanker.OrnamentWheels)
{
Pen penGray = new(Color.Gray);
Brush brBlack = new SolidBrush(Color.Gray);
g.DrawEllipse(penGray, _startPosX + 140, _startPosY + 50, 20, 5);
g.DrawEllipse(penGray, _startPosX + 40, _startPosY + 50, 20, 5);
g.DrawEllipse(penGray, _startPosX + 20, _startPosY + 50, 20, 5);
}
}
}
}

View File

@ -1,70 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GasolineTanker
{
internal class DrawingObjectGasolineTanker : IDrawingObject
{
private DrawingGasolineTanker _gasolineTanker = null;
public DrawingObjectGasolineTanker(DrawingGasolineTanker gasolineTanker)
{
_gasolineTanker = gasolineTanker;
}
public DrawingGasolineTanker GetGasolineTanker => _gasolineTanker;
public float Step => _gasolineTanker?.GasolineTanker?.Step ?? 0;
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return _gasolineTanker?.GetCurrentPosition() ?? default;
}
public void MoveObject(Direction direction)
{
_gasolineTanker?.MoveTransport(direction);
}
public void SetObject(int x, int y, int width, int height)
{
_gasolineTanker.SetPosition(x, y, width, height);
}
void IDrawingObject.DrawningObject(Graphics g)
{
_gasolineTanker.DrawTransport(g);
}
public string GetInfo() => _gasolineTanker?.GetDataForSave();
public static IDrawingObject Create(string data) => new DrawingObjectGasolineTanker(data.CreateDrawingGasolineTanker());
public bool Equals(IDrawingObject? other)
{
if (other is not DrawingObjectGasolineTanker otherGasolineTanker)
{
return false;
}
var entity = _gasolineTanker.GasolineTanker;
var otherEntity = otherGasolineTanker._gasolineTanker.GasolineTanker;
if (entity.GetType() != otherEntity.GetType() ||
entity.Speed != otherEntity.Speed ||
entity.Weight != otherEntity.Weight ||
entity.BodyColor != otherEntity.BodyColor)
{
return false;
}
if (entity is EntityImprovedGasolineTanker entityImprovedGasolineTanker &&
otherEntity is EntityImprovedGasolineTanker otherEntityWarmlyGasolineTanker && (
entityImprovedGasolineTanker.BodyColor != otherEntityWarmlyGasolineTanker.BodyColor ||
entityImprovedGasolineTanker.DopColor != otherEntityWarmlyGasolineTanker.DopColor ||
entityImprovedGasolineTanker.BodyKit != otherEntityWarmlyGasolineTanker.BodyKit))
{
return false;
}
return true;
}
}
}

View File

@ -6,13 +6,13 @@ using System.Threading.Tasks;
namespace GasolineTanker
{
public class EnityGasolineTanker
internal class EnityGasolineTanker
{
public int Speed { get; private set; }
public float Weight { get; private set; }
public Color BodyColor { get; private set; }
public float Step => Speed * 100 / Weight;
public EnityGasolineTanker(int speed, float weight, Color bodyColor)
public void Init(int speed, float weight, Color bodyColor)
{
Random rnd = new Random();
Speed = speed <= 0 ? rnd.Next(50, 100) : speed;

View File

@ -1,22 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GasolineTanker
{
internal class EntityImprovedGasolineTanker : EnityGasolineTanker
{
public Color DopColor { get; private set; }
public bool BodyKit { get; private set; }
public bool OrnamentWheels { get; private set; }
public EntityImprovedGasolineTanker(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool ornamentWheels) :
base(speed, weight, bodyColor)
{
DopColor = dopColor;
BodyKit = bodyKit;
OrnamentWheels = ornamentWheels;
}
}
}

View File

@ -1,41 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GasolineTanker
{
internal static class ExtentionGasolineTanker
{
private static readonly char _separatorForObject = ':';
public static DrawingGasolineTanker CreateDrawingGasolineTanker(this string info)
{
string[] strs = info.Split(_separatorForObject);
if (strs.Length == 3)
{
return new DrawingGasolineTanker(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
}
if (strs.Length == 6)
{
return new DrawingImprovedGasolineTanker(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
Color.FromName(strs[3]), Convert.ToBoolean(strs[4]),
Convert.ToBoolean(strs[5]));
}
return null;
}
public static string GetDataForSave(this DrawingGasolineTanker drawingGasolineTanker)
{
var GasolineTanker = drawingGasolineTanker.GasolineTanker;
var str = $"{GasolineTanker.Speed}{_separatorForObject}{GasolineTanker.Weight}{_separatorForObject}{GasolineTanker.BodyColor.Name}";
if (GasolineTanker is not EntityImprovedGasolineTanker improvedGasolineTanker)
{
return str;
}
return $"{str}{_separatorForObject}{improvedGasolineTanker.DopColor.Name}{_separatorForObject}{improvedGasolineTanker.BodyKit}{_separatorForObject}{improvedGasolineTanker.OrnamentWheels}";
}
}
}

View File

@ -38,8 +38,6 @@
this.keyUp = new System.Windows.Forms.Button();
this.keyLeft = new System.Windows.Forms.Button();
this.keyRight = new System.Windows.Forms.Button();
this.ButtonCreateImproved = new System.Windows.Forms.Button();
this.buttonChoose = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxGasolineTanker)).BeginInit();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
@ -48,8 +46,9 @@
//
this.pictureBoxGasolineTanker.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxGasolineTanker.Location = new System.Drawing.Point(0, 0);
this.pictureBoxGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.pictureBoxGasolineTanker.Name = "pictureBoxGasolineTanker";
this.pictureBoxGasolineTanker.Size = new System.Drawing.Size(807, 428);
this.pictureBoxGasolineTanker.Size = new System.Drawing.Size(922, 574);
this.pictureBoxGasolineTanker.TabIndex = 0;
this.pictureBoxGasolineTanker.TabStop = false;
//
@ -60,49 +59,52 @@
this.toolStripStatusSpeed,
this.toolStripStatusWeight,
this.toolStripStatusBodyColor});
this.statusStrip1.Location = new System.Drawing.Point(0, 428);
this.statusStrip1.Location = new System.Drawing.Point(0, 574);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(807, 22);
this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 16, 0);
this.statusStrip1.Size = new System.Drawing.Size(922, 26);
this.statusStrip1.TabIndex = 1;
this.statusStrip1.Text = "statusStrip1";
//
// toolStripStatusSpeed
//
this.toolStripStatusSpeed.Name = "toolStripStatusSpeed";
this.toolStripStatusSpeed.Size = new System.Drawing.Size(39, 17);
this.toolStripStatusSpeed.Size = new System.Drawing.Size(51, 20);
this.toolStripStatusSpeed.Text = "Speed";
//
// toolStripStatusWeight
//
this.toolStripStatusWeight.Name = "toolStripStatusWeight";
this.toolStripStatusWeight.Size = new System.Drawing.Size(45, 17);
this.toolStripStatusWeight.Size = new System.Drawing.Size(56, 20);
this.toolStripStatusWeight.Text = "Weight";
//
// toolStripStatusBodyColor
//
this.toolStripStatusBodyColor.Name = "toolStripStatusBodyColor";
this.toolStripStatusBodyColor.Size = new System.Drawing.Size(36, 17);
this.toolStripStatusBodyColor.Size = new System.Drawing.Size(45, 20);
this.toolStripStatusBodyColor.Text = "Color";
//
// 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(12, 393);
this.buttonCreate.Location = new System.Drawing.Point(14, 524);
this.buttonCreate.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(75, 23);
this.buttonCreate.Size = new System.Drawing.Size(86, 31);
this.buttonCreate.TabIndex = 2;
this.buttonCreate.Text = "Create";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click_1);
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click_1);
//
// keyDown
//
this.keyDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.keyDown.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyDown;
this.keyDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.keyDown.Location = new System.Drawing.Point(724, 386);
this.keyDown.Location = new System.Drawing.Point(827, 515);
this.keyDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.keyDown.Name = "keyDown";
this.keyDown.Size = new System.Drawing.Size(30, 30);
this.keyDown.Size = new System.Drawing.Size(34, 40);
this.keyDown.TabIndex = 3;
this.keyDown.UseVisualStyleBackColor = true;
this.keyDown.Click += new System.EventHandler(this.ButtonMove_Click);
@ -112,9 +114,10 @@
this.keyUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.keyUp.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyUp;
this.keyUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.keyUp.Location = new System.Drawing.Point(724, 350);
this.keyUp.Location = new System.Drawing.Point(827, 467);
this.keyUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.keyUp.Name = "keyUp";
this.keyUp.Size = new System.Drawing.Size(30, 30);
this.keyUp.Size = new System.Drawing.Size(34, 40);
this.keyUp.TabIndex = 4;
this.keyUp.UseVisualStyleBackColor = true;
this.keyUp.Click += new System.EventHandler(this.ButtonMove_Click);
@ -124,9 +127,10 @@
this.keyLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.keyLeft.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyLeft;
this.keyLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.keyLeft.Location = new System.Drawing.Point(688, 386);
this.keyLeft.Location = new System.Drawing.Point(786, 515);
this.keyLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.keyLeft.Name = "keyLeft";
this.keyLeft.Size = new System.Drawing.Size(30, 30);
this.keyLeft.Size = new System.Drawing.Size(34, 40);
this.keyLeft.TabIndex = 5;
this.keyLeft.UseVisualStyleBackColor = true;
this.keyLeft.Click += new System.EventHandler(this.ButtonMove_Click);
@ -136,41 +140,19 @@
this.keyRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.keyRight.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyRight;
this.keyRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.keyRight.Location = new System.Drawing.Point(760, 386);
this.keyRight.Location = new System.Drawing.Point(868, 515);
this.keyRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.keyRight.Name = "keyRight";
this.keyRight.Size = new System.Drawing.Size(30, 30);
this.keyRight.Size = new System.Drawing.Size(34, 40);
this.keyRight.TabIndex = 6;
this.keyRight.UseVisualStyleBackColor = true;
this.keyRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
// ButtonCreateImproved
//
this.ButtonCreateImproved.Location = new System.Drawing.Point(93, 393);
this.ButtonCreateImproved.Name = "ButtonCreateImproved";
this.ButtonCreateImproved.Size = new System.Drawing.Size(75, 23);
this.ButtonCreateImproved.TabIndex = 7;
this.ButtonCreateImproved.Text = "Improved";
this.ButtonCreateImproved.UseVisualStyleBackColor = true;
this.ButtonCreateImproved.Click += new System.EventHandler(this.ButtonCreateImproved_Click);
//
// buttonChoose
//
this.buttonChoose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonChoose.Location = new System.Drawing.Point(598, 390);
this.buttonChoose.Name = "buttonChoose";
this.buttonChoose.Size = new System.Drawing.Size(75, 23);
this.buttonChoose.TabIndex = 8;
this.buttonChoose.Text = "Choose";
this.buttonChoose.UseVisualStyleBackColor = true;
this.buttonChoose.Click += new System.EventHandler(this.ButtonChoose_Click);
//
// 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.ClientSize = new System.Drawing.Size(807, 450);
this.Controls.Add(this.buttonChoose);
this.Controls.Add(this.ButtonCreateImproved);
this.ClientSize = new System.Drawing.Size(922, 600);
this.Controls.Add(this.keyRight);
this.Controls.Add(this.keyLeft);
this.Controls.Add(this.keyUp);
@ -178,6 +160,7 @@
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.pictureBoxGasolineTanker);
this.Controls.Add(this.statusStrip1);
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormGasolineTanker";
this.Text = "Gasoline tanker";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxGasolineTanker)).EndInit();
@ -200,7 +183,5 @@
private Button keyUp;
private Button keyLeft;
private Button keyRight;
private Button ButtonCreateImproved;
private Button buttonChoose;
}
}

View File

@ -3,7 +3,6 @@ namespace GasolineTanker
public partial class FormGasolineTanker : Form
{
private DrawingGasolineTanker _gasolineTanker;
public DrawingGasolineTanker SelectedGasolineTanker { get; private set; }
public FormGasolineTanker()
{
InitializeComponent();
@ -15,33 +14,22 @@ namespace GasolineTanker
_gasolineTanker?.DrawTransport(gr);
pictureBoxGasolineTanker.Image = bmp;
}
private void SetData()
{
Random rnd = new();
_gasolineTanker.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height);
toolStripStatusSpeed.Text = $"Speed {_gasolineTanker.GasolineTanker.Speed}";
toolStripStatusWeight.Text = $"Weight {_gasolineTanker.GasolineTanker.Weight}";
toolStripStatusBodyColor.Text = $"Color {_gasolineTanker.GasolineTanker.BodyColor.Name}";
}
private void PictureBoxCar_Resize(object sender, EventArgs e)
{
_gasolineTanker?.ChangeBorders(pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height);
Draw();
}
private void ButtonCreate_Click_1(object sender, EventArgs e)
private void buttonCreate_Click_1(object sender, EventArgs e)
{
Random rnd = new();
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256),rnd.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_gasolineTanker = new DrawingGasolineTanker(rnd.Next(100, 300), rnd.Next(1000, 2000),color);
SetData();
_gasolineTanker = new DrawingGasolineTanker();
_gasolineTanker.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_gasolineTanker.SetPosition(rnd.Next(10, 100),rnd.Next(50, 100), pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height);
toolStripStatusSpeed.Text = $"Speed {_gasolineTanker.GasolineTanker.Speed}";
toolStripStatusWeight.Text = $"Weight {_gasolineTanker.GasolineTanker.Weight}";
toolStripStatusBodyColor.Text = $"Color {_gasolineTanker.GasolineTanker.BodyColor.Name}";
Draw();
}
private void ButtonMove_Click(object sender, EventArgs e)
@ -71,31 +59,5 @@ namespace GasolineTanker
_gasolineTanker?.ChangeBorders(pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height);
Draw();
}
private void ButtonCreateImproved_Click(object sender, EventArgs e)
{
Random rnd = new();
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256),rnd.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
Color colorDop = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialogDop = new();
if (dialogDop.ShowDialog() == DialogResult.OK)
{
colorDop = dialogDop.Color;
}
_gasolineTanker = new DrawingImprovedGasolineTanker(rnd.Next(100, 300), rnd.Next(1000, 2000), color, colorDop, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData();
Draw();
}
private void ButtonChoose_Click(object sender, EventArgs e)
{
SelectedGasolineTanker = _gasolineTanker;
DialogResult = DialogResult.OK;
}
}
}

View File

@ -1,381 +0,0 @@
namespace GasolineTanker
{
partial class FormGasolineTankerConfig
{
/// <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.groupBoxConfig = new System.Windows.Forms.GroupBox();
this.numericUpDownWeight = new System.Windows.Forms.NumericUpDown();
this.numericUpDownSpeed = new System.Windows.Forms.NumericUpDown();
this.labelImrovedObject = new System.Windows.Forms.Label();
this.labelSimpleObject = new System.Windows.Forms.Label();
this.groupBoxColor = new System.Windows.Forms.GroupBox();
this.panelPurple = new System.Windows.Forms.Panel();
this.panelRed = new System.Windows.Forms.Panel();
this.panelYellow = new System.Windows.Forms.Panel();
this.panelWhite = new System.Windows.Forms.Panel();
this.panelGreen = new System.Windows.Forms.Panel();
this.panelBlack = new System.Windows.Forms.Panel();
this.panelGray = new System.Windows.Forms.Panel();
this.panelBlue = new System.Windows.Forms.Panel();
this.checkBoxOrnamentWheel = new System.Windows.Forms.CheckBox();
this.checkBoxBodyKit = new System.Windows.Forms.CheckBox();
this.labelWeight = new System.Windows.Forms.Label();
this.labelSpeed = new System.Windows.Forms.Label();
this.pictureBoxObject = new System.Windows.Forms.PictureBox();
this.panelObject = new System.Windows.Forms.Panel();
this.labelDopColor = new System.Windows.Forms.Label();
this.labelBaseColor = new System.Windows.Forms.Label();
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonOk = new System.Windows.Forms.Button();
this.groupBoxConfig.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).BeginInit();
this.groupBoxColor.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).BeginInit();
this.panelObject.SuspendLayout();
this.SuspendLayout();
//
// groupBoxConfig
//
this.groupBoxConfig.Controls.Add(this.numericUpDownWeight);
this.groupBoxConfig.Controls.Add(this.numericUpDownSpeed);
this.groupBoxConfig.Controls.Add(this.labelImrovedObject);
this.groupBoxConfig.Controls.Add(this.labelSimpleObject);
this.groupBoxConfig.Controls.Add(this.groupBoxColor);
this.groupBoxConfig.Controls.Add(this.checkBoxOrnamentWheel);
this.groupBoxConfig.Controls.Add(this.checkBoxBodyKit);
this.groupBoxConfig.Controls.Add(this.labelWeight);
this.groupBoxConfig.Controls.Add(this.labelSpeed);
this.groupBoxConfig.Location = new System.Drawing.Point(12, 12);
this.groupBoxConfig.Name = "groupBoxConfig";
this.groupBoxConfig.Size = new System.Drawing.Size(451, 197);
this.groupBoxConfig.TabIndex = 0;
this.groupBoxConfig.TabStop = false;
this.groupBoxConfig.Text = "Options";
//
// numericUpDownWeight
//
this.numericUpDownWeight.Location = new System.Drawing.Point(80, 70);
this.numericUpDownWeight.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.numericUpDownWeight.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDownWeight.Name = "numericUpDownWeight";
this.numericUpDownWeight.Size = new System.Drawing.Size(79, 23);
this.numericUpDownWeight.TabIndex = 12;
this.numericUpDownWeight.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// numericUpDownSpeed
//
this.numericUpDownSpeed.Location = new System.Drawing.Point(80, 28);
this.numericUpDownSpeed.Maximum = new decimal(new int[] {
1000,
0,
0,
0});
this.numericUpDownSpeed.Minimum = new decimal(new int[] {
100,
0,
0,
0});
this.numericUpDownSpeed.Name = "numericUpDownSpeed";
this.numericUpDownSpeed.Size = new System.Drawing.Size(79, 23);
this.numericUpDownSpeed.TabIndex = 11;
this.numericUpDownSpeed.Value = new decimal(new int[] {
100,
0,
0,
0});
//
// labelImrovedObject
//
this.labelImrovedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelImrovedObject.Location = new System.Drawing.Point(321, 149);
this.labelImrovedObject.Name = "labelImrovedObject";
this.labelImrovedObject.Size = new System.Drawing.Size(97, 36);
this.labelImrovedObject.TabIndex = 8;
this.labelImrovedObject.Text = "Improved";
this.labelImrovedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelImrovedObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// labelSimpleObject
//
this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelSimpleObject.Location = new System.Drawing.Point(209, 149);
this.labelSimpleObject.Name = "labelSimpleObject";
this.labelSimpleObject.Size = new System.Drawing.Size(96, 36);
this.labelSimpleObject.TabIndex = 7;
this.labelSimpleObject.Text = "Simple";
this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelSimpleObject.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelObject_MouseDown);
//
// groupBoxColor
//
this.groupBoxColor.Controls.Add(this.panelPurple);
this.groupBoxColor.Controls.Add(this.panelRed);
this.groupBoxColor.Controls.Add(this.panelYellow);
this.groupBoxColor.Controls.Add(this.panelWhite);
this.groupBoxColor.Controls.Add(this.panelGreen);
this.groupBoxColor.Controls.Add(this.panelBlack);
this.groupBoxColor.Controls.Add(this.panelGray);
this.groupBoxColor.Controls.Add(this.panelBlue);
this.groupBoxColor.Location = new System.Drawing.Point(203, 12);
this.groupBoxColor.Name = "groupBoxColor";
this.groupBoxColor.Size = new System.Drawing.Size(232, 134);
this.groupBoxColor.TabIndex = 6;
this.groupBoxColor.TabStop = false;
this.groupBoxColor.Text = "Color";
//
// panelPurple
//
this.panelPurple.BackColor = System.Drawing.Color.Purple;
this.panelPurple.Location = new System.Drawing.Point(175, 80);
this.panelPurple.Name = "panelPurple";
this.panelPurple.Size = new System.Drawing.Size(40, 40);
this.panelPurple.TabIndex = 11;
//
// panelRed
//
this.panelRed.BackColor = System.Drawing.Color.Red;
this.panelRed.Location = new System.Drawing.Point(6, 29);
this.panelRed.Name = "panelRed";
this.panelRed.Size = new System.Drawing.Size(40, 40);
this.panelRed.TabIndex = 6;
//
// panelYellow
//
this.panelYellow.BackColor = System.Drawing.Color.Yellow;
this.panelYellow.Location = new System.Drawing.Point(175, 29);
this.panelYellow.Name = "panelYellow";
this.panelYellow.Size = new System.Drawing.Size(40, 40);
this.panelYellow.TabIndex = 7;
//
// panelWhite
//
this.panelWhite.BackColor = System.Drawing.Color.White;
this.panelWhite.Location = new System.Drawing.Point(6, 80);
this.panelWhite.Name = "panelWhite";
this.panelWhite.Size = new System.Drawing.Size(40, 40);
this.panelWhite.TabIndex = 10;
//
// panelGreen
//
this.panelGreen.BackColor = System.Drawing.Color.Green;
this.panelGreen.Location = new System.Drawing.Point(63, 29);
this.panelGreen.Name = "panelGreen";
this.panelGreen.Size = new System.Drawing.Size(40, 40);
this.panelGreen.TabIndex = 9;
//
// panelBlack
//
this.panelBlack.BackColor = System.Drawing.Color.Black;
this.panelBlack.Location = new System.Drawing.Point(118, 80);
this.panelBlack.Name = "panelBlack";
this.panelBlack.Size = new System.Drawing.Size(40, 40);
this.panelBlack.TabIndex = 12;
//
// panelGray
//
this.panelGray.BackColor = System.Drawing.Color.Gray;
this.panelGray.Location = new System.Drawing.Point(63, 80);
this.panelGray.Name = "panelGray";
this.panelGray.Size = new System.Drawing.Size(40, 40);
this.panelGray.TabIndex = 13;
//
// panelBlue
//
this.panelBlue.BackColor = System.Drawing.Color.Blue;
this.panelBlue.Location = new System.Drawing.Point(118, 29);
this.panelBlue.Name = "panelBlue";
this.panelBlue.Size = new System.Drawing.Size(40, 40);
this.panelBlue.TabIndex = 8;
//
// checkBoxOrnamentWheel
//
this.checkBoxOrnamentWheel.AutoSize = true;
this.checkBoxOrnamentWheel.Location = new System.Drawing.Point(21, 149);
this.checkBoxOrnamentWheel.Name = "checkBoxOrnamentWheel";
this.checkBoxOrnamentWheel.Size = new System.Drawing.Size(180, 19);
this.checkBoxOrnamentWheel.TabIndex = 5;
this.checkBoxOrnamentWheel.Text = "The presence of an ornament";
this.checkBoxOrnamentWheel.UseVisualStyleBackColor = true;
//
// checkBoxBodyKit
//
this.checkBoxBodyKit.AutoSize = true;
this.checkBoxBodyKit.Location = new System.Drawing.Point(21, 114);
this.checkBoxBodyKit.Name = "checkBoxBodyKit";
this.checkBoxBodyKit.Size = new System.Drawing.Size(151, 19);
this.checkBoxBodyKit.TabIndex = 4;
this.checkBoxBodyKit.Text = "The presence of a barrel";
this.checkBoxBodyKit.UseVisualStyleBackColor = true;
//
// labelWeight
//
this.labelWeight.AutoSize = true;
this.labelWeight.Location = new System.Drawing.Point(21, 72);
this.labelWeight.Name = "labelWeight";
this.labelWeight.Size = new System.Drawing.Size(45, 15);
this.labelWeight.TabIndex = 1;
this.labelWeight.Text = "Weight";
//
// labelSpeed
//
this.labelSpeed.AutoSize = true;
this.labelSpeed.Location = new System.Drawing.Point(21, 30);
this.labelSpeed.Name = "labelSpeed";
this.labelSpeed.Size = new System.Drawing.Size(39, 15);
this.labelSpeed.TabIndex = 0;
this.labelSpeed.Text = "Speed";
//
// pictureBoxObject
//
this.pictureBoxObject.Location = new System.Drawing.Point(20, 44);
this.pictureBoxObject.Name = "pictureBoxObject";
this.pictureBoxObject.Size = new System.Drawing.Size(225, 125);
this.pictureBoxObject.TabIndex = 0;
this.pictureBoxObject.TabStop = false;
//
// panelObject
//
this.panelObject.AllowDrop = true;
this.panelObject.Controls.Add(this.labelDopColor);
this.panelObject.Controls.Add(this.labelBaseColor);
this.panelObject.Controls.Add(this.pictureBoxObject);
this.panelObject.Location = new System.Drawing.Point(489, 12);
this.panelObject.Name = "panelObject";
this.panelObject.Size = new System.Drawing.Size(262, 184);
this.panelObject.TabIndex = 9;
this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop);
this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter);
//
// labelDopColor
//
this.labelDopColor.AllowDrop = true;
this.labelDopColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelDopColor.Location = new System.Drawing.Point(141, 9);
this.labelDopColor.Name = "labelDopColor";
this.labelDopColor.Size = new System.Drawing.Size(104, 32);
this.labelDopColor.TabIndex = 2;
this.labelDopColor.Text = "Dop.color";
this.labelDopColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelDopColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragDrop);
this.labelDopColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelDopColor_DragEnter);
//
// labelBaseColor
//
this.labelBaseColor.AllowDrop = true;
this.labelBaseColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.labelBaseColor.Location = new System.Drawing.Point(20, 9);
this.labelBaseColor.Name = "labelBaseColor";
this.labelBaseColor.Size = new System.Drawing.Size(104, 32);
this.labelBaseColor.TabIndex = 1;
this.labelBaseColor.Text = "Color";
this.labelBaseColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.labelBaseColor.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragDrop);
this.labelBaseColor.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelBaseColor_DragEnter);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(630, 202);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(104, 30);
this.buttonCancel.TabIndex = 11;
this.buttonCancel.Text = "Cancel";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// buttonOk
//
this.buttonOk.Location = new System.Drawing.Point(509, 202);
this.buttonOk.Name = "buttonOk";
this.buttonOk.Size = new System.Drawing.Size(104, 30);
this.buttonOk.TabIndex = 10;
this.buttonOk.Text = "Add";
this.buttonOk.UseVisualStyleBackColor = true;
this.buttonOk.Click += new System.EventHandler(this.ButtonOk_Click);
//
// FormGasolineTankerConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(793, 244);
this.Controls.Add(this.panelObject);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.groupBoxConfig);
this.Controls.Add(this.buttonOk);
this.Name = "FormGasolineTankerConfig";
this.Text = "Create object";
this.groupBoxConfig.ResumeLayout(false);
this.groupBoxConfig.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWeight)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownSpeed)).EndInit();
this.groupBoxColor.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit();
this.panelObject.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBoxConfig;
private CheckBox checkBoxOrnamentWheel;
private CheckBox checkBoxBodyKit;
private Label labelWeight;
private Label labelSpeed;
private Label labelImrovedObject;
private Label labelSimpleObject;
private GroupBox groupBoxColor;
private Panel panelPurple;
private Panel panelRed;
private Panel panelYellow;
private Panel panelWhite;
private Panel panelGreen;
private Panel panelBlack;
private Panel panelGray;
private Panel panelBlue;
private PictureBox pictureBoxObject;
private Panel panelObject;
private Label labelDopColor;
private Label labelBaseColor;
private Button buttonCancel;
private Button buttonOk;
private NumericUpDown numericUpDownWeight;
private NumericUpDown numericUpDownSpeed;
}
}

View File

@ -1,129 +0,0 @@
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;
namespace GasolineTanker
{
public partial class FormGasolineTankerConfig : Form
{
DrawingGasolineTanker _gasolineTanker = null;
private event Action<DrawingGasolineTanker> EventAddGasolineTanker;
public FormGasolineTankerConfig()
{
InitializeComponent();
panelBlack.MouseDown += PanelColor_MouseDown;
panelPurple.MouseDown += PanelColor_MouseDown;
panelGray.MouseDown += PanelColor_MouseDown;
panelGreen.MouseDown += PanelColor_MouseDown;
panelRed.MouseDown += PanelColor_MouseDown;
panelWhite.MouseDown += PanelColor_MouseDown;
panelYellow.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown;
buttonCancel.Click += (s, e) => Close();
}
public void AddEvent(Action<DrawingGasolineTanker> ev)
{
if (EventAddGasolineTanker == null)
{
EventAddGasolineTanker = ev;
}
else
{
EventAddGasolineTanker += ev;
}
}
private void setDragEffect(DragEventArgs e, Type needTypeData, bool condition)
{
if (e.Data.GetDataPresent(needTypeData) && condition)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void LabelBaseColor_DragEnter(object sender, DragEventArgs e) => setDragEffect(e, typeof(Color), _gasolineTanker != null);
private void LabelDopColor_DragEnter(object sender, DragEventArgs e) => setDragEffect(e, typeof(Color), _gasolineTanker != null && _gasolineTanker is DrawingImprovedGasolineTanker);
private void LabelBaseColor_DragDrop(object sender, DragEventArgs e)
{
var color = (Color)e.Data.GetData(typeof(Color));
if (_gasolineTanker is DrawingImprovedGasolineTanker)
{
_gasolineTanker = ((DrawingImprovedGasolineTanker)_gasolineTanker).Copy(bodyColor: color);
}
else if (_gasolineTanker is DrawingGasolineTanker)
{
_gasolineTanker = _gasolineTanker.Copy(bodyColor: color);
}
DrawGasolineTanker();
}
private void LabelDopColor_DragDrop(object sender, DragEventArgs e)
{
var color = (Color)e.Data.GetData(typeof(Color));
var gasolineTanker = _gasolineTanker as DrawingImprovedGasolineTanker;
if (gasolineTanker != null)
{
_gasolineTanker = gasolineTanker.Copy(dopColor: color);
}
DrawGasolineTanker();
}
private void ButtonOk_Click(object sender, EventArgs e)
{
EventAddGasolineTanker?.Invoke(_gasolineTanker);
Close();
}
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label).DoDragDrop((sender as Label).Name, DragDropEffects.Move | DragDropEffects.Copy);
}
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Control).DoDragDrop((sender as Control).BackColor, DragDropEffects.Move | DragDropEffects.Copy);
}
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void DrawGasolineTanker()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_gasolineTanker?.SetPosition(5, 5, pictureBoxObject.Width, pictureBoxObject.Height);
_gasolineTanker?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
private void PanelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data.GetData(DataFormats.Text).ToString())
{
case "labelSimpleObject":
_gasolineTanker = new DrawingGasolineTanker((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White);
break;
case "labelImrovedObject":
_gasolineTanker = new DrawingImprovedGasolineTanker((int)numericUpDownSpeed.Value, (int)numericUpDownWeight.Value, Color.White, Color.Black,
checkBoxBodyKit.Checked, checkBoxOrnamentWheel.Checked);
break;
}
DrawGasolineTanker();
}
}
}

View File

@ -1,60 +0,0 @@
<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

@ -1,379 +0,0 @@
namespace GasolineTanker
{
partial class FormMapWithSetGasolineTanker
{
/// <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.groupBoxTools = new System.Windows.Forms.GroupBox();
this.buttonSortByColor = new System.Windows.Forms.Button();
this.buttonSortByType = new System.Windows.Forms.Button();
this.groupBoxMaps = new System.Windows.Forms.GroupBox();
this.buttonDeleteMap = new System.Windows.Forms.Button();
this.listBoxMaps = new System.Windows.Forms.ListBox();
this.buttonAddMap = new System.Windows.Forms.Button();
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.keyRight = new System.Windows.Forms.Button();
this.keyLeft = new System.Windows.Forms.Button();
this.keyUp = new System.Windows.Forms.Button();
this.keyDown = new System.Windows.Forms.Button();
this.buttonShowOnMap = new System.Windows.Forms.Button();
this.buttonShowStorage = new System.Windows.Forms.Button();
this.buttonRemoveGasolineTanker = new System.Windows.Forms.Button();
this.buttonAddGasolineTanker = new System.Windows.Forms.Button();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.menuStrip = new System.Windows.Forms.MenuStrip();
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.SaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.groupBoxTools.SuspendLayout();
this.groupBoxMaps.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.menuStrip.SuspendLayout();
this.SuspendLayout();
//
// groupBoxTools
//
this.groupBoxTools.Controls.Add(this.buttonSortByColor);
this.groupBoxTools.Controls.Add(this.buttonSortByType);
this.groupBoxTools.Controls.Add(this.groupBoxMaps);
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
this.groupBoxTools.Controls.Add(this.keyRight);
this.groupBoxTools.Controls.Add(this.keyLeft);
this.groupBoxTools.Controls.Add(this.keyUp);
this.groupBoxTools.Controls.Add(this.keyDown);
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
this.groupBoxTools.Controls.Add(this.buttonRemoveGasolineTanker);
this.groupBoxTools.Controls.Add(this.buttonAddGasolineTanker);
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBoxTools.Location = new System.Drawing.Point(793, 30);
this.groupBoxTools.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxTools.Name = "groupBoxTools";
this.groupBoxTools.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxTools.Size = new System.Drawing.Size(229, 924);
this.groupBoxTools.TabIndex = 0;
this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Tools";
//
// buttonSortByColor
//
this.buttonSortByColor.Location = new System.Drawing.Point(16, 504);
this.buttonSortByColor.Name = "buttonSortByColor";
this.buttonSortByColor.Size = new System.Drawing.Size(198, 29);
this.buttonSortByColor.TabIndex = 15;
this.buttonSortByColor.Text = "Sort by color";
this.buttonSortByColor.UseVisualStyleBackColor = true;
this.buttonSortByColor.Click += new System.EventHandler(this.buttonSortByColor_Click);
//
// buttonSortByType
//
this.buttonSortByType.Location = new System.Drawing.Point(16, 457);
this.buttonSortByType.Name = "buttonSortByType";
this.buttonSortByType.Size = new System.Drawing.Size(198, 29);
this.buttonSortByType.TabIndex = 14;
this.buttonSortByType.Text = "Sort by type";
this.buttonSortByType.UseVisualStyleBackColor = true;
this.buttonSortByType.Click += new System.EventHandler(this.buttonSortByType_Click);
//
// groupBoxMaps
//
this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
this.groupBoxMaps.Controls.Add(this.listBoxMaps);
this.groupBoxMaps.Controls.Add(this.buttonAddMap);
this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
this.groupBoxMaps.Location = new System.Drawing.Point(7, 29);
this.groupBoxMaps.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxMaps.Name = "groupBoxMaps";
this.groupBoxMaps.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxMaps.Size = new System.Drawing.Size(217, 407);
this.groupBoxMaps.TabIndex = 13;
this.groupBoxMaps.TabStop = false;
this.groupBoxMaps.Text = "Maps";
//
// buttonDeleteMap
//
this.buttonDeleteMap.Location = new System.Drawing.Point(7, 321);
this.buttonDeleteMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonDeleteMap.Name = "buttonDeleteMap";
this.buttonDeleteMap.Size = new System.Drawing.Size(200, 65);
this.buttonDeleteMap.TabIndex = 16;
this.buttonDeleteMap.Text = "Delete Map";
this.buttonDeleteMap.UseVisualStyleBackColor = true;
this.buttonDeleteMap.Click += new System.EventHandler(this.buttonDeleteMap_Click);
//
// listBoxMaps
//
this.listBoxMaps.FormattingEnabled = true;
this.listBoxMaps.ItemHeight = 20;
this.listBoxMaps.Location = new System.Drawing.Point(7, 188);
this.listBoxMaps.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.listBoxMaps.Name = "listBoxMaps";
this.listBoxMaps.Size = new System.Drawing.Size(201, 124);
this.listBoxMaps.TabIndex = 15;
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged);
//
// buttonAddMap
//
this.buttonAddMap.Location = new System.Drawing.Point(7, 112);
this.buttonAddMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonAddMap.Name = "buttonAddMap";
this.buttonAddMap.Size = new System.Drawing.Size(201, 68);
this.buttonAddMap.TabIndex = 14;
this.buttonAddMap.Text = "Add Map";
this.buttonAddMap.UseVisualStyleBackColor = true;
this.buttonAddMap.Click += new System.EventHandler(this.buttonAddMap_Click);
//
// textBoxNewMapName
//
this.textBoxNewMapName.Location = new System.Drawing.Point(4, 68);
this.textBoxNewMapName.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.textBoxNewMapName.Name = "textBoxNewMapName";
this.textBoxNewMapName.Size = new System.Drawing.Size(203, 27);
this.textBoxNewMapName.TabIndex = 13;
//
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.Location = new System.Drawing.Point(4, 33);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(204, 28);
this.comboBoxSelectorMap.TabIndex = 17;
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(16, 611);
this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(210, 27);
this.maskedTextBoxPosition.TabIndex = 11;
//
// keyRight
//
this.keyRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.keyRight.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyRight;
this.keyRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.keyRight.Location = new System.Drawing.Point(139, 868);
this.keyRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.keyRight.Name = "keyRight";
this.keyRight.Size = new System.Drawing.Size(34, 40);
this.keyRight.TabIndex = 10;
this.keyRight.UseVisualStyleBackColor = true;
this.keyRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
// keyLeft
//
this.keyLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.keyLeft.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyLeft;
this.keyLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.keyLeft.Location = new System.Drawing.Point(57, 868);
this.keyLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.keyLeft.Name = "keyLeft";
this.keyLeft.Size = new System.Drawing.Size(34, 40);
this.keyLeft.TabIndex = 9;
this.keyLeft.UseVisualStyleBackColor = true;
this.keyLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
// keyUp
//
this.keyUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.keyUp.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyUp;
this.keyUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.keyUp.Location = new System.Drawing.Point(98, 820);
this.keyUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.keyUp.Name = "keyUp";
this.keyUp.Size = new System.Drawing.Size(34, 40);
this.keyUp.TabIndex = 8;
this.keyUp.UseVisualStyleBackColor = true;
this.keyUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// keyDown
//
this.keyDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.keyDown.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyDown;
this.keyDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.keyDown.Location = new System.Drawing.Point(98, 868);
this.keyDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.keyDown.Name = "keyDown";
this.keyDown.Size = new System.Drawing.Size(34, 40);
this.keyDown.TabIndex = 7;
this.keyDown.UseVisualStyleBackColor = true;
this.keyDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonShowOnMap
//
this.buttonShowOnMap.Location = new System.Drawing.Point(14, 757);
this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(213, 45);
this.buttonShowOnMap.TabIndex = 4;
this.buttonShowOnMap.Text = "Show on map";
this.buttonShowOnMap.UseVisualStyleBackColor = true;
this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
//
// buttonShowStorage
//
this.buttonShowStorage.Location = new System.Drawing.Point(14, 703);
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(213, 45);
this.buttonShowStorage.TabIndex = 3;
this.buttonShowStorage.Text = "Show storage";
this.buttonShowStorage.UseVisualStyleBackColor = true;
this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
//
// buttonRemoveGasolineTanker
//
this.buttonRemoveGasolineTanker.Location = new System.Drawing.Point(14, 650);
this.buttonRemoveGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonRemoveGasolineTanker.Name = "buttonRemoveGasolineTanker";
this.buttonRemoveGasolineTanker.Size = new System.Drawing.Size(213, 45);
this.buttonRemoveGasolineTanker.TabIndex = 2;
this.buttonRemoveGasolineTanker.Text = "Remove gasoline tanker";
this.buttonRemoveGasolineTanker.UseVisualStyleBackColor = true;
this.buttonRemoveGasolineTanker.Click += new System.EventHandler(this.buttonRemoveGasolineTanker_Click);
//
// buttonAddGasolineTanker
//
this.buttonAddGasolineTanker.Location = new System.Drawing.Point(16, 558);
this.buttonAddGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonAddGasolineTanker.Name = "buttonAddGasolineTanker";
this.buttonAddGasolineTanker.Size = new System.Drawing.Size(213, 45);
this.buttonAddGasolineTanker.TabIndex = 1;
this.buttonAddGasolineTanker.Text = "Add gasoline tanker";
this.buttonAddGasolineTanker.UseVisualStyleBackColor = true;
this.buttonAddGasolineTanker.Click += new System.EventHandler(this.ButtonAddGasolineTanker_Click);
//
// pictureBox
//
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 30);
this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(793, 924);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
// menuStrip
//
this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Padding = new System.Windows.Forms.Padding(7, 3, 0, 3);
this.menuStrip.Size = new System.Drawing.Size(1022, 30);
this.menuStrip.TabIndex = 2;
//
// fileToolStripMenuItem
//
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.SaveToolStripMenuItem,
this.LoadToolStripMenuItem});
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
this.fileToolStripMenuItem.Size = new System.Drawing.Size(46, 24);
this.fileToolStripMenuItem.Text = "File";
//
// SaveToolStripMenuItem
//
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(125, 26);
this.SaveToolStripMenuItem.Text = "Save";
this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
//
// LoadToolStripMenuItem
//
this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(125, 26);
this.LoadToolStripMenuItem.Text = "Load";
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
//
// openFileDialog
//
this.openFileDialog.Filter = "txt file | *.txt";
//
// saveFileDialog
//
this.saveFileDialog.Filter = "txt file | *.txt";
//
// FormMapWithSetGasolineTanker
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1022, 954);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBoxTools);
this.Controls.Add(this.menuStrip);
this.MainMenuStrip = this.menuStrip;
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormMapWithSetGasolineTanker";
this.Text = "FormMapWithSetGasolineTanker";
this.groupBoxTools.ResumeLayout(false);
this.groupBoxTools.PerformLayout();
this.groupBoxMaps.ResumeLayout(false);
this.groupBoxMaps.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.menuStrip.ResumeLayout(false);
this.menuStrip.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private GroupBox groupBoxTools;
private Button buttonShowOnMap;
private Button buttonShowStorage;
private Button buttonRemoveGasolineTanker;
private Button buttonAddGasolineTanker;
private ComboBox comboBoxSelectorMap;
private PictureBox pictureBox;
private Button keyRight;
private Button keyLeft;
private Button keyUp;
private Button keyDown;
private MaskedTextBox maskedTextBoxPosition;
private GroupBox groupBoxMaps;
private Button buttonAddMap;
private TextBox textBoxNewMapName;
private Button buttonDeleteMap;
private ListBox listBoxMaps;
private MenuStrip menuStrip;
private ToolStripMenuItem fileToolStripMenuItem;
private ToolStripMenuItem SaveToolStripMenuItem;
private ToolStripMenuItem LoadToolStripMenuItem;
private OpenFileDialog openFileDialog;
private SaveFileDialog saveFileDialog;
private Button buttonSortByColor;
private Button buttonSortByType;
}
}

View File

@ -1,283 +0,0 @@
using Microsoft.Extensions.Logging;
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;
namespace GasolineTanker
{
public partial class FormMapWithSetGasolineTanker : Form
{
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
{
{ "Simple map", new SimpleMap() },
{ "Long map", new LongMap() }
};
private readonly MapsCollection _mapsCollection;
private readonly ILogger _logger;
public FormMapWithSetGasolineTanker(ILogger<FormMapWithSetGasolineTanker> logger)
{
InitializeComponent();
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
_logger = logger;
comboBoxSelectorMap.Items.Clear();
foreach (var elem in _mapsDict)
{
comboBoxSelectorMap.Items.Add(elem.Key);
}
}
private void ReloadMaps()
{
int index = listBoxMaps.SelectedIndex;
listBoxMaps.Items.Clear();
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
{
listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
}
if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
{
listBoxMaps.SelectedIndex = 0;
}
else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
{
listBoxMaps.SelectedIndex = index;
}
}
private void ButtonDeleteMap_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
_logger.LogInformation($"Attempt to remove a non - existent card: {textBoxNewMapName.Text}");
return;
}
if (MessageBox.Show($"Delete card {listBoxMaps.SelectedItem}?", "Removal", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
ReloadMaps();
_logger.LogInformation($"Map removed: {listBoxMaps.SelectedItem?.ToString() ?? string.Empty}");
}
}
private void ButtonAddGasolineTanker_Click(object sender, EventArgs e)
{
{
var formGasolineTankerConfig = new FormGasolineTankerConfig();
formGasolineTankerConfig.AddEvent(AddGasolineTankerOnMap);
formGasolineTankerConfig.Show();
}
}
private void AddGasolineTankerOnMap(DrawingGasolineTanker drawingGasolineTanker)
{
try
{
if (listBoxMaps.SelectedIndex == -1)
{
_logger.LogInformation($"Attempt to add a feature to an unselected map");
return;
}
if (drawingGasolineTanker == null)
{
MessageBox.Show("You need to select an object before adding");
_logger.LogInformation($"No object was selected to add to the map");
return;
}
DrawingObjectGasolineTanker gasolineTanker = new DrawingObjectGasolineTanker(drawingGasolineTanker);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + gasolineTanker != -1)
{
MessageBox.Show("Object added");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
_logger.LogInformation($"Object added {drawingGasolineTanker} to map ");
}
else
{
MessageBox.Show("Failed to add item");
_logger.LogInformation($"Failed to add item {drawingGasolineTanker} to map ");
}
}
catch (StorageOverflowException ex)
{
_logger.LogWarning($"Storage full error: {ex.Message}");
MessageBox.Show($"Storage full error: {ex.Message}", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonShowStorage_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
private void ButtonShowOnMap_Click(object sender, EventArgs e)
{
if(listBoxMaps.SelectedIndex == -1)
{
return;
}
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
Direction dir = Direction.None;
switch (name)
{
case "keyUp":
dir = Direction.Up;
break;
case "keyDown":
dir = Direction.Down;
break;
case "keyLeft":
dir = Direction.Left;
break;
case "keyRight":
dir = Direction.Right;
break;
}
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
}
private void buttonAddMap_Click(object sender, EventArgs e)
{
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
{
MessageBox.Show("Not all data is filled", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogInformation("When adding card {0}", comboBoxSelectorMap.SelectedIndex == -1 ? "No card selected" : "No card named");
return;
}
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
{
MessageBox.Show("No such card", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogWarning("No card named: {0}", textBoxNewMapName.Text);
return;
}
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
ReloadMaps();
_logger.LogInformation("Added map {0}", textBoxNewMapName.Text); ;
}
private void buttonDeleteMap_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Delete card {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
_logger.LogInformation("Map removed {0}", listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
ReloadMaps();
}
}
private void listBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
_logger.LogInformation("You have navigated to the map named: {0}", listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
}
private void buttonRemoveGasolineTanker_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{
return;
}
if (MessageBox.Show("Delete object?", "Removal", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
try
{
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
{
MessageBox.Show("Object removed");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
_logger.LogInformation($"Object removed { pos}");
}
else
{
MessageBox.Show("Failed to delete object");
_logger.LogInformation($"Failed to delete object {pos}");
}
}
catch (GasolineTankerNotFoundException ex)
{
_logger.LogWarning($"Deletion error: {ex.Message}");
MessageBox.Show($"Deletion error {ex.Message}");
}
catch (Exception ex)
{
_logger.LogWarning($"Unknown error: {ex.Message}");
MessageBox.Show($"Unknown error {ex.Message}");
}
}
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
_mapsCollection.SaveData(saveFileDialog.FileName);
_logger.LogInformation("The save was successful. The file is located: {0}", saveFileDialog.FileName);
MessageBox.Show("The save was successful", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show($"Not preserved: {ex.Message}", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogWarning("Failed to save file '{0}'. Error text: {1}", saveFileDialog.FileName, ex.Message);
}
}
}
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
_mapsCollection.LoadData(openFileDialog.FileName);
MessageBox.Show("Opening was successful", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
_logger.LogInformation("Opening file '{0}' was successful", openFileDialog.FileName);
ReloadMaps();
}
catch (Exception ex)
{
MessageBox.Show($"Failed to open: {ex.Message}", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogWarning("Failed to open file {0}. Error text: {1}", openFileDialog.FileName, ex.Message);
}
}
}
private void SortBy(IComparer<IDrawingObject> comparer)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(comparer);
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
private void buttonSortByType_Click(object sender, EventArgs e) => SortBy(new GasolineTankerCompareByType());
private void buttonSortByColor_Click(object sender, EventArgs e) => SortBy(new GasolineTankerCompareByColor());
}
}

View File

@ -1,69 +0,0 @@
<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>
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>125, 17</value>
</metadata>
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>265, 17</value>
</metadata>
</root>

View File

@ -8,19 +8,6 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.0" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1" />
<PackageReference Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>

View File

@ -1,39 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GasolineTanker
{
internal class GasolineTankerCompareByColor : IComparer<IDrawingObject>
{
public int Compare(IDrawingObject? x, IDrawingObject? y)
{
var xGasolineTanker = x as DrawingObjectGasolineTanker;
var yGasolineTanker = y as DrawingObjectGasolineTanker;
if (xGasolineTanker == yGasolineTanker)
{
return 0;
}
if (xGasolineTanker == null)
{
return 1;
}
if (yGasolineTanker == null)
{
return -1;
}
var xEntity = xGasolineTanker.GetGasolineTanker.GasolineTanker;
var yEntity = yGasolineTanker.GetGasolineTanker.GasolineTanker;
var colorWeight = xEntity.BodyColor.ToArgb().CompareTo(yEntity.BodyColor.ToArgb());
if (colorWeight != 0 ||
xEntity is not EntityImprovedGasolineTanker xEntityImprovedGasolineTanker ||
yEntity is not EntityImprovedGasolineTanker yEntityImprovedGasolineTanker)
{
return colorWeight;
}
return xEntityImprovedGasolineTanker.DopColor.ToArgb().CompareTo(yEntityImprovedGasolineTanker.DopColor.ToArgb());
}
}
}

View File

@ -1,44 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GasolineTanker
{
internal class GasolineTankerCompareByType : IComparer<IDrawingObject>
{
public int Compare(IDrawingObject? x, IDrawingObject? y)
{
var xGasolineTanker = x as DrawingObjectGasolineTanker;
var yGasolineTanker = y as DrawingObjectGasolineTanker;
if (xGasolineTanker == yGasolineTanker)
{
return 0;
}
if (xGasolineTanker == null)
{
return 1;
}
if (yGasolineTanker == null)
{
return -1;
}
if (xGasolineTanker.GetGasolineTanker.GetType().Name != yGasolineTanker.GetGasolineTanker.GetType().Name)
{
if (xGasolineTanker.GetGasolineTanker.GetType() == typeof(DrawingGasolineTanker))
{
return -1;
}
return 1;
}
var speedCompare = xGasolineTanker.GetGasolineTanker.GasolineTanker.Speed.CompareTo(yGasolineTanker.GetGasolineTanker.GasolineTanker.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return xGasolineTanker.GetGasolineTanker.GasolineTanker.Weight.CompareTo(yGasolineTanker.GetGasolineTanker.GasolineTanker.Weight);
}
}
}

View File

@ -1,20 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
namespace GasolineTanker
{
[Serializable]
internal class GasolineTankerNotFoundException : ApplicationException
{
public GasolineTankerNotFoundException(int i) : base($"Object not found by position { i}") { }
public GasolineTankerNotFoundException() : base() { }
public GasolineTankerNotFoundException(string message) : base(message) { }
public GasolineTankerNotFoundException(string message, Exception exception) : base(message, exception) { }
protected GasolineTankerNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
}
}

View File

@ -1,18 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GasolineTanker
{
internal interface IDrawingObject : IEquatable<IDrawingObject>
{
public float Step { get; }
void SetObject(int x, int y, int width, int height);
void MoveObject(Direction direction);
void DrawningObject(Graphics g);
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
string GetInfo();
}
}

View File

@ -1,49 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GasolineTanker
{
internal class LongMap : AbstractMap
{
private readonly Brush barrierColor = new SolidBrush(Color.Black);
private readonly Brush roadColor = new SolidBrush(Color.Gray);
protected override void DrawBarrierPart(Graphics g, int i, int j)
{
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y);
}
protected override void DrawRoadPart(Graphics g, int i, int j)
{
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
}
protected override void GenerateMap()
{
_map = new int[100, 100];
_size_x = (float)_width / _map.GetLength(0);
_size_y = (float)_height / _map.GetLength(1);
int counter = 0;
for (int i = 0; i < _map.GetLength(0); ++i)
{
for (int j = 0; j < _map.GetLength(1); ++j)
{
_map[i, j] = _freeRoad;
}
}
while (counter < 5)
{
int xStart = _random.Next(0, 100);
int xEnd = _random.Next(80, 100);
for (int i = xStart; i <= xEnd; ++i)
{
_map[i, xStart] = _barrier;
}
counter++;
}
}
}
}

View File

@ -1,142 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GasolineTanker
{
internal class MapWithSetGasolienTankerGeneric<T, U>
where T : class, IEquatable<T>, IDrawingObject
where U : AbstractMap
{
private readonly int _pictureWidth;
private readonly int _pictureHeight;
private readonly int _placeSizeWidth = 210;
private readonly int _placeSizeHeight = 90;
private readonly SetGasolineTankerGeneric<T> _setGasolineTanker;
private readonly U _map;
public MapWithSetGasolienTankerGeneric(int picWidth, int picHeight, U map)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
_setGasolineTanker = new SetGasolineTankerGeneric<T>(width * height);
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_map = map;
}
public static int operator +(MapWithSetGasolienTankerGeneric<T, U> map, T gasolineTanker)
{
return map._setGasolineTanker.Insert(gasolineTanker);
}
public static T operator -(MapWithSetGasolienTankerGeneric<T, U> map, int position)
{
return map._setGasolineTanker.Remove(position);
}
public Bitmap ShowSet()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawGasolineTanker(gr);
return bmp;
}
public Bitmap ShowOnMap()
{
Shaking();
foreach (var gasolineTanker in _setGasolineTanker.GetGasolineTanker())
{
return _map.CreateMap(_pictureWidth, _pictureHeight, gasolineTanker);
}
return new(_pictureWidth, _pictureHeight);
}
public Bitmap MoveObject(Direction direction)
{
if (_map != null)
{
return _map.MoveObject(direction);
}
return new(_pictureWidth, _pictureHeight);
}
public string GetData(char separatorType, char separatorData)
{
string data = $"{_map.GetType().Name}{separatorType}";
foreach (var gasolineTanker in _setGasolineTanker.GetGasolineTanker())
{
data += $"{gasolineTanker.GetInfo()}{separatorData}";
}
return data;
}
public void LoadData(string[] records)
{
foreach (var rec in records)
{
_setGasolineTanker.Insert(DrawingObjectGasolineTanker.Create(rec) as T);
}
}
private void Shaking()
{
int j = _setGasolineTanker.Count - 1;
for (int i = 0; i < _setGasolineTanker.Count; i++)
{
if (_setGasolineTanker[i] == null)
{
for (; j > i; j--)
{
var gasolineTanker = _setGasolineTanker[j];
if (gasolineTanker != null)
{
_setGasolineTanker.Insert(gasolineTanker, i);
_setGasolineTanker.Remove(j);
break;
}
}
if (j <= i)
{
return;
}
}
}
}
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 5);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
{
g.DrawLine(pen, i * _placeSizeWidth + 10, j * _placeSizeHeight + 2, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + 2);
g.DrawLine(pen, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + 2, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.9) + 10, j * _placeSizeHeight + 2 + 20);
g.DrawLine(pen, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.9) + 10, j * _placeSizeHeight + 2 + 20, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.9) + 10, j * _placeSizeHeight + 2 + 20);
}
}
}
private void DrawGasolineTanker(Graphics g)
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
int i = 0;
foreach (var gasolineTanker in _setGasolineTanker.GetGasolineTanker())
{
gasolineTanker.SetObject(i % width * _placeSizeWidth+10, (height - 1 - i / width) * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
gasolineTanker.DrawningObject(g);
i++;
}
}
public void Sort(IComparer<T> comparer)
{
_setGasolineTanker.SortSet(comparer);
}
}
}

View File

@ -1,95 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GasolineTanker
{
internal class MapsCollection
{
readonly Dictionary<string, MapWithSetGasolienTankerGeneric<IDrawingObject, AbstractMap>> _mapStorages;
public List<string> Keys => _mapStorages.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
private readonly char separatorDict = '|';
private readonly char separatorData = ';';
public MapsCollection(int pictureWidth, int pictureHeight)
{
_mapStorages = new Dictionary<string, MapWithSetGasolienTankerGeneric<IDrawingObject, AbstractMap>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
public void AddMap(string name, AbstractMap map)
{
if (!_mapStorages.ContainsKey(name)) _mapStorages.Add(name, new MapWithSetGasolienTankerGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
}
public void DelMap(string name)
{
_mapStorages.Remove(name);
}
public MapWithSetGasolienTankerGeneric<IDrawingObject, AbstractMap> this[string ind]
{
get
{
if (_mapStorages.TryGetValue(ind, out var map)) return map;
return null;
}
}
public void SaveData(string filename)
{
if (File.Exists(filename))
{
File.Delete(filename);
}
using (StreamWriter sw = new StreamWriter(filename))
{
sw.WriteLine($"MapsCollection");
foreach (var storage in _mapStorages)
{
sw.WriteLine($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}");
}
}
}
public void LoadData(string filename)
{
if (!File.Exists(filename))
{
throw new Exception("File not found");
}
using (StreamReader sr = new StreamReader(filename))
{
string str;
_mapStorages.Clear();
str = sr.ReadLine();
if (!str.Contains("MapsCollection"))
{
throw new Exception("The file format is incorrec");
}
while ((str = sr.ReadLine()) != null)
{
var elem = str.Split(separatorDict);
AbstractMap map = null;
switch (elem[1])
{
case "Simple map":
map = new SimpleMap();
break;
case "Long map":
map = new LongMap();
break;
}
_mapStorages.Add(elem[0], new MapWithSetGasolienTankerGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
}
}
}
}
}

View File

@ -1,8 +1,3 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
namespace GasolineTanker
{
internal static class Program
@ -16,30 +11,7 @@ namespace GasolineTanker
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
var services = new ServiceCollection();
ConfigureServices(services);
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
{
Application.Run(serviceProvider.GetRequiredService<FormMapWithSetGasolineTanker>());
}
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddSingleton<FormMapWithSetGasolineTanker>()
.AddLogging(option =>
{
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(path: "C:\\Users\\kashi\\Desktop\\RPP\\GasolineTanker\\GasolineTanker\\GasolineTanker\\appSetting.json", optional: false, reloadOnChange: true)
.Build();
var logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
option.SetMinimumLevel(LogLevel.Information);
option.AddSerilog(logger);
});
Application.Run(new FormGasolineTanker());
}
}
}

View File

@ -1,89 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GasolineTanker
{
internal class SetGasolineTankerGeneric<T>
where T : class, IEquatable<T>
{
private readonly List<T> _places;
public int Count => _places.Count;
private readonly int _maxCount;
public SetGasolineTankerGeneric(int count)
{
_maxCount = count;
_places = new List<T>();
}
public int Insert(T gasolineTanker)
{
return Insert(gasolineTanker, 0);
}
private bool isCorrectPosition(int position)
{
return 0 <= position && position < _maxCount;
}
public int Insert(T gasolineTanker, int position)
{
if (Count == _maxCount)
throw new StorageOverflowException(_maxCount);
if (position < 0 || position > Count)
return -1;
if (_places.Contains(gasolineTanker))
return -1;
_places.Insert(position, gasolineTanker);
return position;
}
public T Remove(int position)
{
if (!isCorrectPosition(position))
return null;
var result = this[position];
if (result == null)
throw new GasolineTankerNotFoundException(position);
_places.RemoveAt(position);
return result;
}
public T this[int position]
{
get
{
if (position < 0 || position >= _places.Count) return null;
return _places[position];
}
set
{
if (position < 0 || position >= _places.Count) return;
_places.Insert(position, value);
}
}
public IEnumerable<T> GetGasolineTanker()
{
foreach (var gasolineTanker in _places)
{
if (gasolineTanker != null)
{
yield return gasolineTanker;
}
else
{
yield break;
}
}
}
public void SortSet(IComparer<T> comparer)
{
if (comparer == null)
{
return;
}
_places.Sort(comparer);
}
}
}

View File

@ -1,47 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GasolineTanker
{
internal class SimpleMap : AbstractMap
{
private readonly Brush barrierColor = new SolidBrush(Color.Black);
private readonly Brush roadColor = new SolidBrush(Color.Gray);
protected override void DrawBarrierPart(Graphics g, int i, int j)
{
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
}
protected override void DrawRoadPart(Graphics g, int i, int j)
{
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
}
protected override void GenerateMap()
{
_map = new int[100, 100];
_size_x = (float)_width / _map.GetLength(0);
_size_y = (float)_height / _map.GetLength(1);
int counter = 0;
for (int i = 0; i < _map.GetLength(0); ++i)
{
for (int j = 0; j < _map.GetLength(1); ++j)
{
_map[i, j] = _freeRoad;
}
}
while (counter < 50)
{
int x = _random.Next(0, 100);
int y = _random.Next(0, 100);
if (_map[x, y] == _freeRoad)
{
_map[x, y] = _barrier;
counter++;
}
}
}
}
}

View File

@ -1,20 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
namespace GasolineTanker
{
[Serializable]
internal class StorageOverflowException : ApplicationException
{
public StorageOverflowException(int count) : base($"The set exceeded the allowed quantity: {count}") { }
public StorageOverflowException() : base() { }
public StorageOverflowException(string message) : base(message) { }
public StorageOverflowException(string message, Exception exception) : base(message, exception) { }
protected StorageOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
}
}

View File

@ -1,20 +0,0 @@
{
"Serilog": {
"Using": [ "Serilog.Sinks.File" ],
"MinimumLevel": "Information",
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "Logs/log_.log",
"rollingInterval": "Day",
"outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}"
}
}
],
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
"Properties": {
"Application": "GasolineTanker"
}
}
}