This commit is contained in:
Аркадий Радаев 2023-11-25 20:02:11 +04:00
parent a9f980816e
commit 5ce4825742
11 changed files with 708 additions and 88 deletions

View File

@ -81,7 +81,7 @@ namespace Catamaran
if (catamaran!= null) if (catamaran!= null)
{ {
int inRow = _pictureWidth / _placeSizeWidth; int inRow = _pictureWidth / _placeSizeWidth;
catamaran.SetPosition(i % inRow * _placeSizeWidth, ((_collection.Count / inRow - 1 - i / inRow) * _placeSizeHeight)+5); catamaran.SetPosition(i % inRow * _placeSizeWidth, _pictureHeight - _pictureHeight % _placeSizeHeight - (i / inRow + 1) * _placeSizeHeight);
catamaran.DrawTransport(g); catamaran.DrawTransport(g);
} }
i++; i++;

View File

@ -8,7 +8,7 @@ namespace Catamaran
{ {
public class DrawningCatamaran public class DrawningCatamaran
{ {
public EntityCatamaran? EntityCatamaran { get; set; } public EntityCatamaran? EntityCatamaran { get; set; }
public int _pictureWidth = 800; public int _pictureWidth = 800;
@ -24,45 +24,47 @@ namespace Catamaran
public IMoveableObject GetMoveableObject => new DrawningObjectCatamaran(this); public IMoveableObject GetMoveableObject => new DrawningObjectCatamaran(this);
public DrawningCatamaran(int speed, double weight, Color bodyColor, Color additioncolor, int width, int height, bool seats) public DrawningCatamaran(int speed, double weight, Color bodyColor, int width, int height)
{ {
if (_pictureHeight < _catamaranWidth && _pictureWidth < _catamaranHeight) return; if (_pictureHeight < _catamaranWidth && _pictureWidth < _catamaranHeight) return;
_pictureWidth = width; _pictureWidth = width;
_pictureHeight = height; _pictureHeight = height;
EntityCatamaran = new EntityCatamaran(speed,weight,bodyColor,additioncolor,seats); EntityCatamaran = new EntityCatamaran(speed,weight,bodyColor);
} }
protected DrawningCatamaran(int speed, double weight, Color bodyColor, Color additioncolor, int width, int height, int catWidth, int catHeight, bool seats) protected DrawningCatamaran(int speed, double weight, Color bodyColor, int width, int height, int catWidth, int catHeight)
{ {
if (width <= _catamaranWidth || height <= _catamaranHeight) return; if (width <= _catamaranWidth || height <= _catamaranHeight) return;
_pictureWidth = width; _pictureWidth = width;
_pictureHeight = height; _pictureHeight = height;
_catamaranWidth = catWidth; _catamaranWidth = catWidth;
_catamaranHeight = catHeight; _catamaranHeight = catHeight;
EntityCatamaran = new EntityCatamaran(speed, weight, bodyColor, additioncolor, seats); EntityCatamaran = new EntityCatamaran(speed, weight, bodyColor);
} }
public void ChangeColor(Color col)
{
if (EntityCatamaran == null)
return;
EntityCatamaran.BodyColor = col;
}
public void ChangePictureBoxSize(int pictureBoxWidth, int pictureBoxHeight)
{
_pictureHeight = pictureBoxHeight;
_pictureWidth = pictureBoxWidth;
}
public void SetPosition(int x, int y) public void SetPosition(int x, int y)
{ {
if(EntityCatamaran == null) return; if(EntityCatamaran == null) return;
while(x + _catamaranWidth > _pictureWidth)
{
x-= (int)EntityCatamaran.Step;
}
while (x < 0)
{
x+= (int)EntityCatamaran.Step;
}
while (y + _catamaranHeight > _pictureHeight)
{
y-= (int)EntityCatamaran.Step;
}
while (y < 0)
{
y+= (int)EntityCatamaran.Step;
}
_startPosX = x; _startPosX = x;
_startPosY = y; _startPosY = y;
if (x + _catamaranWidth >= _pictureWidth || y + _catamaranHeight >= _pictureHeight)
{
_startPosX = 1;
_startPosY = 1;
}
} }
public int GetPosX => _startPosX; public int GetPosX => _startPosX;
public int GetPosY => _startPosY; public int GetPosY => _startPosY;
@ -135,11 +137,8 @@ namespace Catamaran
} }
Pen pen = new(Color.Black); Pen pen = new(Color.Black);
Brush bodyBrush = new SolidBrush(EntityCatamaran.BodyColor); Brush bodyBrush = new SolidBrush(Cat.BodyColor);
Brush ellipseBrush = new SolidBrush(EntityCatamaran.AdditionalColor); Brush ellipseBrush = new SolidBrush(Color.AliceBlue);
Point[] pontf = { new Point(_startPosX + _catamaranWidth - 40, _startPosY+10), new Point(_startPosX + _catamaranWidth, _startPosY + 40), new Point(_startPosX + _catamaranWidth - 40, _startPosY + 70) };
g.DrawPolygon(pen, pontf);
g.FillRectangle(bodyBrush, _startPosX+10, _startPosY+10, _catamaranWidth - 50, 60); g.FillRectangle(bodyBrush, _startPosX+10, _startPosY+10, _catamaranWidth - 50, 60);
g.DrawRectangle(pen, _startPosX+10, _startPosY+10, _catamaranWidth - 50, 60); g.DrawRectangle(pen, _startPosX+10, _startPosY+10, _catamaranWidth - 50, 60);
@ -147,12 +146,12 @@ namespace Catamaran
g.FillEllipse(ellipseBrush, _startPosX + 15, _startPosY + 25, 60, 30); g.FillEllipse(ellipseBrush, _startPosX + 15, _startPosY + 25, 60, 30);
g.DrawEllipse(pen, _startPosX + 15, _startPosY + 25, 60, 30); g.DrawEllipse(pen, _startPosX + 15, _startPosY + 25, 60, 30);
if (Cat.Seats) g.DrawEllipse(pen, _startPosX + 20, _startPosY + 35, 10, 10);
{ g.DrawEllipse(pen, _startPosX + 35, _startPosY + 35, 10, 10);
g.DrawEllipse(pen, _startPosX + 20, _startPosY + 35, 10, 10); g.DrawEllipse(pen, _startPosX + 50, _startPosY + 35, 10, 10);
g.DrawEllipse(pen, _startPosX + 35, _startPosY + 35, 10, 10);
g.DrawEllipse(pen, _startPosX + 50, _startPosY + 35, 10, 10); Point[] pontf = { new Point(_startPosX + _catamaranWidth - 40, _startPosY+10), new Point(_startPosX + _catamaranWidth, _startPosY + 40), new Point(_startPosX + _catamaranWidth - 40, _startPosY + 70) };
} g.DrawPolygon(pen, pontf);
} }
} }
} }

View File

@ -8,14 +8,18 @@ namespace Catamaran
{ {
public class DrawningCatamaranPro : DrawningCatamaran public class DrawningCatamaranPro : DrawningCatamaran
{ {
public DrawningCatamaranPro(int speed, double weight, Color bodyColor,Color otherColor, Color additionalColor, bool bodyKit, bool motor, bool sheet, int width, int height, bool seats) : public DrawningCatamaranPro(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool motor, bool sail, int width, int height) :
base(speed, weight, bodyColor,additionalColor, width, height, seats) base(speed, weight, bodyColor, width, height)
{ {
if (EntityCatamaran != null) if (EntityCatamaran != null)
{ {
EntityCatamaran = new EntityCatamaranPro(speed, weight, bodyColor, additionalColor,otherColor,bodyKit, motor, sheet, seats); EntityCatamaran = new EntityCatamaranPro(speed, weight, bodyColor, additionalColor,bodyKit, motor, sail);
} }
} }
public void ChangeAddColor(Color col)
{
((EntityCatamaranPro)EntityCatamaran).AdditionalColor = col;
}
public override void DrawTransport(Graphics g) public override void DrawTransport(Graphics g)
{ {
@ -27,7 +31,7 @@ namespace Catamaran
Pen pen = new(Color.Black); Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(CatPro.AdditionalColor); Brush additionalBrush = new SolidBrush(CatPro.AdditionalColor);
Brush floatsBrush = new SolidBrush(CatPro.OtherColor); Brush floatsBrush = new SolidBrush(CatPro.AdditionalColor);
if (CatPro.Motor) if (CatPro.Motor)
{ {
g.FillRectangle(additionalBrush, _startPosX, _startPosY+25, 10, 30); g.FillRectangle(additionalBrush, _startPosX, _startPosY+25, 10, 30);
@ -47,10 +51,7 @@ namespace Catamaran
g.DrawPolygon(pen, trig1); g.DrawPolygon(pen, trig1);
Point[] trig2 = { new Point(_startPosX + _catamaranWidth - 20, _startPosY + 70), new Point(_startPosX + _catamaranWidth, _startPosY + 75), new Point(_startPosX + _catamaranWidth - 20, _startPosY + 80) }; Point[] trig2 = { new Point(_startPosX + _catamaranWidth - 20, _startPosY + 70), new Point(_startPosX + _catamaranWidth, _startPosY + 75), new Point(_startPosX + _catamaranWidth - 20, _startPosY + 80) };
g.DrawPolygon(pen, trig2); g.DrawPolygon(pen, trig2);
}
if (CatPro.Sheet)
{
for (int i = 10; i< 100; i+=10) for (int i = 10; i< 100; i+=10)
{ {
Point point1 = new Point(_startPosX+i, _startPosY); Point point1 = new Point(_startPosX+i, _startPosY);
@ -63,7 +64,16 @@ namespace Catamaran
Point point4 = new Point(_startPosX+i, _startPosY+_catamaranHeight); Point point4 = new Point(_startPosX+i, _startPosY+_catamaranHeight);
g.DrawLine(pen, point3, point4); g.DrawLine(pen, point3, point4);
} }
}
if (CatPro.Sail)
{
SolidBrush machta = new SolidBrush(Color.Brown);
SolidBrush sail = new SolidBrush(Color.White);
Point[] pointf = { new Point(_startPosX+50, _startPosY+40), new Point(_startPosX+60,_startPosY+40), new Point(_startPosX+45, _startPosY+20), new Point(_startPosX+35, _startPosY+20) };
g.FillPolygon(sail,pointf);
g.DrawPolygon(pen,pointf);
g.FillEllipse(machta, _startPosX + 50, _startPosY + 35, 10, 10);
} }
Point[] points = { new Point(_startPosX + _catamaranWidth - 35, _startPosY+20), new Point(_startPosX + _catamaranWidth - 10, _startPosY + 40), new Point(_startPosX + _catamaranWidth - 35, _startPosY + 60) }; Point[] points = { new Point(_startPosX + _catamaranWidth - 35, _startPosY+20), new Point(_startPosX + _catamaranWidth - 10, _startPosY + 40), new Point(_startPosX + _catamaranWidth - 35, _startPosY + 60) };
g.FillPolygon(additionalBrush, points); g.FillPolygon(additionalBrush, points);

View File

@ -13,21 +13,15 @@ namespace Catamaran
public double Weight { get; private set; } public double Weight { get; private set; }
public Color BodyColor { get; private set; } public Color BodyColor { get; set; }
public Color AdditionalColor { get; private set; }
public bool Seats { get; private set; }
public double Step => (double)Speed * 100 / Weight; public double Step => (double)Speed * 100 / Weight;
public EntityCatamaran(int speed, double weight, Color bodyColor, Color additionalColor, bool seats) public EntityCatamaran(int speed, double weight, Color bodyColor)
{ {
Speed = speed; Speed = speed;
Weight = weight; Weight = weight;
BodyColor = bodyColor; BodyColor = bodyColor;
AdditionalColor = additionalColor;
Seats = seats;
} }
} }

View File

@ -10,17 +10,17 @@ namespace Catamaran
public class EntityCatamaranPro : EntityCatamaran public class EntityCatamaranPro : EntityCatamaran
{ {
public Color OtherColor { get; private set; } public Color AdditionalColor { get; set; }
public bool Motor { get; private set; } public bool Motor { get; private set; }
public bool BodyKit { get; private set; } public bool BodyKit { get; private set; }
public bool Sheet { get; private set; } public bool Sail { get; private set; }
public EntityCatamaranPro(int speed, double weight, Color bodyColor,Color additionalColor, Color otherColor, bool bodykit, bool motor, bool sheet, bool seats) : public EntityCatamaranPro(int speed, double weight, Color bodyColor,Color additionalColor, bool bodykit, bool motor, bool sail) :
base(speed, weight, bodyColor, additionalColor, seats) base(speed, weight, bodyColor)
{ {
OtherColor = otherColor; AdditionalColor = additionalColor;
Motor = motor; Motor = motor;
Sheet = sheet; Sail = sail;
BodyKit = bodykit; BodyKit = bodykit;
} }

View File

@ -18,7 +18,7 @@
private void InitializeComponent() private void InitializeComponent()
{ {
pictureBoxCatatamaran=new PictureBox(); pictureBox=new PictureBox();
buttonCreateBasic=new Button(); buttonCreateBasic=new Button();
buttonUp=new Button(); buttonUp=new Button();
buttonRight=new Button(); buttonRight=new Button();
@ -28,19 +28,19 @@
comboBox=new ComboBox(); comboBox=new ComboBox();
buttonStep=new Button(); buttonStep=new Button();
buttonSelect=new Button(); buttonSelect=new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxCatatamaran).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// pictureBoxCatatamaran // pictureBox
// //
pictureBoxCatatamaran.Dock=DockStyle.Fill; pictureBox.Dock=DockStyle.Fill;
pictureBoxCatatamaran.Location=new Point(0, 0); pictureBox.Location=new Point(0, 0);
pictureBoxCatatamaran.Margin=new Padding(4, 5, 4, 5); pictureBox.Margin=new Padding(4, 5, 4, 5);
pictureBoxCatatamaran.Name="pictureBoxCatatamaran"; pictureBox.Name="pictureBox";
pictureBoxCatatamaran.Size=new Size(1143, 750); pictureBox.Size=new Size(1143, 750);
pictureBoxCatatamaran.TabIndex=5; pictureBox.TabIndex=5;
pictureBoxCatatamaran.TabStop=false; pictureBox.TabStop=false;
pictureBoxCatatamaran.Click+=ButtonMove_Click; pictureBox.Click+=ButtonMove_Click;
// //
// buttonCreateBasic // buttonCreateBasic
// //
@ -160,19 +160,18 @@
Controls.Add(buttonDown); Controls.Add(buttonDown);
Controls.Add(buttonLeft); Controls.Add(buttonLeft);
Controls.Add(buttonCreateBasic); Controls.Add(buttonCreateBasic);
Controls.Add(pictureBoxCatatamaran); Controls.Add(pictureBox);
Margin=new Padding(4, 5, 4, 5); Margin=new Padding(4, 5, 4, 5);
Name="FormCatamaran"; Name="FormCatamaran";
Text="FormCatamaran"; Text="FormCatamaran";
((System.ComponentModel.ISupportInitialize)pictureBoxCatatamaran).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false); ResumeLayout(false);
} }
#endregion #endregion
private Button button1;
private Button UpBut; private Button UpBut;
private PictureBox pictureBoxCatatamaran; private PictureBox pictureBox;
private Button buttonCreateBasic; private Button buttonCreateBasic;
private Button buttonUp; private Button buttonUp;
private Button buttonRight; private Button buttonRight;

View File

@ -17,10 +17,10 @@ namespace Catamaran
{ {
return; return;
} }
Bitmap bmp = new(pictureBoxCatatamaran.Width, pictureBoxCatatamaran.Height); Bitmap bmp = new(pictureBox.Width, pictureBox.Height);
Graphics gr = Graphics.FromImage(bmp); Graphics gr = Graphics.FromImage(bmp);
_DrawningCatamaran.DrawTransport(gr); _DrawningCatamaran.DrawTransport(gr);
pictureBoxCatatamaran.Image = bmp; pictureBox.Image = bmp;
} }
private void ButtonMove_Click(object sender, EventArgs e) private void ButtonMove_Click(object sender, EventArgs e)
@ -59,7 +59,7 @@ namespace Catamaran
{ {
bodyColor = dialog.Color; bodyColor = dialog.Color;
} }
_DrawningCatamaran = new DrawningCatamaran(random.Next(10, 30), random.Next(100, 300), bodyColor, additionalColor, pictureBoxCatatamaran.Width, pictureBoxCatatamaran.Height, true); _DrawningCatamaran = new DrawningCatamaran(random.Next(10, 30), random.Next(100, 300), bodyColor, pictureBox.Width, pictureBox.Height);
_DrawningCatamaran.SetPosition(random.Next(10, 100), random.Next(10, 100)); _DrawningCatamaran.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw(); Draw();
@ -84,7 +84,7 @@ namespace Catamaran
} }
_DrawningCatamaran = new DrawningCatamaranPro(random.Next(100, 300), _DrawningCatamaran = new DrawningCatamaranPro(random.Next(100, 300),
random.Next(1000, 3000), bodyColor, otherColor, additionalColor, true, true, true, pictureBoxCatatamaran.Width, pictureBoxCatatamaran.Height, true); random.Next(1000, 3000), bodyColor, additionalColor, true, true, true, pictureBox.Width, pictureBox.Height);
_DrawningCatamaran.SetPosition(random.Next(10, 100), random.Next(10, 100)); _DrawningCatamaran.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw(); Draw();
@ -111,8 +111,8 @@ namespace Catamaran
return; return;
} }
_abstractStrategy.SetData(new _abstractStrategy.SetData(new
DrawningObjectCatamaran(_DrawningCatamaran), pictureBoxCatatamaran.Width, DrawningObjectCatamaran(_DrawningCatamaran), pictureBox.Width,
pictureBoxCatatamaran.Height); pictureBox.Height);
comboBox.Enabled = false; comboBox.Enabled = false;
} }
if (_abstractStrategy == null) if (_abstractStrategy == null)

View File

@ -86,19 +86,23 @@ namespace Catamaran
{ {
return; return;
} }
FormCatamaran form = new(); FormCatamaranConfig form = new();
if (form.ShowDialog() == DialogResult.OK) form.Show();
{ Action<DrawningCatamaran>? catamaranDelegate = new((c) => {
if (obj + form.SelectedCatamaran) bool q = (obj + c);
if (q)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
c.ChangePictureBoxSize(pictureBoxCollection.Width, pictureBoxCollection.Height);
pictureBoxCollection.Image = obj.ShowCats(); pictureBoxCollection.Image = obj.ShowCats();
} }
else else
{ {
MessageBox.Show("Не удалось добавить объект"); MessageBox.Show("Не удалось добавить объект");
} }
} });
form.AddEvent(catamaranDelegate);
} }
private void ButtonRemoveCatamaran_Click(object sender, EventArgs e) private void ButtonRemoveCatamaran_Click(object sender, EventArgs e)

356
Catamaran/FormCatamaranConfig.Designer.cs generated Normal file
View File

@ -0,0 +1,356 @@
namespace Catamaran
{
partial class FormCatamaranConfig
{
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()
{
groupBoxParam=new GroupBox();
ColorBox=new GroupBox();
panelOrange=new Panel();
panelBlue=new Panel();
panelGray=new Panel();
panelWhite=new Panel();
panelPurple=new Panel();
panelGreen=new Panel();
panelBlack=new Panel();
panelRed=new Panel();
labelHardObject=new Label();
labelSimpleObject=new Label();
checkBoSail=new CheckBox();
checkBoxMotor=new CheckBox();
checkBoxBodyKit=new CheckBox();
numericUpDownWeight=new NumericUpDown();
numericUpDownSpeed=new NumericUpDown();
LabelWeight=new Label();
LabelSpeed=new Label();
PanelObject=new Panel();
labelAdditionalColor=new Label();
labelColourMain=new Label();
pictureBoxObject=new PictureBox();
buttonAddObject=new Button();
buttonRepeal=new Button();
groupBoxParam.SuspendLayout();
ColorBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit();
PanelObject.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit();
SuspendLayout();
//
// groupBoxParam
//
groupBoxParam.Controls.Add(ColorBox);
groupBoxParam.Controls.Add(labelHardObject);
groupBoxParam.Controls.Add(labelSimpleObject);
groupBoxParam.Controls.Add(checkBoSail);
groupBoxParam.Controls.Add(checkBoxMotor);
groupBoxParam.Controls.Add(checkBoxBodyKit);
groupBoxParam.Controls.Add(numericUpDownWeight);
groupBoxParam.Controls.Add(numericUpDownSpeed);
groupBoxParam.Controls.Add(LabelWeight);
groupBoxParam.Controls.Add(LabelSpeed);
groupBoxParam.Location=new Point(12, 12);
groupBoxParam.Name="groupBoxParam";
groupBoxParam.Size=new Size(781, 384);
groupBoxParam.TabIndex=0;
groupBoxParam.TabStop=false;
groupBoxParam.Text="Параметры";
//
// ColorBox
//
ColorBox.Controls.Add(panelOrange);
ColorBox.Controls.Add(panelBlue);
ColorBox.Controls.Add(panelGray);
ColorBox.Controls.Add(panelWhite);
ColorBox.Controls.Add(panelPurple);
ColorBox.Controls.Add(panelGreen);
ColorBox.Controls.Add(panelBlack);
ColorBox.Controls.Add(panelRed);
ColorBox.Location=new Point(302, 30);
ColorBox.Name="ColorBox";
ColorBox.Size=new Size(415, 252);
ColorBox.TabIndex=10;
ColorBox.TabStop=false;
ColorBox.Text="Цвета";
//
// panelOrange
//
panelOrange.BackColor=Color.Orange;
panelOrange.Location=new Point(319, 143);
panelOrange.Name="panelOrange";
panelOrange.Size=new Size(60, 60);
panelOrange.TabIndex=2;
//
// panelBlue
//
panelBlue.BackColor=Color.Blue;
panelBlue.Location=new Point(217, 143);
panelBlue.Name="panelBlue";
panelBlue.Size=new Size(60, 60);
panelBlue.TabIndex=2;
//
// panelGray
//
panelGray.BackColor=Color.Gray;
panelGray.Location=new Point(113, 143);
panelGray.Name="panelGray";
panelGray.Size=new Size(60, 60);
panelGray.TabIndex=2;
//
// panelWhite
//
panelWhite.BackColor=Color.White;
panelWhite.Location=new Point(16, 143);
panelWhite.Name="panelWhite";
panelWhite.Size=new Size(60, 60);
panelWhite.TabIndex=2;
//
// panelPurple
//
panelPurple.BackColor=Color.Purple;
panelPurple.Location=new Point(319, 49);
panelPurple.Name="panelPurple";
panelPurple.Size=new Size(60, 60);
panelPurple.TabIndex=1;
//
// panelGreen
//
panelGreen.BackColor=Color.FromArgb(0, 192, 0);
panelGreen.Location=new Point(217, 49);
panelGreen.Name="panelGreen";
panelGreen.Size=new Size(60, 60);
panelGreen.TabIndex=1;
//
// panelBlack
//
panelBlack.BackColor=Color.Black;
panelBlack.Location=new Point(113, 49);
panelBlack.Name="panelBlack";
panelBlack.Size=new Size(60, 60);
panelBlack.TabIndex=1;
//
// panelRed
//
panelRed.BackColor=Color.Red;
panelRed.Location=new Point(16, 49);
panelRed.Name="panelRed";
panelRed.Size=new Size(60, 60);
panelRed.TabIndex=0;
//
// labelHardObject
//
labelHardObject.AllowDrop=true;
labelHardObject.BackColor=SystemColors.Control;
labelHardObject.BorderStyle=BorderStyle.FixedSingle;
labelHardObject.Location=new Point(567, 293);
labelHardObject.Name="labelHardObject";
labelHardObject.Size=new Size(150, 50);
labelHardObject.TabIndex=9;
labelHardObject.Text="Продвинутый";
labelHardObject.TextAlign=ContentAlignment.MiddleCenter;
//
// labelSimpleObject
//
labelSimpleObject.AllowDrop=true;
labelSimpleObject.BackColor=SystemColors.Control;
labelSimpleObject.BorderStyle=BorderStyle.FixedSingle;
labelSimpleObject.Location=new Point(302, 293);
labelSimpleObject.Name="labelSimpleObject";
labelSimpleObject.Size=new Size(150, 50);
labelSimpleObject.TabIndex=8;
labelSimpleObject.Text="Простой";
labelSimpleObject.TextAlign=ContentAlignment.MiddleCenter;
labelSimpleObject.MouseDown+=LabelObject_MouseDown;
//
// checkBoSail
//
checkBoSail.AutoSize=true;
checkBoSail.Location=new Point(22, 253);
checkBoSail.Name="checkBoSail";
checkBoSail.Size=new Size(241, 29);
checkBoSail.TabIndex=6;
checkBoSail.Text="Признак наличия паруса";
checkBoSail.UseVisualStyleBackColor=true;
//
// checkBoxMotor
//
checkBoxMotor.AutoSize=true;
checkBoxMotor.Location=new Point(22, 204);
checkBoxMotor.Name="checkBoxMotor";
checkBoxMotor.Size=new Size(247, 29);
checkBoxMotor.TabIndex=5;
checkBoxMotor.Text="Признак наличия мотора";
checkBoxMotor.UseVisualStyleBackColor=true;
//
// checkBoxBodyKit
//
checkBoxBodyKit.AutoSize=true;
checkBoxBodyKit.Location=new Point(22, 158);
checkBoxBodyKit.Name="checkBoxBodyKit";
checkBoxBodyKit.Size=new Size(274, 29);
checkBoxBodyKit.TabIndex=4;
checkBoxBodyKit.Text="Признак наличия поплавков";
checkBoxBodyKit.UseVisualStyleBackColor=true;
//
// numericUpDownWeight
//
numericUpDownWeight.Location=new Point(117, 93);
numericUpDownWeight.Name="numericUpDownWeight";
numericUpDownWeight.Size=new Size(87, 31);
numericUpDownWeight.TabIndex=3;
//
// numericUpDownSpeed
//
numericUpDownSpeed.Location=new Point(117, 50);
numericUpDownSpeed.Name="numericUpDownSpeed";
numericUpDownSpeed.Size=new Size(87, 31);
numericUpDownSpeed.TabIndex=2;
//
// LabelWeight
//
LabelWeight.AutoSize=true;
LabelWeight.Location=new Point(22, 95);
LabelWeight.Name="LabelWeight";
LabelWeight.Size=new Size(39, 25);
LabelWeight.TabIndex=1;
LabelWeight.Text="Вес";
//
// LabelSpeed
//
LabelSpeed.AutoSize=true;
LabelSpeed.Location=new Point(22, 50);
LabelSpeed.Name="LabelSpeed";
LabelSpeed.Size=new Size(89, 25);
LabelSpeed.TabIndex=0;
LabelSpeed.Text="Скорость";
//
// PanelObject
//
PanelObject.AllowDrop=true;
PanelObject.Controls.Add(labelAdditionalColor);
PanelObject.Controls.Add(labelColourMain);
PanelObject.Controls.Add(pictureBoxObject);
PanelObject.Location=new Point(799, 12);
PanelObject.Name="PanelObject";
PanelObject.Size=new Size(471, 310);
PanelObject.TabIndex=1;
PanelObject.DragDrop+=PanelObject_DragDrop;
PanelObject.DragEnter+=PanelObject_DragEnter;
//
// labelAdditionalColor
//
labelAdditionalColor.AllowDrop=true;
labelAdditionalColor.BorderStyle=BorderStyle.FixedSingle;
labelAdditionalColor.Location=new Point(257, 18);
labelAdditionalColor.Name="labelAdditionalColor";
labelAdditionalColor.Size=new Size(200, 50);
labelAdditionalColor.TabIndex=2;
labelAdditionalColor.Text="Дополнительный цвет";
labelAdditionalColor.TextAlign=ContentAlignment.MiddleCenter;
labelAdditionalColor.DragDrop+=ColorLabel_DragDrop;
labelAdditionalColor.DragEnter+=ColorLabel_DragEnter;
//
// labelColourMain
//
labelColourMain.AllowDrop=true;
labelColourMain.BorderStyle=BorderStyle.FixedSingle;
labelColourMain.Location=new Point(15, 18);
labelColourMain.Name="labelColourMain";
labelColourMain.Size=new Size(200, 50);
labelColourMain.TabIndex=1;
labelColourMain.Text="Основной цвет";
labelColourMain.TextAlign=ContentAlignment.MiddleCenter;
labelColourMain.DragDrop+=ColorLabel_DragDrop;
labelColourMain.DragEnter+=ColorLabel_DragEnter;
//
// pictureBoxObject
//
pictureBoxObject.Location=new Point(15, 79);
pictureBoxObject.Name="pictureBoxObject";
pictureBoxObject.Size=new Size(442, 212);
pictureBoxObject.TabIndex=0;
pictureBoxObject.TabStop=false;
//
// buttonAddObject
//
buttonAddObject.Location=new Point(814, 346);
buttonAddObject.Name="buttonAddObject";
buttonAddObject.Size=new Size(182, 50);
buttonAddObject.TabIndex=2;
buttonAddObject.Text="Добавить";
buttonAddObject.UseVisualStyleBackColor=true;
buttonAddObject.Click+=ButtonOk_Click;
//
// buttonRepeal
//
buttonRepeal.Location=new Point(1074, 346);
buttonRepeal.Name="buttonRepeal";
buttonRepeal.Size=new Size(182, 50);
buttonRepeal.TabIndex=3;
buttonRepeal.Text="Отмена";
buttonRepeal.UseVisualStyleBackColor=true;
//
// FormCatamaranConfig
//
AutoScaleDimensions=new SizeF(10F, 25F);
AutoScaleMode=AutoScaleMode.Font;
ClientSize=new Size(1281, 420);
Controls.Add(buttonRepeal);
Controls.Add(buttonAddObject);
Controls.Add(PanelObject);
Controls.Add(groupBoxParam);
Name="FormCatamaranConfig";
Text="FormCatamaranConfig";
groupBoxParam.ResumeLayout(false);
groupBoxParam.PerformLayout();
ColorBox.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit();
PanelObject.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox groupBoxParam;
private Label LabelSpeed;
private Label LabelWeight;
private CheckBox checkBoSail;
private CheckBox checkBoxMotor;
private CheckBox checkBoxBodyKit;
private NumericUpDown numericUpDownWeight;
private NumericUpDown numericUpDownSpeed;
private Label labelHardObject;
private Label labelSimpleObject;
private Panel PanelObject;
private Label labelColourMain;
private PictureBox pictureBoxObject;
private Label labelAdditionalColor;
private Button buttonAddObject;
private Button buttonRepeal;
private GroupBox ColorBox;
private Panel panelOrange;
private Panel panelBlue;
private Panel panelGray;
private Panel panelWhite;
private Panel panelPurple;
private Panel panelGreen;
private Panel panelBlack;
private Panel panelRed;
}
}

View File

@ -0,0 +1,138 @@
using System;
using System.Collections;
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 Catamaran
{
public partial class FormCatamaranConfig : Form
{
DrawningCatamaran? _catamaran = null;
private event Action<DrawningCatamaran>? EventAddCatamaran;
public void AddEvent(Action<DrawningCatamaran> ev)
{
if (EventAddCatamaran == null)
{
EventAddCatamaran = ev;
}
else
{
EventAddCatamaran += ev;
}
}
public FormCatamaranConfig()
{
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;
panelOrange.MouseDown += PanelColor_MouseDown;
panelBlue.MouseDown += PanelColor_MouseDown;
labelSimpleObject.MouseDown += LabelObject_MouseDown;
labelHardObject.MouseDown += LabelObject_MouseDown;
buttonRepeal.Click += (s, e) => Close();
}
private void DrawCatamaran()
{
Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height);
Graphics gr = Graphics.FromImage(bmp);
_catamaran?.SetPosition(5, 5);
_catamaran?.DrawTransport(gr);
pictureBoxObject.Image = bmp;
}
private void PanelColor_MouseDown(object sender, MouseEventArgs e)
{
(sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor,
DragDropEffects.Move | DragDropEffects.Copy);
}
private void PanelObject_DragDrop(object sender, DragEventArgs e)
{
switch (e.Data?.GetData(DataFormats.Text).ToString())
{
case "labelSimpleObject":
_catamaran = new DrawningCatamaran((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width,
pictureBoxObject.Height);
break;
case "labelHardObject":
_catamaran = new DrawningCatamaranPro((int)numericUpDownSpeed.Value,
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxBodyKit.Checked,
checkBoxMotor.Checked, checkBoSail.Checked, pictureBoxObject.Width,
pictureBoxObject.Height);
break;
}
DrawCatamaran();
}
private void PanelObject_DragEnter(object sender, DragEventArgs e)
{
if (e.Data?.GetDataPresent(DataFormats.Text) ?? false)
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void ButtonOk_Click(object sender, EventArgs e)
{
EventAddCatamaran?.Invoke(_catamaran);
Close();
}
private void LabelObject_MouseDown(object sender, MouseEventArgs e)
{
(sender as Label)?.DoDragDrop((sender as Label)?.Name,
DragDropEffects.Move | DragDropEffects.Copy);
}
private void ColorLabel_DragDrop(object sender, DragEventArgs e)
{
string senderName = ((Label)sender).Name;
if (_catamaran == null || e.Data.GetDataPresent(typeof(Color)) == false)
return;
Color droppedColor = (Color)e.Data.GetData(typeof(Color));
if (senderName == "labelColourMain")
{
labelColourMain.BackColor = droppedColor;
((DrawningCatamaran)_catamaran).ChangeColor(labelColourMain.BackColor);
}
else if (senderName == "labelAdditionalColor" && _catamaran is DrawningCatamaran)
{
labelAdditionalColor.BackColor = droppedColor;
((DrawningCatamaranPro)_catamaran).ChangeAddColor(labelAdditionalColor.BackColor);
}
DrawCatamaran();
}
private void ColorLabel_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Color)))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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>