Compare commits

...

5 Commits
main ... lab4

Author SHA1 Message Date
Александр Чегодаев
8d8e031953 lab4 2023-12-14 01:06:57 +04:00
Александр Чегодаев
160e1ae53b lab3 2023-12-14 00:48:20 +04:00
Александр Чегодаев
7b9c27b2b6 lab2 2023-12-14 00:21:22 +04:00
Александр Чегодаев
4a1039d391 lab1 2023-12-13 23:10:44 +04:00
Александр Чегодаев
b9edd805a8 lab1 2023-12-13 23:02:38 +04:00
30 changed files with 3687 additions and 51 deletions

View File

@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectCruiser.Drawnings;
namespace ProjectCruiser.MovementStrategy
{
public abstract class AbstractStrategy
{
private IMoveableObject? _moveableObject;
private Status _state = Status.NotInit;
protected int FieldWidth { get; private set; }
protected int FieldHeight { get; private set; }
public Status GetStatus() { return _state; }
public void SetData(IMoveableObject moveableObject, int width, int
height)
{
if (moveableObject == null)
{
_state = Status.NotInit;
return;
}
_state = Status.InProgress;
_moveableObject = moveableObject;
FieldWidth = width;
FieldHeight = height;
}
public void MakeStep()
{
if (_state != Status.InProgress)
{
return;
}
if (IsTargetDestinaion())
{
_state = Status.Finish;
return;
}
MoveToTarget();
}
protected bool MoveLeft() => MoveTo(DirectionType.Left);
protected bool MoveRight() => MoveTo(DirectionType.Right);
protected bool MoveUp() => MoveTo(DirectionType.Up);
protected bool MoveDown() => MoveTo(DirectionType.Down);
protected ObjectParameters? GetObjectParameters =>
_moveableObject?.GetObjectPosition;
protected int? GetStep()
{
if (_state != Status.InProgress)
{
return null;
}
return _moveableObject?.GetStep;
}
protected abstract void MoveToTarget();
protected abstract bool IsTargetDestinaion();
private bool MoveTo(DirectionType directionType)
{
if (_state != Status.InProgress)
{
return false;
}
if (_moveableObject?.CheckCanMove(directionType) ?? false)
{
_moveableObject.MoveObject(directionType);
return true;
}
return false;
}
}
}

View File

@ -0,0 +1,103 @@
using ProjectCruiser.DrawningObjects;
using ProjectCruiser.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCruiser
{
internal class CruiserGenericCollection<T, U>
where T : DrawningCruiser
where U : IMoveableObject
{
private readonly int _pictureWidth;
private readonly int _pictureHeight;
private readonly int _placeSizeWidth = 210;
private readonly int _placeSizeHeight = 100;
private readonly SetGeneric<T> _collection;
public CruiserGenericCollection(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 +(CruiserGenericCollection<T, U> collect, T? obj)
{
if (obj == null)
{
return -1;
}
return collect?._collection.Insert(obj);
}
public static bool operator -(CruiserGenericCollection<T, U> collect, int pos)
{
T? obj = collect._collection[pos];
if (obj != null)
{
collect._collection.Remove(pos);
}
return false;
}
public U? GetU(int pos)
{
return (U?)_collection[pos]?.GetMoveableObject;
}
public Bitmap ShowCruiser()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
DrawBackground(gr);
DrawObjects(gr);
return bmp;
}
private void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 3);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight +
1; ++j)
{
g.DrawLine(pen, i * _placeSizeWidth, j *
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2 + 2, j *
_placeSizeHeight);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
private void DrawObjects(Graphics g)
{
int Ix = 3;
int Iy = 15;
int i = 0;
foreach (var cruiser in _collection.GetCruiser())
{
_collection[i]?.SetPosition(Ix, Iy);
_collection[i]?.DrawTransport(g);
Ix += _placeSizeWidth;
if (Ix + _placeSizeHeight > _pictureWidth)
{
Ix = 0;
Iy = _placeSizeHeight;
}
i++;
}
}
}
}

View File

@ -0,0 +1,59 @@
using ProjectCruiser.DrawningObjects;
using ProjectCruiser.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCruiser
{
internal class CruiserGenericStorage
{
readonly Dictionary<string, CruiserGenericCollection<DrawningCruiser,
DrawningObjectCruiser>> _CruiserStorages;
public List<string> Keys => _CruiserStorages.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
public CruiserGenericStorage(int pictureWidth, int pictureHeight)
{
_CruiserStorages = new Dictionary<string,
CruiserGenericCollection<DrawningCruiser, DrawningObjectCruiser>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
public void AddSet(string name)
{
if (!_CruiserStorages.ContainsKey(name))
{
var ustaCollection = new CruiserGenericCollection<DrawningCruiser, DrawningObjectCruiser>(_pictureWidth, _pictureHeight);
_CruiserStorages.Add(name, ustaCollection);
}
}
public void DelSet(string name)
{
if (_CruiserStorages.ContainsKey(name))
{
_CruiserStorages.Remove(name);
}
}
public CruiserGenericCollection<DrawningCruiser, DrawningObjectCruiser>? this[string ind]
{
get
{
if (_CruiserStorages.ContainsKey(ind))
{
return _CruiserStorages[ind];
}
return null;
}
}
}
}

View File

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

View File

@ -0,0 +1,160 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectCruiser.Entities;
using ProjectCruiser.Drawnings;
using System.Drawing.Drawing2D;
using ProjectCruiser.MovementStrategy;
namespace ProjectCruiser.DrawningObjects
{
public class DrawningCruiser
{
public EntityCruiser? EntityCruiser { get; protected set; }
private int _pictureWidth;
private int _pictureHeight;
protected int _startPosX;
protected int _startPosY;
protected readonly int _carWidth = 145;
protected readonly int _carHeight = 45;
public DrawningCruiser(int speed, double weight, Color bodyColor, int
width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
EntityCruiser = new EntityCruiser(speed, weight, bodyColor);
}
protected DrawningCruiser(int speed, double weight, Color bodyColor, int
width, int height, int carWidth, int carHeight)
{
if (width <= _pictureWidth || height <= _pictureHeight)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
_carWidth = carWidth;
_carHeight = carHeight;
EntityCruiser = new EntityCruiser(speed, weight, bodyColor);
}
public void SetPosition(int x, int y)
{
if (x < 0 || y < 0 || x + _carWidth > _pictureWidth || y + _carHeight > _pictureHeight)
{
x = 10;
y = 10;
}
_startPosX = x;
_startPosY = y;
}
public IMoveableObject GetMoveableObject => new DrawningObjectCruiser(this);
protected int PictureWidth
{
get { return _pictureWidth; }
}
protected int PictureHeight
{
get { return _pictureHeight; }
}
public int GetPosX => _startPosX;
public int GetPosY => _startPosY;
public int GetWidth => _carWidth;
public int GetHeight => _carHeight;
public virtual bool CanMove(DirectionType direction)
{
if (EntityCruiser == null)
{
return false;
}
return direction switch
{
DirectionType.Left => _startPosX - EntityCruiser.Step > 0,
DirectionType.Up => _startPosY - EntityCruiser.Step > 7,
DirectionType.Right => _startPosX + EntityCruiser.Step + _carWidth <= _pictureWidth,
DirectionType.Down => _startPosY + EntityCruiser.Step + _carHeight <= _pictureHeight,
_ => false,
};
}
public virtual void MoveTransport(DirectionType direction)
{
if (!CanMove(direction) || EntityCruiser == null)
{
return;
}
switch (direction)
{
case DirectionType.Left:
_startPosX -= (int)EntityCruiser.Step;
break;
case DirectionType.Up:
_startPosY -= (int)EntityCruiser.Step;
break;
case DirectionType.Right:
_startPosX += (int)EntityCruiser.Step;
break;
case DirectionType.Down:
_startPosY += (int)EntityCruiser.Step;
break;
}
}
public virtual void DrawTransport(Graphics g)
{
if (EntityCruiser == null)
{
return;
}
Pen pen = new(Color.Black);
Brush BodyColor = new SolidBrush(EntityCruiser.BodyColor);
GraphicsPath path1 = new GraphicsPath();
path1.AddLine(_startPosX + 100, _startPosY + 0, _startPosX + 0, _startPosY + 0);
path1.AddLine(_startPosX + 0, _startPosY + 50, _startPosX + 0, _startPosY + 0);
path1.AddLine(_startPosX + 0, _startPosY + 50, _startPosX + 100, _startPosY + 50);
path1.AddLine(_startPosX + 100, _startPosY + 50, _startPosX + 150, _startPosY + 25);
path1.AddLine(_startPosX + 100, _startPosY + 0, _startPosX + 150, _startPosY + 25);
g.FillPath(BodyColor, path1);
g.DrawPath(pen, path1);
Brush brBlack = new SolidBrush(Color.Black);
g.DrawRectangle(pen, _startPosX - 3, _startPosY + 7, 3, 15);
g.FillRectangle(brBlack, _startPosX - 3, _startPosY + 7, 3, 15);
g.DrawRectangle(pen, _startPosX - 3, _startPosY + 25, 3, 15);
g.FillRectangle(brBlack, _startPosX - 3, _startPosY + 25, 3, 15);
g.DrawRectangle(pen, _startPosX + 60, _startPosY + 12, 20, 25);
g.FillRectangle(brBlack, _startPosX + 60, _startPosY + 12, 20, 25);
g.DrawRectangle(pen, _startPosX + 30, _startPosY + 19, 30, 13);
g.FillRectangle(brBlack, _startPosX + 30, _startPosY + 19, 30, 13);
}
}
}

View File

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectCruiser.Drawnings;
using ProjectCruiser.Entities;
namespace ProjectCruiser.DrawningObjects
{
public class DrawningCruiserDou : DrawningCruiser
{
public DrawningCruiserDou(int speed, double weight, Color bodyColor, Color
additionalColor, bool vert, bool rocket, int width, int height) :
base(speed, weight, bodyColor, width, height, 145, 45)
{
if (EntityCruiser != null)
{
EntityCruiser = new EntityCruiserDou(speed, weight, bodyColor,
additionalColor, vert, rocket);
}
}
public override void DrawTransport(Graphics g)
{
if (EntityCruiser is not EntityCruiserDou cruiserDou)
{
return;
}
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(cruiserDou.AdditionalColor);
Brush brBlack = new SolidBrush(Color.Black);
base.DrawTransport(g);
if (cruiserDou.Vert)
{
Brush brRed = new SolidBrush(Color.Red);
g.FillEllipse(additionalBrush, _startPosX + 95, _startPosY + 15, 20, 20);
g.DrawEllipse(pen, _startPosX + 95, _startPosY + 15, 20, 20);
}
if (cruiserDou.Rocket)
{
g.DrawEllipse(pen, _startPosX + 8, _startPosY + 3, 15, 12);
g.FillEllipse(additionalBrush, _startPosX + 8, _startPosY + 3, 15, 12);
g.DrawEllipse(pen, _startPosX + 8, _startPosY + 18, 15, 12);
g.FillEllipse(additionalBrush, _startPosX + 8, _startPosY + 18, 15, 12);
g.DrawEllipse(pen, _startPosX + 8, _startPosY + 33, 15, 12);
g.FillEllipse(additionalBrush, _startPosX + 8, _startPosY + 33, 15, 12);
}
}
}
}

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCruiser.Entities
{
public class EntityCruiser
{
public int Speed { get; private set; }
public double Weight { get; private set; }
public Color BodyColor { get; private set; }
public double Step => (double)Speed * 100 / Weight;
public EntityCruiser(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
}
}
}

View File

@ -0,0 +1,22 @@
using System;
namespace ProjectCruiser.Entities
{
public class EntityCruiserDou : EntityCruiser
{
public Color AdditionalColor { get; private set; }
public bool Vert { get; private set; }
public bool Rocket { get; private set; }
public EntityCruiserDou(int speed, double weight, Color bodyColor, Color additionalColor, bool vert, bool rocket)
: base(speed, weight, bodyColor)
{
AdditionalColor = additionalColor;
Vert = vert;
Rocket = rocket;
}
}
}

View File

@ -1,39 +0,0 @@
namespace Cruiser
{
partial class Form1
{
/// <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.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}

View File

@ -1,10 +0,0 @@
namespace Cruiser
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}

187
Cruiser/Cruiser/FormCruiser.Designer.cs generated Normal file
View File

@ -0,0 +1,187 @@
namespace ProjectCruiser
{
partial class FormCruiser
{
/// <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()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormCruiser));
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
this.ButtonCreateCruiserBat = new System.Windows.Forms.Button();
this.ButtonCreateCruiser = new System.Windows.Forms.Button();
this.ButtonStep = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.pictureBoxCruiser = new System.Windows.Forms.PictureBox();
this.ButtonSelectCruiser = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCruiser)).BeginInit();
this.SuspendLayout();
//
// comboBoxStrategy
//
this.comboBoxStrategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxStrategy.FormattingEnabled = true;
this.comboBoxStrategy.Items.AddRange(new object[] {
"MoveToCenter",
"MoveToBorder",
"-"});
this.comboBoxStrategy.Location = new System.Drawing.Point(667, 12);
this.comboBoxStrategy.Name = "comboBoxStrategy";
this.comboBoxStrategy.Size = new System.Drawing.Size(121, 23);
this.comboBoxStrategy.TabIndex = 0;
//
// ButtonCreateCruiserBat
//
this.ButtonCreateCruiserBat.Location = new System.Drawing.Point(19, 386);
this.ButtonCreateCruiserBat.Name = "ButtonCreateCruiserBat";
this.ButtonCreateCruiserBat.Size = new System.Drawing.Size(160, 57);
this.ButtonCreateCruiserBat.TabIndex = 1;
this.ButtonCreateCruiserBat.Text = "Создать крейсер с ракетными шахтами и площадкой под вертолет";
this.ButtonCreateCruiserBat.UseVisualStyleBackColor = true;
this.ButtonCreateCruiserBat.Click += new System.EventHandler(this.ButtonCreateCruiserBat_Click);
//
// ButtonCreateCruiser
//
this.ButtonCreateCruiser.Location = new System.Drawing.Point(185, 386);
this.ButtonCreateCruiser.Name = "ButtonCreateCruiser";
this.ButtonCreateCruiser.Size = new System.Drawing.Size(160, 57);
this.ButtonCreateCruiser.TabIndex = 2;
this.ButtonCreateCruiser.Text = "Создать крейсер";
this.ButtonCreateCruiser.UseVisualStyleBackColor = true;
this.ButtonCreateCruiser.Click += new System.EventHandler(this.ButtonCreateCruiser_Click);
//
// ButtonStep
//
this.ButtonStep.Location = new System.Drawing.Point(713, 50);
this.ButtonStep.Name = "ButtonStep";
this.ButtonStep.Size = new System.Drawing.Size(75, 23);
this.ButtonStep.TabIndex = 3;
this.ButtonStep.Text = "Шаг";
this.ButtonStep.UseVisualStyleBackColor = true;
this.ButtonStep.Click += new System.EventHandler(this.ButtonStep_Click);
//
// buttonUp
//
this.buttonUp.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonUp.BackgroundImage")));
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonUp.Location = new System.Drawing.Point(678, 352);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(44, 38);
this.buttonUp.TabIndex = 4;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonDown
//
this.buttonDown.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonDown.BackgroundImage")));
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonDown.Location = new System.Drawing.Point(678, 395);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(44, 38);
this.buttonDown.TabIndex = 5;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonLeft
//
this.buttonLeft.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonLeft.BackgroundImage")));
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonLeft.Location = new System.Drawing.Point(629, 395);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(44, 38);
this.buttonLeft.TabIndex = 6;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonRight
//
this.buttonRight.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonRight.BackgroundImage")));
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonRight.Location = new System.Drawing.Point(727, 395);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(44, 38);
this.buttonRight.TabIndex = 7;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
// pictureBoxCruiser
//
this.pictureBoxCruiser.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxCruiser.Location = new System.Drawing.Point(0, 0);
this.pictureBoxCruiser.Name = "pictureBoxCruiser";
this.pictureBoxCruiser.Size = new System.Drawing.Size(800, 450);
this.pictureBoxCruiser.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxCruiser.TabIndex = 8;
this.pictureBoxCruiser.TabStop = false;
//
// ButtonSelectCruiser
//
this.ButtonSelectCruiser.Location = new System.Drawing.Point(351, 386);
this.ButtonSelectCruiser.Name = "ButtonSelectCruiser";
this.ButtonSelectCruiser.Size = new System.Drawing.Size(160, 57);
this.ButtonSelectCruiser.TabIndex = 9;
this.ButtonSelectCruiser.Text = "Выбор";
this.ButtonSelectCruiser.UseVisualStyleBackColor = true;
this.ButtonSelectCruiser.Click += new System.EventHandler(this.ButtonSelectCruiser_Click);
//
// FormCruiser
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.ButtonSelectCruiser);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.ButtonStep);
this.Controls.Add(this.ButtonCreateCruiser);
this.Controls.Add(this.ButtonCreateCruiserBat);
this.Controls.Add(this.comboBoxStrategy);
this.Controls.Add(this.pictureBoxCruiser);
this.Name = "FormCruiser";
this.Text = "FormCruiser";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCruiser)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private ComboBox comboBoxStrategy;
private Button ButtonCreateCruiserBat;
private Button ButtonCreateCruiser;
private Button ButtonStep;
private Button buttonUp;
private Button buttonDown;
private Button buttonLeft;
private Button buttonRight;
private PictureBox pictureBoxCruiser;
private Button ButtonSelectCruiser;
}
}

View File

@ -0,0 +1,149 @@
using ProjectCruiser.DrawningObjects;
using ProjectCruiser.Drawnings;
using ProjectCruiser.MovementStrategy;
namespace ProjectCruiser
{
public partial class FormCruiser : Form
{
private DrawningCruiser? _drawningCruiser;
private AbstractStrategy? _abstractStrategy;
public DrawningCruiser? SelectedCruiser { get; private set; }
public FormCruiser()
{
InitializeComponent();
_abstractStrategy = null;
SelectedCruiser = null;
}
private void Draw()
{
if (_drawningCruiser == null)
{
return;
}
Bitmap bmp = new(pictureBoxCruiser.Width,
pictureBoxCruiser.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningCruiser.DrawTransport(gr);
pictureBoxCruiser.Image = bmp;
}
private void ButtonCreateCruiserBat_Click(object sender, EventArgs e)
{
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;
}
Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog_dop = new();
if (dialog_dop.ShowDialog() == DialogResult.OK)
{
dopColor = dialog_dop.Color;
}
_drawningCruiser = new DrawningCruiserDou(random.Next(100, 300),
random.Next(1000, 3000),
color,
dopColor,
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
pictureBoxCruiser.Width, pictureBoxCruiser.Height);
_drawningCruiser.SetPosition(random.Next(10, 100), random.Next(10,100));
Draw();
}
private void ButtonCreateCruiser_Click(object sender, EventArgs e)
{
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;
}
_drawningCruiser = new DrawningCruiser(random.Next(100, 300),
random.Next(1000, 3000),
color,
pictureBoxCruiser.Width, pictureBoxCruiser.Height);
_drawningCruiser.SetPosition(random.Next(10, 100), random.Next(10,100));
Draw();
}
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawningCruiser == null)
{
return;
}
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
case "buttonUp":
_drawningCruiser.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
_drawningCruiser.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
_drawningCruiser.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
_drawningCruiser.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
private void ButtonStep_Click(object sender, EventArgs e)
{
if (_drawningCruiser == null)
{
return;
}
if (comboBoxStrategy.Enabled)
{
_abstractStrategy = comboBoxStrategy.SelectedIndex
switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
if (_abstractStrategy == null)
{
return;
}
_abstractStrategy.SetData(new
DrawningObjectCruiser(_drawningCruiser), pictureBoxCruiser.Width,
pictureBoxCruiser.Height);
comboBoxStrategy.Enabled = false;
}
if (_abstractStrategy != null)
{
_abstractStrategy.MakeStep();
Draw();
if (_abstractStrategy.GetStatus() == Status.Finish)
{
comboBoxStrategy.Enabled = true;
_abstractStrategy = null;
}
}
}
private void ButtonSelectCruiser_Click(object sender, EventArgs e)
{
SelectedCruiser = _drawningCruiser;
DialogResult = DialogResult.OK;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,192 @@
namespace ProjectCruiser
{
partial class FormCruiserCollection
{
/// <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.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.listBoxStorage = new System.Windows.Forms.ListBox();
this.textBoxStorageName = new System.Windows.Forms.MaskedTextBox();
this.ButtonAddObject = new System.Windows.Forms.Button();
this.ButtonDelObject = new System.Windows.Forms.Button();
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
this.ButtonRefreshCollection = new System.Windows.Forms.Button();
this.ButtonRemoveCruiser = new System.Windows.Forms.Button();
this.buttonAddCruiser = new System.Windows.Forms.Button();
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.groupBox2);
this.groupBox1.Controls.Add(this.maskedTextBoxNumber);
this.groupBox1.Controls.Add(this.ButtonRefreshCollection);
this.groupBox1.Controls.Add(this.ButtonRemoveCruiser);
this.groupBox1.Controls.Add(this.buttonAddCruiser);
this.groupBox1.Location = new System.Drawing.Point(643, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(196, 436);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Инструменты";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.listBoxStorage);
this.groupBox2.Controls.Add(this.textBoxStorageName);
this.groupBox2.Controls.Add(this.ButtonAddObject);
this.groupBox2.Controls.Add(this.ButtonDelObject);
this.groupBox2.Location = new System.Drawing.Point(9, 24);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(179, 256);
this.groupBox2.TabIndex = 4;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Наборы";
//
// listBoxStorage
//
this.listBoxStorage.FormattingEnabled = true;
this.listBoxStorage.ItemHeight = 15;
this.listBoxStorage.Location = new System.Drawing.Point(6, 93);
this.listBoxStorage.Name = "listBoxStorage";
this.listBoxStorage.Size = new System.Drawing.Size(167, 109);
this.listBoxStorage.TabIndex = 5;
listBoxStorage.SelectedIndexChanged += listBoxStorage_SelectedIndexChanged;
//
// textBoxStorageName
//
this.textBoxStorageName.Font = new System.Drawing.Font("Lucida Sans Unicode", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.textBoxStorageName.Location = new System.Drawing.Point(6, 22);
this.textBoxStorageName.Name = "textBoxStorageName";
this.textBoxStorageName.Size = new System.Drawing.Size(167, 26);
this.textBoxStorageName.TabIndex = 4;
//
// ButtonAddObject
//
this.ButtonAddObject.Location = new System.Drawing.Point(6, 54);
this.ButtonAddObject.Name = "ButtonAddObject";
this.ButtonAddObject.Size = new System.Drawing.Size(167, 33);
this.ButtonAddObject.TabIndex = 3;
this.ButtonAddObject.Text = "Добавить набор";
this.ButtonAddObject.UseVisualStyleBackColor = true;
this.ButtonAddObject.Click += new System.EventHandler(this.ButtonAddObject_Click);
//
// ButtonDelObject
//
this.ButtonDelObject.Location = new System.Drawing.Point(6, 217);
this.ButtonDelObject.Name = "ButtonDelObject";
this.ButtonDelObject.Size = new System.Drawing.Size(167, 33);
this.ButtonDelObject.TabIndex = 2;
this.ButtonDelObject.Text = "Удалить набор";
this.ButtonDelObject.UseVisualStyleBackColor = true;
this.ButtonDelObject.Click += new System.EventHandler(this.ButtonDelObject_Click);
//
// maskedTextBoxNumber
//
this.maskedTextBoxNumber.Font = new System.Drawing.Font("Lucida Sans Unicode", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.maskedTextBoxNumber.Location = new System.Drawing.Point(34, 325);
this.maskedTextBoxNumber.Mask = "00";
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
this.maskedTextBoxNumber.Size = new System.Drawing.Size(130, 26);
this.maskedTextBoxNumber.TabIndex = 3;
//
// ButtonRefreshCollection
//
this.ButtonRefreshCollection.Location = new System.Drawing.Point(6, 396);
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
this.ButtonRefreshCollection.Size = new System.Drawing.Size(184, 33);
this.ButtonRefreshCollection.TabIndex = 2;
this.ButtonRefreshCollection.Text = "Обовить коллекцию";
this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
//
// ButtonRemoveCruiser
//
this.ButtonRemoveCruiser.Location = new System.Drawing.Point(6, 357);
this.ButtonRemoveCruiser.Name = "ButtonRemoveCruiser";
this.ButtonRemoveCruiser.Size = new System.Drawing.Size(184, 33);
this.ButtonRemoveCruiser.TabIndex = 1;
this.ButtonRemoveCruiser.Text = "Удалить крейсер";
this.ButtonRemoveCruiser.UseVisualStyleBackColor = true;
this.ButtonRemoveCruiser.Click += new System.EventHandler(this.ButtonRemoveCruiser_Click);
//
// buttonAddCruiser
//
this.buttonAddCruiser.Location = new System.Drawing.Point(6, 286);
this.buttonAddCruiser.Name = "buttonAddCruiser";
this.buttonAddCruiser.Size = new System.Drawing.Size(184, 33);
this.buttonAddCruiser.TabIndex = 0;
this.buttonAddCruiser.Text = "Добавить крейсер";
this.buttonAddCruiser.UseVisualStyleBackColor = true;
this.buttonAddCruiser.Click += new System.EventHandler(this.buttonAddCruiser_Click);
//
// pictureBoxCollection
//
this.pictureBoxCollection.Location = new System.Drawing.Point(0, -1);
this.pictureBoxCollection.Name = "pictureBoxCollection";
this.pictureBoxCollection.Size = new System.Drawing.Size(637, 449);
this.pictureBoxCollection.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBoxCollection.TabIndex = 1;
this.pictureBoxCollection.TabStop = false;
//
// FormCruiserCollection
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(851, 458);
this.Controls.Add(this.pictureBoxCollection);
this.Controls.Add(this.groupBox1);
this.Name = "FormCruiserCollection";
this.Text = "FormCruiserCollection";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
this.ResumeLayout(false);
}
#endregion
private GroupBox groupBox1;
private MaskedTextBox maskedTextBoxNumber;
private Button ButtonRefreshCollection;
private Button ButtonRemoveCruiser;
private Button buttonAddCruiser;
private PictureBox pictureBoxCollection;
private GroupBox groupBox2;
private ListBox listBoxStorage;
private MaskedTextBox textBoxStorageName;
private Button ButtonAddObject;
private Button ButtonDelObject;
}
}

View File

@ -0,0 +1,150 @@
using ProjectCruiser.DrawningObjects;
using ProjectCruiser.MovementStrategy;
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 ProjectCruiser
{
public partial class FormCruiserCollection : Form
{
private readonly CruiserGenericStorage _storage;
public FormCruiserCollection()
{
InitializeComponent();
_storage = new CruiserGenericStorage(pictureBoxCollection.Width,
pictureBoxCollection.Height);
}
private void ReloadObjects()
{
int index = listBoxStorage.SelectedIndex;
listBoxStorage.Items.Clear();
for (int i = 0; i < _storage.Keys.Count; i++)
{
listBoxStorage.Items.Add(_storage.Keys[i]);
}
if (listBoxStorage.Items.Count > 0 && (index == -1 || index
>= listBoxStorage.Items.Count))
{
listBoxStorage.SelectedIndex = 0;
}
else if (listBoxStorage.Items.Count > 0 && index > -1 &&
index < listBoxStorage.Items.Count)
{
listBoxStorage.SelectedIndex = index;
}
}
private void ButtonAddObject_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxStorageName.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_storage.AddSet(textBoxStorageName.Text);
ReloadObjects();
}
private void listBoxStorage_SelectedIndexChanged(object sender,
EventArgs e)
{
pictureBoxCollection.Image =
_storage[listBoxStorage.SelectedItem?.ToString() ?? string.Empty]?.ShowCruiser();
}
private void ButtonDelObject_Click(object sender, EventArgs e)
{
if (listBoxStorage.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Удалить объект {listBoxStorage.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_storage.DelSet(listBoxStorage.SelectedItem.ToString()
?? string.Empty);
ReloadObjects();
}
}
private void buttonAddCruiser_Click(object sender, EventArgs e)
{
if (listBoxStorage.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorage.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
FormCruiser form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (obj + form.SelectedCruiser > -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowCruiser();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
private void ButtonRemoveCruiser_Click(object sender, EventArgs e)
{
if (listBoxStorage.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorage.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (obj - pos != null)
{
MessageBox.Show("Объект удален");
pictureBoxCollection.Image = obj.ShowCruiser();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
{
if (listBoxStorage.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorage.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
pictureBoxCollection.Image = obj.ShowCruiser();
}
}
}

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,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectCruiser.Drawnings;
namespace ProjectCruiser.MovementStrategy
{
public interface IMoveableObject
{
ObjectParameters? GetObjectPosition { get; }
int GetStep { get; }
bool CheckCanMove(DirectionType direction);
void MoveObject(DirectionType direction);
void SetPosition(int x, int y);
void Draw(Graphics g);
}
}

View File

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectCruiser.DrawningObjects;
using ProjectCruiser.Drawnings;
namespace ProjectCruiser.MovementStrategy
{
public class DrawningObjectCruiser : IMoveableObject
{
private readonly DrawningCruiser? _drawningCruiser = null;
public DrawningObjectCruiser(DrawningCruiser drawningCruiser)
{
_drawningCruiser = drawningCruiser;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_drawningCruiser == null || _drawningCruiser.EntityCruiser ==
null)
{
return null;
}
return new ObjectParameters(_drawningCruiser.GetPosX,
_drawningCruiser.GetPosY, _drawningCruiser.GetWidth, _drawningCruiser.GetHeight);
}
}
public int GetStep => (int)(_drawningCruiser?.EntityCruiser?.Step ?? 0);
public bool CheckCanMove(DirectionType direction) =>
_drawningCruiser?.CanMove(direction) ?? false;
public void MoveObject(DirectionType direction) =>
_drawningCruiser?.MoveTransport(direction);
public void SetPosition(int x, int y)
{
if (_drawningCruiser != null)
{
_drawningCruiser.SetPosition(x, y);
}
}
public void Draw(Graphics g)
{
if (_drawningCruiser != null)
{
_drawningCruiser.DrawTransport(g);
}
}
}
}

View File

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCruiser.MovementStrategy
{
public class MoveToBorder : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.RightBorder <= FieldWidth &&
objParams.RightBorder + GetStep() >= FieldWidth &&
objParams.DownBorder <= FieldHeight &&
objParams.DownBorder + GetStep() >= FieldHeight;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
var diffX = objParams.RightBorder - FieldWidth;
if (Math.Abs(diffX) > GetStep())
{
MoveRight();
}
var diffY = objParams.DownBorder - FieldHeight;
if (Math.Abs(diffY) > GetStep())
{
MoveDown();
}
}
}
}

View File

@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCruiser.MovementStrategy
{
public class MoveToCenter : AbstractStrategy
{
protected override bool IsTargetDestinaion()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return false;
}
return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 &&
objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
if (objParams == null)
{
return;
}
var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
if (Math.Abs(diffX) > GetStep() || Math.Abs(diffY) > GetStep())
{
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}
}
}

View File

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCruiser.MovementStrategy
{
/// <summary>
/// Параметры-координаты объекта
/// </summary>
public class ObjectParameters
{
private readonly int _x;
private readonly int _y;
private readonly int _width;
private readonly int _height;
public int LeftBorder => _x;
public int TopBorder => _y;
public int RightBorder => _x + _width;
public int DownBorder => _y + _height;
public int ObjectMiddleHorizontal => _x + _width / 2;
public int ObjectMiddleVertical => _y + _height / 2;
public ObjectParameters(int x, int y, int width, int height)
{
_x = x;
_y = y;
_width = width;
_height = height;
}
}
}

View File

@ -1,4 +1,4 @@
namespace Cruiser namespace ProjectCruiser
{ {
internal static class Program internal static class Program
{ {
@ -11,7 +11,7 @@ namespace Cruiser
// 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 Form1()); Application.Run(new FormCruiserCollection());
} }
} }
} }

View File

@ -0,0 +1,103 @@
//------------------------------------------------------------------------------
// <auto-generated>
// Этот код создан программой.
// Исполняемая версия:4.0.30319.42000
//
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
// повторной генерации кода.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ProjectCruiser.Properties {
using System;
/// <summary>
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
/// </summary>
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
// с помощью такого средства, как ResGen или Visual Studio.
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
// с параметром /str или перестройте свой проект VS.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ProjectCruiser.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap вверх {
get {
object obj = ResourceManager.GetObject("вверх", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap влево {
get {
object obj = ResourceManager.GetObject("влево", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap вниз {
get {
object obj = ResourceManager.GetObject("вниз", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap вправо {
get {
object obj = ResourceManager.GetObject("вправо", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -117,4 +117,17 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="вверх" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\вверх.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="влево" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\влево.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="вниз" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\вниз.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="вправо" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\вправо.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root> </root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View File

@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCruiser
{
internal class SetGeneric<T>
where T : class
{
private readonly List<T?> _places;
public int Count => _places.Count;
private readonly int _maxCount;
public SetGeneric(int count)
{
_maxCount = count;
_places = new List<T?>(count);
}
public int Insert(T cruiser)
{
return Insert(cruiser, 0);
}
public int Insert(T cruiser, int position)
{
if (position < 0 || position >= _maxCount)
return -1;
if (Count >= _maxCount)
return -1;
_places.Insert(position, cruiser);
return position;
}
public bool Remove(int position)
{
if ((position < 0) || (position > _maxCount)) return false;
_places.RemoveAt(position);
return true;
}
public T? this[int position]
{
get
{
if (position < 0 || position > _maxCount)
return null;
return _places[position];
}
set
{
if (position < 0 || position > _maxCount)
return;
_places[position] = value;
}
}
public IEnumerable<T?> GetCruiser(int? maxCruiser = null)
{
for (int i = 0; i < _places.Count; ++i)
{
yield return _places[i];
if (maxCruiser.HasValue && i == maxCruiser.Value)
{
yield break;
}
}
}
}
}

15
Cruiser/Cruiser/Status.cs Normal file
View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectCruiser.MovementStrategy
{
public enum Status
{
NotInit,
InProgress,
Finish
}
}