pfabrcbhjdfnm

This commit is contained in:
Kristina 2023-12-25 02:09:56 +04:00
parent ec76794b98
commit 05ec3b8972
18 changed files with 2099 additions and 1720 deletions

View File

@ -1,88 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Boat_Hard
{
public class DrawningOars
{
private Oars amount;
public void SetAmount(int a)
{
if (a <= 1)
{
amount = Oars.One;
}
else if (a == 2)
{
amount = Oars.Two;
}
else if (a >= 3)
{
amount = Oars.Three;
}
}
public void DrawOars(Graphics g, int _startPosX, int _startPosY)
{
Brush oarsColor = new SolidBrush(Color.Black);
g.FillPolygon(oarsColor, new Point[] // up
{
new Point(_startPosX + 31, _startPosY - 10),
new Point(_startPosX + 41, _startPosY - 10),
new Point(_startPosX + 41, _startPosY + 90),
new Point(_startPosX + 31, _startPosY + 90),
}
);
g.FillPolygon(oarsColor, new Point[] // down
{
new Point(_startPosX + 31, _startPosY + 30),
new Point(_startPosX + 41, _startPosY + 30),
new Point(_startPosX + 41, _startPosY + 140),
new Point(_startPosX + 31, _startPosY + 140),
}
);
if (amount == Oars.Two || amount == Oars.Three)
{
g.FillPolygon(oarsColor, new Point[] // up
{
new Point(_startPosX + 61, _startPosY - 10),
new Point(_startPosX + 71, _startPosY - 10),
new Point(_startPosX + 71, _startPosY + 90),
new Point(_startPosX + 61, _startPosY + 90),
}
);
g.FillPolygon(oarsColor, new Point[] // down
{
new Point(_startPosX + 61, _startPosY + 30),
new Point(_startPosX + 71, _startPosY + 30),
new Point(_startPosX + 71, _startPosY + 140),
new Point(_startPosX + 61, _startPosY + 140),
}
);
}
if (amount == Oars.Three)
{
g.FillPolygon(oarsColor, new Point[] // up
{
new Point(_startPosX + 91, _startPosY - 10),
new Point(_startPosX + 101, _startPosY - 10),
new Point(_startPosX + 101, _startPosY + 90),
new Point(_startPosX + 91, _startPosY + 90),
}
);
g.FillPolygon(oarsColor, new Point[] // down
{
new Point(_startPosX + 91, _startPosY + 30),
new Point(_startPosX + 101, _startPosY + 30),
new Point(_startPosX + 101, _startPosY + 140),
new Point(_startPosX + 91, _startPosY + 140),
}
);
}
}
}
}

View File

@ -4,16 +4,18 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Boat_Hard.Entities;
using Boat_Hard.MovementStrategy;
namespace Boat_Hard.DrawningObjects
{
public class DrawningBoat
{
public EntityBoat? EntityBoat { get; private set; }
public IMoveableObject GetMoveableObject => new DrawningObjectBoat(this);
private int _pictureWidth;
private int _pictureHeight;
private int _startPosX;
private int _startPosY;
public int _startPosX;
public int _startPosY;
private readonly int _boatWidth = 160;
private readonly int _boatHeight = 118;
public int GetPosX => _startPosX;
@ -53,12 +55,12 @@ namespace Boat_Hard.DrawningObjects
case 1:
drawningsOars = new DrawningOarsOval();
break;
case 2:
drawningsOars = new DrawningOarsTriangle();
break;
default:
drawningsOars = new DrawningOarsRectangle();
break;
//case 2:
// drawningsOars = new DrawningOarsTriangle();
// break;
//default:
// drawningsOars = new DrawningOarsRectangle();
// break;
}
drawningsOars.ChangeOarsNumber(oarsNumbers);
}
@ -191,7 +193,20 @@ namespace Boat_Hard.DrawningObjects
Pen pen = new(Color.Black);
Brush mainBrush = new SolidBrush(EntityBoat.BodyColor);
drawningsOars.DrawOarsNumber(g, _startPosX, _startPosY);
g.FillRectangle(mainBrush, _startPosX + 20, _startPosY + 20, 150, 90);
#region Координаты переда лодки
Point b1 = new Point(_startPosX + 170, _startPosY + 20);
Point b2 = new Point(_startPosX + 200, _startPosY + 70);
Point b3 = new Point(_startPosX + 170, _startPosY + 110);
Point[] pointsBoat = { b1, b2, b3 };
#endregion
g.DrawPolygon(pen, pointsBoat);
g.FillPolygon(mainBrush, pointsBoat);
}
}
}

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Boat_Hard.Entities;
using Boat_Hard.MovementStrategy;
namespace Boat_Hard.DrawningObjects
{
@ -14,25 +15,41 @@ namespace Boat_Hard.DrawningObjects
Color additionalColor, bool ismotor, int oarsNumbers, int oars, int width, int height, int oarsShape) :
base(speed, weight, bodyColor, width, height, oarsNumbers, oarsShape)
{
if (EntityBoat != null)
{
EntityBoat = new EntityMotorboat(speed, weight, bodyColor,
additionalColor, ismotor, oarsNumbers, oars);
}
//if (EntityBoat != null)
//{
// EntityBoat = new EntityMotorboat(speed, weight, bodyColor,
// additionalColor, ismotor, oars, oarsNumbers);
//}
}
public override void DrawTransport(Graphics g)
{
if (EntityBoat is not EntityMotorboat doubleDeckerBus)
if (EntityBoat is not EntityMotorboat motorboat)
{
return;
}
Pen pen = new(Color.Black);
Brush brAdditionalColor = new SolidBrush(doubleDeckerBus.AdditionalColor);
Brush brBlue = new SolidBrush(Color.Blue);
Brush brBlack = new SolidBrush(Color.Black);
Brush brAdditionalColor = new SolidBrush(motorboat.AdditionalColor);
Brush oarsColor = new SolidBrush(Color.Black);
g.FillPolygon(oarsColor, new Point[] // up
{
new Point(_startPosX + 31, _startPosY - 10),
new Point(_startPosX + 41, _startPosY - 10),
new Point(_startPosX + 41, _startPosY + 90),
new Point(_startPosX + 31, _startPosY + 90),
}
);
g.FillPolygon(oarsColor, new Point[] // down
{
new Point(_startPosX + 31, _startPosY + 30),
new Point(_startPosX + 41, _startPosY + 30),
new Point(_startPosX + 41, _startPosY + 140),
new Point(_startPosX + 31, _startPosY + 140),
}
);
base.DrawTransport(g);
}
}
}

View File

@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Boat_Hard.DrawningObjects
{
internal class DrawningOarsOval: IDrawningOars
{
public OarsNumbers _oarsNumbers;
public void ChangeOarsNumber(int x)
{
if (x <= 3)
{
_oarsNumbers = OarsNumbers.One;
}
if (x == 4)
{
_oarsNumbers = OarsNumbers.Two;
}
if (x >= 5)
{
_oarsNumbers = OarsNumbers.Three;
}
}
public void DrawOarsNumber(Graphics g, int _startPosX, int _startPosY)
{
Pen pen = new(Color.White);
Brush brBlue = new SolidBrush(Color.Black);
g.FillEllipse(brBlue, _startPosX + 20, _startPosY + 21, 10, 20);
g.FillEllipse(brBlue, _startPosX + 31, _startPosY + 21, 10, 20);
g.FillEllipse(brBlue, _startPosX + 60, _startPosY + 21, 10, 20);
if (_oarsNumbers == OarsNumbers.Two || _oarsNumbers == OarsNumbers.Three)
{
g.FillEllipse(brBlue, _startPosX + 80, _startPosY + 21, 10, 20);
}
if (_oarsNumbers == OarsNumbers.Three)
{
g.FillEllipse(brBlue, _startPosX + 42, _startPosY + 21, 10, 20);
}
}
}
}

View File

@ -12,17 +12,11 @@ namespace Boat_Hard.Entities
public double Weight { get; private set; }
public Color BodyColor { get; private set; }
public double Step => (double)Speed * 100 / Weight;
public void Init(int speed, double weight, Color bodyColor
//, Color additionalColor
//, bool motor, int oars
)
public EntityBoat(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
//AdditionalColor = additionalColor;
//isMotor = motor;
//Oars = oars;
}
}
}

View File

@ -11,12 +11,14 @@ namespace Boat_Hard.Entities
public Color AdditionalColor { get; private set; }
public bool isMotor { get; private set; }
public int Oars { get; private set; }
public int OarsNumbers { get; private set; }
public EntityMotorboat(int speed, double weight, Color bodyColor, Color
additionalColor, bool ismotor, int oars) : base (speed, weight, bodyColor)
additionalColor, bool ismotor, int oars, int oarsNumbers) : base (speed, weight, bodyColor)
{
AdditionalColor = additionalColor;
isMotor = ismotor;
Oars = oars;
OarsNumbers = oarsNumbers;
}
}
}

View File

@ -35,6 +35,9 @@
buttonRight = new Button();
buttonLeft = new Button();
pictureBoxBoat = new PictureBox();
buttonMotorboatCreate = new Button();
comboBoxStrategy = new ComboBox();
//buttonStep_Click = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxBoat).BeginInit();
SuspendLayout();
//
@ -102,11 +105,44 @@
pictureBoxBoat.TabIndex = 5;
pictureBoxBoat.TabStop = false;
//
// buttonMotorboatCreate
//
buttonMotorboatCreate.Location = new Point(141, 573);
buttonMotorboatCreate.Name = "buttonMotorboatCreate";
buttonMotorboatCreate.Size = new Size(196, 34);
buttonMotorboatCreate.TabIndex = 6;
buttonMotorboatCreate.Text = "Создать моторную";
buttonMotorboatCreate.UseVisualStyleBackColor = true;
buttonMotorboatCreate.Click += buttonMotorboatCreate_Click;
//
// comboBoxStrategy
//
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToBorder" });
comboBoxStrategy.Location = new Point(853, 0);
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(182, 33);
comboBoxStrategy.TabIndex = 7;
comboBoxStrategy.SelectedIndexChanged += comboBoxStrategy_SelectedIndexChanged;
//
// buttonStep_Click
//
buttonStep_Click.Location = new Point(936, 39);
buttonStep_Click.Name = "buttonStep_Click";
buttonStep_Click.Size = new Size(56, 34);
buttonStep_Click.TabIndex = 8;
buttonStep_Click.Text = "шаг";
buttonStep_Click.UseVisualStyleBackColor = true;
buttonStep_Click.Click += this.buttonStep_Click_Click;
//
// FormBoat
//
AutoScaleDimensions = new SizeF(10F, 25F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1035, 619);
Controls.Add(buttonStep_Click);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonMotorboatCreate);
Controls.Add(buttonLeft);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
@ -128,5 +164,9 @@
private Button buttonRight;
private Button buttonLeft;
private PictureBox pictureBoxBoat;
private Button buttonMotorboatCreate;
private ComboBox comboBoxStrategy;
private Button buttonStep_Click;
private Button buttonStep_Click;
}
}

View File

@ -1,10 +1,13 @@
using Boat_Hard.DrawningObjects;
using Boat_Hard.MovementStrategy;
namespace Boat_Hard
{
public partial class FormBoat : Form
{
private DrawningBoat? _drawningBoat;
private AbstractStrategy? _strategy;
public DrawningBoat? SelectedBoat { get; private set; }
public FormBoat()
{
InitializeComponent();
@ -18,18 +21,15 @@ namespace Boat_Hard
}
Bitmap bmp = new(pictureBoxBoat.Width, pictureBoxBoat.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningBoat.DrawBoat(gr);
_drawningBoat.DrawTransport(gr);
pictureBoxBoat.Image = bmp;
}
private void buttonCreate_Click(object sender, EventArgs e)
{
Random random = new();
_drawningBoat = new DrawningBoat();
_drawningBoat.Init(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))
,random.Next(1, 4) * 2, pictureBoxBoat.Width, pictureBoxBoat.Height);
_drawningBoat = new DrawningBoat(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
pictureBoxBoat.Width, pictureBoxBoat.Height, random.Next(2, 6), random.Next(0, 4));
_drawningBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
@ -59,5 +59,64 @@ namespace Boat_Hard
}
Draw();
}
private void buttonMotorboatCreate_Click(object sender, EventArgs e)
{
Random random = new();
_drawningBoat = new DrawningMotorboat(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)),
random.Next(0, 4),
//random.Next(2, 6),
//Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
pictureBoxBoat.Width, pictureBoxBoat.Height, random.Next(0, 4), random.Next(0, 4));
_drawningBoat.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void comboBoxStrategy_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void buttonStep_Click(object sender, EventArgs e)
{
if (_drawningBoat == null)
{
return;
}
if (comboBoxStrategy.Enabled)
{
_strategy = comboBoxStrategy.SelectedIndex switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
if (_strategy == null)
{
return;
}
_strategy.SetData(_drawningBoat.GetMoveableObject,
pictureBoxBoat.Width, pictureBoxBoat.Height);
}
if (_strategy == null)
{
return;
}
comboBoxStrategy.Enabled = false;
_strategy.MakeStep();
Draw();
if (_strategy.GetStatus() == Status.Finish)
{
comboBoxStrategy.Enabled = true;
_strategy = null;
}
}
private void buttonStep_Click_Click(object sender, EventArgs e)
{
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Boat_Hard
{
internal interface IDrawningOars
{
public void ChangeOarsNumber(int x);
public void DrawOarsNumber(Graphics g, int _startPosX, int _startPosY);
}
}

View File

@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace Boat_Hard.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,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Boat_Hard.DrawningObjects;
namespace Boat_Hard.MovementStrategy
{
public class DrawningObjectBoat: IMoveableObject
{
private readonly DrawningBoat? _drawningBoat = null;
public DrawningObjectBoat(DrawningBoat drawningBus)
{
_drawningBoat = drawningBus;
}
public ObjectParameters? GetObjectPosition
{
get
{
if (_drawningBoat == null || _drawningBoat.EntityBoat == null)
{
return null;
}
return new ObjectParameters(_drawningBoat.GetPosX,
_drawningBoat.GetPosY, _drawningBoat.GetWidth, _drawningBoat.GetHeight);
}
}
public int GetStep => (int)(_drawningBoat?.EntityBoat?.Step ?? 0);
public bool CheckCanMove(DirectionType direction) =>
_drawningBoat?.CanMove(direction) ?? false;
public void MoveObject(DirectionType direction) =>
_drawningBoat?.MoveTransport(direction);
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Boat_Hard.MovementStrategy
{
public interface IMoveableObject
{
ObjectParameters? GetObjectPosition { get; }
int GetStep { get; }
bool CheckCanMove(DirectionType direction);
void MoveObject(DirectionType direction);
}
}

View File

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Boat_Hard.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())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
var diffY = objParams.DownBorder - FieldHeight;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}
}

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Boat_Hard.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;
if (Math.Abs(diffX) > GetStep())
{
if (diffX > 0)
{
MoveLeft();
}
else
{
MoveRight();
}
}
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
if (Math.Abs(diffY) > GetStep())
{
if (diffY > 0)
{
MoveUp();
}
else
{
MoveDown();
}
}
}
}
}

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Boat_Hard.MovementStrategy
{
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

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

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Boat_Hard
{
public enum Oars
public enum OarsNumbers
{
One,
Two,