This commit is contained in:
Alenka 2023-11-17 21:18:59 +04:00
parent 36f18be18a
commit c7f9f0fc86
16 changed files with 557 additions and 122 deletions

View File

@ -1,8 +1,11 @@
using System;
using Cruiser;
using Cruiser.MovementStrategy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cruiser.MovementStrategy
{
public abstract class AbstractStrategy
@ -12,7 +15,6 @@ namespace Cruiser.MovementStrategy
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)
{

View File

@ -7,17 +7,20 @@
private void InitializeComponent()
{
this.pictureBoxCruiser = new System.Windows.Forms.PictureBox();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = 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.ButtonUp = new System.Windows.Forms.Button();
this.buttonAdvancedCreate = new System.Windows.Forms.Button();
this.buttonCreate = new System.Windows.Forms.Button();
this.comboBoxCruiser = new System.Windows.Forms.ComboBox();
this.ButtonStep = new System.Windows.Forms.Button();
this.ButtonSelected = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCruiser)).BeginInit();
this.SuspendLayout();
//
// pictureBoxCruiser
//
this.pictureBoxCruiser.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxCruiser.Location = new System.Drawing.Point(0, 0);
this.pictureBoxCruiser.Name = "pictureBoxCruiser";
@ -26,47 +29,57 @@
this.pictureBoxCruiser.TabIndex = 0;
this.pictureBoxCruiser.TabStop = false;
this.pictureBoxCruiser.Click += new System.EventHandler(this.ButtonMove_Click);
// buttonDown
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::Cruiser.Properties.Resources.вниз;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonDown.Location = new System.Drawing.Point(543, 306);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 1;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
// buttonLeft
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::Cruiser.Properties.Resources.влево;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonLeft.Location = new System.Drawing.Point(517, 306);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 2;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
// buttonRight
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::Cruiser.Properties.Resources.вправо;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonRight.Location = new System.Drawing.Point(567, 306);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 3;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
// buttonUp
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::Cruiser.Properties.Resources.вверх;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonUp.Location = new System.Drawing.Point(543, 284);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 4;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// ButtonDown
//
this.ButtonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.ButtonDown.BackgroundImage = global::Cruiser.Properties.Resources.вниз;
this.ButtonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.ButtonDown.Location = new System.Drawing.Point(543, 306);
this.ButtonDown.Name = "ButtonDown";
this.ButtonDown.Size = new System.Drawing.Size(30, 30);
this.ButtonDown.TabIndex = 1;
this.ButtonDown.UseVisualStyleBackColor = true;
this.ButtonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
// ButtonLeft
//
this.ButtonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.ButtonLeft.BackgroundImage = global::Cruiser.Properties.Resources.влево;
this.ButtonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.ButtonLeft.Location = new System.Drawing.Point(517, 306);
this.ButtonLeft.Name = "ButtonLeft";
this.ButtonLeft.Size = new System.Drawing.Size(30, 30);
this.ButtonLeft.TabIndex = 2;
this.ButtonLeft.UseVisualStyleBackColor = true;
this.ButtonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
// ButtonRight
//
this.ButtonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.ButtonRight.BackgroundImage = global::Cruiser.Properties.Resources.вправо;
this.ButtonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.ButtonRight.Location = new System.Drawing.Point(567, 306);
this.ButtonRight.Name = "ButtonRight";
this.ButtonRight.Size = new System.Drawing.Size(30, 30);
this.ButtonRight.TabIndex = 3;
this.ButtonRight.UseVisualStyleBackColor = true;
this.ButtonRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
// ButtonUp
//
this.ButtonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.ButtonUp.BackgroundImage = global::Cruiser.Properties.Resources.вверх;
this.ButtonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.ButtonUp.Location = new System.Drawing.Point(543, 284);
this.ButtonUp.Name = "ButtonUp";
this.ButtonUp.Size = new System.Drawing.Size(30, 30);
this.ButtonUp.TabIndex = 4;
this.ButtonUp.UseVisualStyleBackColor = true;
this.ButtonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonAdvancedCreate
//
this.buttonAdvancedCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonAdvancedCreate.Location = new System.Drawing.Point(12, 267);
this.buttonAdvancedCreate.Name = "buttonAdvancedCreate";
@ -75,7 +88,9 @@
this.buttonAdvancedCreate.Text = "Создать продвинутую версию";
this.buttonAdvancedCreate.UseVisualStyleBackColor = true;
this.buttonAdvancedCreate.Click += new System.EventHandler(this.ButtonAdvancedCreate_Click);
//
// 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(240, 267);
this.buttonCreate.Name = "buttonCreate";
@ -84,7 +99,9 @@
this.buttonCreate.Text = "Создать простую версию";
this.buttonCreate.UseVisualStyleBackColor = true;
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
//
// comboBoxCruiser
//
this.comboBoxCruiser.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxCruiser.FormattingEnabled = true;
this.comboBoxCruiser.Items.AddRange(new object[] {
@ -94,7 +111,9 @@
this.comboBoxCruiser.Name = "comboBoxCruiser";
this.comboBoxCruiser.Size = new System.Drawing.Size(182, 33);
this.comboBoxCruiser.TabIndex = 7;
//
// ButtonStep
//
this.ButtonStep.Location = new System.Drawing.Point(485, 70);
this.ButtonStep.Name = "ButtonStep";
this.ButtonStep.Size = new System.Drawing.Size(112, 34);
@ -102,16 +121,29 @@
this.ButtonStep.Text = "Шаг";
this.ButtonStep.UseVisualStyleBackColor = true;
this.ButtonStep.Click += new System.EventHandler(this.ButtonStep_Click);
//
// ButtonSelected
//
this.ButtonSelected.Location = new System.Drawing.Point(180, 215);
this.ButtonSelected.Name = "ButtonSelected";
this.ButtonSelected.Size = new System.Drawing.Size(105, 34);
this.ButtonSelected.TabIndex = 9;
this.ButtonSelected.Text = "Выбрать";
this.ButtonSelected.UseVisualStyleBackColor = true;
this.ButtonSelected.Click += new System.EventHandler(this.ButtonSelectedCruiser_Click);
//
// CruiserForm
//
this.ClientSize = new System.Drawing.Size(667, 358);
this.Controls.Add(this.ButtonSelected);
this.Controls.Add(this.ButtonStep);
this.Controls.Add(this.comboBoxCruiser);
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.buttonAdvancedCreate);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.ButtonUp);
this.Controls.Add(this.ButtonRight);
this.Controls.Add(this.ButtonLeft);
this.Controls.Add(this.ButtonDown);
this.Controls.Add(this.pictureBoxCruiser);
this.Name = "CruiserForm";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCruiser)).EndInit();
@ -122,13 +154,14 @@
#endregion
private PictureBox pictureBoxCruiser;
private Button buttonDown;
private Button buttonLeft;
private Button buttonRight;
private Button buttonUp;
private Button ButtonDown;
private Button ButtonLeft;
private Button ButtonRight;
private Button ButtonUp;
private Button buttonAdvancedCreate;
private Button buttonCreate;
private ComboBox comboBoxCruiser;
private Button ButtonStep;
private Button ButtonSelected;
}
}

View File

@ -9,9 +9,12 @@ namespace Cruiser
private DrawningCruiser? _drawningCruiser;
private AbstractStrategy? _abstractStrategy;
public DrawningCruiser? SelectedCruiser { get; private set; }
public CruiserForm()
{
InitializeComponent();
_abstractStrategy = null;
SelectedCruiser = null;
}
private void Draw()
{
@ -51,13 +54,16 @@ namespace Cruiser
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random random = new();
_drawningCruiser = new DrawningCruiser(random.Next(100, 300),
random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
random.Next(0, 256)),
pictureBoxCruiser.Width, pictureBoxCruiser.Height);
_drawningCruiser.SetPosition(random.Next(10, 100), random.Next(10,
100));
Color color = Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256));
ColorDialog dialogColor = new();
if (dialogColor.ShowDialog() == DialogResult.OK)
{
color = dialogColor.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 ButtonStep_Click(object sender, EventArgs e)
@ -81,7 +87,6 @@ namespace Cruiser
}
_abstractStrategy.SetData(new DrawningObjectCruiser(_drawningCruiser), pictureBoxCruiser.Width,
pictureBoxCruiser.Height);
comboBoxCruiser.Enabled = false;
}
if (_abstractStrategy == null)
{
@ -98,20 +103,33 @@ namespace Cruiser
private void ButtonAdvancedCreate_Click(object sender, EventArgs e)
{
Random random = new();
_drawningCruiser = new DrawningAdvancedCruiser(random.Next(100, 300),
random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)),
Color color = Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256));
ColorDialog dialogColor = new();
if (dialogColor.ShowDialog() == DialogResult.OK)
{
color = dialogColor.Color;
}
Color dopColor = Color.FromArgb(random.Next(0, 256),
random.Next(0, 256), random.Next(0, 256));
ColorDialog dialogDopColor = new();
if (dialogDopColor.ShowDialog() == DialogResult.OK)
{
dopColor = dialogDopColor.Color;
}
_drawningCruiser = new DrawningAdvancedCruiser(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));
_drawningCruiser.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void ButtonSelectedCruiser_Click(object sender, EventArgs e)
{
SelectedCruiser = _drawningCruiser;
DialogResult = DialogResult.OK;
}
}
}

View File

@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cruiser.Generics;
using Cruiser.DrawningObjects;
using Cruiser.Entities;
using Cruiser.MovementStrategy;
namespace Cruiser.Generics
{
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 = 90;
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.Get(pos);
if (obj != null)
{
collect._collection.Remove(pos);
}
return false;
}
public U? GetU(int pos)
{
return (U?)_collection.Get(pos)?.GetMoveableObject;
}
public Bitmap ShowCruisers()
{
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, j *
_placeSizeHeight);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
private void DrawObjects(Graphics g)
{
for (int i = 0; i < _collection.Count; i++)
{
DrawningCruiser cruiser = _collection.Get(i);
if (cruiser != null)
{
int numPlacesInRow = _pictureWidth / _placeSizeWidth;
cruiser.SetPosition((i % numPlacesInRow) * _placeSizeWidth + _placeSizeWidth / 20, _placeSizeHeight * (i / numPlacesInRow) + _placeSizeHeight / 10);
cruiser.DrawTransport(g);
}
}
}
}
}

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cruiser
{
public enum Direction

View File

@ -1,19 +1,22 @@
using Cruiser.DrawningObjects;
using System;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Cruiser.Entities;
namespace Cruiser.DrawningObjects
{
public class DrawningAdvancedCruiser : DrawningCruiser
{
public DrawningAdvancedCruiser(int speed, double weight, Color bodyColor, Color additionalColor, bool headlights, bool helicopterPad, bool coating, int width, int height) : base(speed, weight, bodyColor, width, height, 150, 50)
public DrawningAdvancedCruiser(int speed, double weight, Color bodyColor, Color additionalColor, bool helicopterPad, bool coating, int width, int height) : base(speed, weight, bodyColor, width, height, 110, 60)
{
if (EntityCruiser != null)
{
EntityCruiser = new EntityAdvancedCruiser(speed, weight, bodyColor, additionalColor, headlights, helicopterPad, coating);
EntityCruiser = new EntityAdvancedCruiser(speed, weight, bodyColor, additionalColor, helicopterPad, coating);
}
}
public override void DrawTransport(Graphics g)
@ -26,7 +29,7 @@ namespace Cruiser.DrawningObjects
Brush addBrush = new SolidBrush(cruiser.AdditionalColor);
Brush brush = new SolidBrush(cruiser.BodyColor);
base.DrawTransport(g);
if (cruiser.Headlights)
if (cruiser.HelicopterPad)
{
Brush brYellow = new SolidBrush(Color.Yellow);
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 5, 20,
@ -34,15 +37,11 @@ namespace Cruiser.DrawningObjects
g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 35, 20,
20);
}
if (cruiser.HelicopterPad)
{
g.FillEllipse(Brushes.Green, _startPosX + 90, _startPosY + 20, 20, 20);
}
if (cruiser.Coating)
{
g.FillEllipse(Brushes.Red, _startPosX + 80, _startPosY + 20, 20, 20);
g.FillEllipse(Brushes.Red, _startPosX + 60, _startPosY + 20, 20, 20);
g.FillEllipse(Brushes.Green, _startPosX + 90, _startPosY + 20, 20, 20);
}
}
}
}
}
}

View File

@ -4,29 +4,24 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cruiser.Entities;
using Cruiser.MovementStrategy;
namespace Cruiser.DrawningObjects
{
public class DrawningCruiser
{
public EntityCruiser ? EntityCruiser { get; protected set; }
public EntityCruiser? EntityCruiser { get; protected set; }
private int _pictureWidth;
private int _pictureHeight;
protected int _startPosX;
protected int _startPosY;
private readonly int _cruiserWidth = 150;
private readonly int _cruiserHeight = 50;
private readonly int _cruiserWidth = 110;
private readonly int _cruiserHeight = 60;
public int GetPosX => _startPosX;
public int GetPosY => _startPosY;
public int GetWidth => _cruiserWidth;
public int GetHeight => _cruiserHeight;
public IMoveableObject GetMoveableObject => new DrawningObjectCruiser(this);
public DrawningCruiser(int speed, double weight, Color bodyColor, int width, int height)
{
if (width < _cruiserWidth || height < _cruiserHeight)
@ -118,24 +113,17 @@ width, int height, int cruiserWidth, int cruiserHeight)
g.FillRectangle(br, _startPosX + 10, _startPosY + 15, 10, 30);
g.FillRectangle(br, _startPosX + 90, _startPosY + 15, 10, 30);
g.FillRectangle(br, _startPosX + 20, _startPosY + 5, 70, 50);
Point[] points = new Point[3];
Point[] points = new Point[3];//
points[0] = new Point(_startPosX + 100, _startPosY + 5);
points[1] = new Point(_startPosX + 100, _startPosY + 55);
points[2] = new Point(_startPosX + 100 + 50, _startPosY + 50 / 2);
g.FillPolygon(Brushes.Pink, points);
Point[] points1 = new Point[3];
points1[0] = new Point(_startPosX + 100, _startPosY + 5);
points1[1] = new Point(_startPosX + 100, _startPosY + 55);
points1[2] = new Point(_startPosX + 100 + 50, _startPosY + 50 / 2);
g.DrawPolygon(pen, points1);
g.FillRectangle(Brushes.Black, _startPosX + 5, _startPosY + 15, 10, 10);
g.FillRectangle(Brushes.Black, _startPosX + 5, _startPosY + 35, 10, 10);
g.DrawRectangle(Pens.Black, _startPosX + 35,
_startPosY + 23, 15, 15);
g.DrawRectangle(Pens.Black, _startPosX + 50,
_startPosY + 19, 30, 25);
}
}
}

View File

@ -4,7 +4,6 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cruiser.DrawningObjects;
namespace Cruiser.MovementStrategy
{
internal class DrawningObjectCruiser : IMoveableObject

View File

@ -1,25 +1,25 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;
using System.Windows.Forms;
namespace Cruiser.Entities
{
public class EntityAdvancedCruiser : EntityCruiser
{
public Color AdditionalColor { get; private set; }
public bool Headlights { get; private set; }
public bool HelicopterPad { get; private set; }
public bool Coating { get; private set; }
public EntityAdvancedCruiser(int speed, double weight, Color bodyColor, Color
additionalColor, bool headlights, bool helicopterPad, bool coating) : base(speed, weight, bodyColor)
{
AdditionalColor = additionalColor;
Headlights = headlights;
HelicopterPad = helicopterPad;
Coating = coating;
public bool HelicopterPad { get; private set; }
public bool Coating { get; private set; }
public EntityAdvancedCruiser(int speed, double weight, Color bodyColor, Color
additionalColor, bool helicopterPad, bool coating) : base(speed, weight, bodyColor)
{
AdditionalColor = additionalColor;
HelicopterPad = helicopterPad;
Coating = coating;
}
}
}

View File

@ -0,0 +1,111 @@
namespace Cruiser
{
partial class FormCruiserCollection
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.pictureBoxCruiser = new System.Windows.Forms.PictureBox();
this.panelCruiser = new System.Windows.Forms.Panel();
this.ButtonRemoveCruiser = new System.Windows.Forms.Button();
this.ButtonAddCruiser = new System.Windows.Forms.Button();
this.textBoxCruiser = new System.Windows.Forms.TextBox();
this.ButtonRefresh = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCruiser)).BeginInit();
this.panelCruiser.SuspendLayout();
this.SuspendLayout();
//
// 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 = 0;
this.pictureBoxCruiser.TabStop = false;
//
// panelCruiser
//
this.panelCruiser.Controls.Add(this.ButtonRefresh);
this.panelCruiser.Controls.Add(this.ButtonRemoveCruiser);
this.panelCruiser.Controls.Add(this.ButtonAddCruiser);
this.panelCruiser.Controls.Add(this.textBoxCruiser);
this.panelCruiser.Location = new System.Drawing.Point(589, 12);
this.panelCruiser.Name = "panelCruiser";
this.panelCruiser.Size = new System.Drawing.Size(211, 438);
this.panelCruiser.TabIndex = 1;
//
// ButtonRemoveCruiser
//
this.ButtonRemoveCruiser.Location = new System.Drawing.Point(31, 168);
this.ButtonRemoveCruiser.Name = "ButtonRemoveCruiser";
this.ButtonRemoveCruiser.Size = new System.Drawing.Size(150, 34);
this.ButtonRemoveCruiser.TabIndex = 2;
this.ButtonRemoveCruiser.Text = "Удалить";
this.ButtonRemoveCruiser.UseVisualStyleBackColor = true;
this.ButtonRemoveCruiser.Click += new System.EventHandler(this.ButtonRemoveCruiser_Click);
//
// ButtonAddCruiser
//
this.ButtonAddCruiser.Location = new System.Drawing.Point(31, 37);
this.ButtonAddCruiser.Name = "ButtonAddCruiser";
this.ButtonAddCruiser.Size = new System.Drawing.Size(150, 34);
this.ButtonAddCruiser.TabIndex = 3;
this.ButtonAddCruiser.Text = "Добавить";
this.ButtonAddCruiser.UseVisualStyleBackColor = true;
this.ButtonAddCruiser.Click += new System.EventHandler(this.ButtonAddCruiser_Click);
//
// textBoxCruiser
//
this.textBoxCruiser.Location = new System.Drawing.Point(31, 104);
this.textBoxCruiser.Name = "textBoxCruiser";
this.textBoxCruiser.Size = new System.Drawing.Size(150, 31);
this.textBoxCruiser.TabIndex = 2;
//
// ButtonRefresh
//
this.ButtonRefresh.Location = new System.Drawing.Point(46, 324);
this.ButtonRefresh.Name = "ButtonRefresh";
this.ButtonRefresh.Size = new System.Drawing.Size(120, 31);
this.ButtonRefresh.TabIndex = 2;
this.ButtonRefresh.Text = "Обновить";
this.ButtonRefresh.UseVisualStyleBackColor = true;
this.ButtonRefresh.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
//
// FormCruiserCollection
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.panelCruiser);
this.Controls.Add(this.pictureBoxCruiser);
this.Name = "FormCruiserCollection";
this.Text = "FormCruiserCollection";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCruiser)).EndInit();
this.panelCruiser.ResumeLayout(false);
this.panelCruiser.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private PictureBox pictureBoxCruiser;
private Panel panelCruiser;
private Button ButtonRemoveCruiser;
private Button ButtonAddCruiser;
private TextBox textBoxCruiser;
private Button ButtonRefresh;
}
}

View File

@ -0,0 +1,64 @@
using Cruiser.Generics;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Cruiser.DrawningObjects;
using Cruiser.MovementStrategy;
namespace Cruiser
{
public partial class FormCruiserCollection : Form
{
private readonly CruiserGenericCollection<DrawningCruiser, DrawningObjectCruiser> _cruiser;
public FormCruiserCollection()
{
InitializeComponent();
_cruiser = new CruiserGenericCollection<DrawningCruiser, DrawningObjectCruiser>(pictureBoxCruiser.Width, pictureBoxCruiser.Height);
}
private void ButtonAddCruiser_Click(object sender, EventArgs e)
{
CruiserForm form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (_cruiser + form.SelectedCruiser != -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCruiser.Image = _cruiser.ShowCruisers();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
private void ButtonRemoveCruiser_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(textBoxCruiser.Text);
if (_cruiser - pos != true)
{
MessageBox.Show("Объект удален");
pictureBoxCruiser.Image = _cruiser.ShowCruisers();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
{
pictureBoxCruiser.Image = _cruiser.ShowCruisers();
}
}
}

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

@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cruiser.MovementStrategy;
namespace Cruiser.MovementStrategy
{
public interface IMoveableObject

View File

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cruiser.MovementStrategy;
namespace Cruiser.MovementStrategy
{
@ -21,7 +20,6 @@ namespace Cruiser.MovementStrategy
objParams.DownBorder <= FieldHeight &&
objParams.DownBorder + GetStep() >= FieldHeight;
}
protected override void MoveToTarget()
{
var objParams = GetObjectParameters;
@ -51,10 +49,9 @@ namespace Cruiser.MovementStrategy
else
{
MoveDown();
}
}
}
}
}

View File

@ -2,13 +2,16 @@ namespace Cruiser
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new CruiserForm());
Application.Run(new FormCruiserCollection());
}
}
}

View File

@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Cruiser.Generics
{
internal class SetGeneric<T>
where T : class
{
private readonly T?[] _places;
public int Count => _places.Length;
public int startPointer = 0;
public SetGeneric(int count)
{
_places = new T?[count];
}
public int Insert(T cruiser)
{
return Insert(cruiser, 0);
}
public int Insert(T cruiser, int position)
{
int nullIndex = -1, i;
if (position < 0 || position >= Count)
{
return -1;
}
for (i = position; i < Count; i++)
{
if (_places[i] == null)
{
nullIndex = i;
break;
}
}
if (nullIndex < 0)
{
return -1;
}
for (i = nullIndex; i > position; i--)
{
_places[i] = _places[i - 1];
}
_places[position] = cruiser;
return position;
}
public bool Remove(int position)
{
if (position < 0 || position >= Count)
{
return false;
}
_places[position] = null;
return true;
}
public T? Get(int position)
{
if (position < 0 || position >= Count)
{
return null;
}
return _places[position];
}
}
}