зафиксировать
This commit is contained in:
parent
6295e00999
commit
ec76794b98
@ -1,113 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Boat_Hard
|
||||
{
|
||||
public class DrawningBoat
|
||||
{
|
||||
public EntityBoat? EntityBoat { get; private set; }
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
private int _startPosX;
|
||||
private int _startPosY;
|
||||
private readonly int _boatWidth = 160;
|
||||
private readonly int _boatHeight = 118;
|
||||
private DrawningOars drawningOars;
|
||||
|
||||
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool motor, int oars, int width, int height)
|
||||
{
|
||||
if (width < _boatWidth || height < _boatHeight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityBoat = new EntityBoat();
|
||||
EntityBoat.Init(speed, weight, bodyColor, additionalColor, motor, oars);
|
||||
|
||||
drawningOars = new DrawningOars();
|
||||
drawningOars.SetAmount(oars);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (x < 0 || x + _boatWidth > _pictureWidth)
|
||||
{
|
||||
x = _pictureWidth - _boatWidth;
|
||||
}
|
||||
|
||||
if (y < 0 || y + _boatWidth > _pictureHeight)
|
||||
{
|
||||
y = _pictureHeight - _boatHeight;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityBoat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
case DirectionType.Left:
|
||||
if (_startPosX - EntityBoat.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityBoat.Step;
|
||||
}
|
||||
break;
|
||||
case DirectionType.Up:
|
||||
if (_startPosY - EntityBoat.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityBoat.Step;
|
||||
}
|
||||
break;
|
||||
case DirectionType.Right:
|
||||
if (_startPosX + EntityBoat.Step + _boatWidth < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityBoat.Step;
|
||||
}
|
||||
break;
|
||||
case DirectionType.Down:
|
||||
if (_startPosY + EntityBoat.Step + _boatHeight < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityBoat.Step;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void DrawBoat(Graphics g)
|
||||
{
|
||||
if (EntityBoat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(EntityBoat.BodyColor);
|
||||
Brush mainBrush = new SolidBrush(EntityBoat.AdditionalColor);
|
||||
|
||||
drawningOars.DrawOars(g, _startPosX, _startPosY);
|
||||
|
||||
g.FillRectangle(mainBrush, _startPosX + 20, _startPosY + 20, 150, 90);
|
||||
g.DrawEllipse(pen, _startPosX + 30, _startPosY + 30, 130, 70);
|
||||
g.FillEllipse(additionalBrush, _startPosX + 30, _startPosY + 30, 130, 70);
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
||||
}
|
197
Boat_Hard/Boat_Hard/DrawningObjects/DrawningBoat.cs
Normal file
197
Boat_Hard/Boat_Hard/DrawningObjects/DrawningBoat.cs
Normal file
@ -0,0 +1,197 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Boat_Hard.Entities;
|
||||
|
||||
namespace Boat_Hard.DrawningObjects
|
||||
{
|
||||
public class DrawningBoat
|
||||
{
|
||||
public EntityBoat? EntityBoat { get; private set; }
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
private int _startPosX;
|
||||
private int _startPosY;
|
||||
private readonly int _boatWidth = 160;
|
||||
private readonly int _boatHeight = 118;
|
||||
public int GetPosX => _startPosX;
|
||||
public int GetPosY => _startPosY;
|
||||
public int GetWidth => _boatWidth;
|
||||
public int GetHeight => _boatHeight;
|
||||
private IDrawningOars drawningsOars;
|
||||
//private DrawningOars drawningOars;
|
||||
|
||||
//public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool motor, int oars, int width, int height)
|
||||
//{
|
||||
// if (width < _boatWidth || height < _boatHeight)
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
// _pictureWidth = width;
|
||||
// _pictureHeight = height;
|
||||
// EntityBoat = new EntityBoat();
|
||||
// EntityBoat.Init(speed, weight, bodyColor, additionalColor, motor, oars);
|
||||
|
||||
// drawningOars = new DrawningOars();
|
||||
// drawningOars.SetAmount(oars);
|
||||
|
||||
// return true;
|
||||
//}
|
||||
public DrawningBoat(int speed, float weight, Color bodyColor, int width, int height, int oarsNumbers, int oarsShape)
|
||||
{
|
||||
if (width < _boatWidth || height < _boatHeight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
EntityBoat = new EntityBoat(speed, weight, bodyColor);
|
||||
switch (oarsShape)
|
||||
{
|
||||
case 1:
|
||||
drawningsOars = new DrawningOarsOval();
|
||||
break;
|
||||
case 2:
|
||||
drawningsOars = new DrawningOarsTriangle();
|
||||
break;
|
||||
default:
|
||||
drawningsOars = new DrawningOarsRectangle();
|
||||
break;
|
||||
}
|
||||
drawningsOars.ChangeOarsNumber(oarsNumbers);
|
||||
}
|
||||
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (x < 0 || x + _boatWidth > _pictureWidth)
|
||||
{
|
||||
x = _pictureWidth - _boatWidth;
|
||||
}
|
||||
|
||||
if (y < 0 || y + _boatWidth > _pictureHeight)
|
||||
{
|
||||
y = _pictureHeight - _boatHeight;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
public bool CanMove(DirectionType direction)
|
||||
{
|
||||
if (EntityBoat == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return direction switch
|
||||
{
|
||||
//влево
|
||||
DirectionType.Left => _startPosX - EntityBoat.Step > 0,
|
||||
//вверх
|
||||
DirectionType.Up => _startPosY - EntityBoat.Step > 0,
|
||||
//вправо
|
||||
DirectionType.Right => _startPosX + _boatWidth + EntityBoat.Step < _pictureWidth,
|
||||
//вниз
|
||||
DirectionType.Down => _startPosY + _boatHeight + EntityBoat.Step < _pictureHeight,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
|
||||
public void MoveTransport(DirectionType direction)
|
||||
{
|
||||
//if (EntityBoat == null)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
//switch (direction)
|
||||
//{
|
||||
// case DirectionType.Left:
|
||||
// if (_startPosX - EntityBoat.Step > 0)
|
||||
// {
|
||||
// _startPosX -= (int)EntityBoat.Step;
|
||||
// }
|
||||
// break;
|
||||
// case DirectionType.Up:
|
||||
// if (_startPosY - EntityBoat.Step > 0)
|
||||
// {
|
||||
// _startPosY -= (int)EntityBoat.Step;
|
||||
// }
|
||||
// break;
|
||||
// case DirectionType.Right:
|
||||
// if (_startPosX + EntityBoat.Step + _boatWidth < _pictureWidth)
|
||||
// {
|
||||
// _startPosX += (int)EntityBoat.Step;
|
||||
// }
|
||||
// break;
|
||||
// case DirectionType.Down:
|
||||
// if (_startPosY + EntityBoat.Step + _boatHeight < _pictureHeight)
|
||||
// {
|
||||
// _startPosY += (int)EntityBoat.Step;
|
||||
// }
|
||||
// break;
|
||||
//}
|
||||
if (!CanMove(direction) || EntityBoat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
_startPosX -= (int)EntityBoat.Step;
|
||||
break;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
_startPosY -= (int)EntityBoat.Step;
|
||||
break;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
_startPosX += (int)EntityBoat.Step;
|
||||
break;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
_startPosY += (int)EntityBoat.Step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//public void DrawBoat(Graphics g)
|
||||
//{
|
||||
// if (EntityBoat == null)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// Pen pen = new(Color.Black);
|
||||
// Brush additionalBrush = new SolidBrush(EntityBoat.BodyColor);
|
||||
// Brush mainBrush = new SolidBrush(EntityBoat.AdditionalColor);
|
||||
|
||||
// drawningOars.DrawOars(g, _startPosX, _startPosY);
|
||||
|
||||
// g.FillRectangle(mainBrush, _startPosX + 20, _startPosY + 20, 150, 90);
|
||||
// g.DrawEllipse(pen, _startPosX + 30, _startPosY + 30, 130, 70);
|
||||
// g.FillEllipse(additionalBrush, _startPosX + 30, _startPosY + 30, 130, 70);
|
||||
|
||||
// #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);
|
||||
//}
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBoat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush mainBrush = new SolidBrush(EntityBoat.BodyColor);
|
||||
drawningsOars.DrawOarsNumber(g, _startPosX, _startPosY);
|
||||
}
|
||||
}
|
||||
}
|
39
Boat_Hard/Boat_Hard/DrawningObjects/DrawningMotorboat.cs
Normal file
39
Boat_Hard/Boat_Hard/DrawningObjects/DrawningMotorboat.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Boat_Hard.Entities;
|
||||
|
||||
namespace Boat_Hard.DrawningObjects
|
||||
{
|
||||
internal class DrawningMotorboat: DrawningBoat
|
||||
{
|
||||
public EntityMotorboat? EntityMotorboat { get; private set; }
|
||||
public DrawningMotorboat(int speed, float weight, Color bodyColor,
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBoat is not EntityMotorboat doubleDeckerBus)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush brAdditionalColor = new SolidBrush(doubleDeckerBus.AdditionalColor);
|
||||
Brush brBlue = new SolidBrush(Color.Blue);
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,26 +4,25 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Boat_Hard
|
||||
namespace Boat_Hard.Entities
|
||||
{
|
||||
public class EntityBoat
|
||||
{
|
||||
public int Speed { get; private set; }
|
||||
public double Weight { get; private set; }
|
||||
public Color BodyColor { get; private set; }
|
||||
public Color AdditionalColor { get; private set; }
|
||||
public bool isMotor { get; private set; }
|
||||
|
||||
public int Oars { 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 void Init(int speed, double weight, Color bodyColor
|
||||
//, Color additionalColor
|
||||
//, bool motor, int oars
|
||||
)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
isMotor = motor;
|
||||
Oars = oars;
|
||||
//AdditionalColor = additionalColor;
|
||||
//isMotor = motor;
|
||||
//Oars = oars;
|
||||
}
|
||||
}
|
||||
}
|
22
Boat_Hard/Boat_Hard/Entities/EntityMotorboat.cs
Normal file
22
Boat_Hard/Boat_Hard/Entities/EntityMotorboat.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Boat_Hard.Entities
|
||||
{
|
||||
public class EntityMotorboat: EntityBoat
|
||||
{
|
||||
public Color AdditionalColor { get; private set; }
|
||||
public bool isMotor { get; private set; }
|
||||
public int Oars { get; private set; }
|
||||
public EntityMotorboat(int speed, double weight, Color bodyColor, Color
|
||||
additionalColor, bool ismotor, int oars) : base (speed, weight, bodyColor)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
isMotor = ismotor;
|
||||
Oars = oars;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
using Boat_Hard.DrawningObjects;
|
||||
|
||||
namespace Boat_Hard
|
||||
{
|
||||
public partial class FormBoat : Form
|
||||
|
Loading…
Reference in New Issue
Block a user