Коммит

This commit is contained in:
devil_1nc 2022-10-01 18:31:52 +04:00
parent 9805789853
commit d3e23a1905
10 changed files with 140 additions and 83 deletions

View File

@ -18,6 +18,35 @@ namespace ProjectPlane
protected readonly int _freeRoad = 0; protected readonly int _freeRoad = 0;
protected readonly int _barrier = 1; protected readonly int _barrier = 1;
public bool IsMoveable(float x, float y)
{
var getPos = _drawingObject.GetCurrentPosition();
int Right = Convert.ToInt32((getPos.Right + x) / _size_x) > 0
? Convert.ToInt32((getPos.Right + x) / _size_x) : 0;
int Left = Convert.ToInt32((getPos.Left + x) / _size_x) > 0
? Convert.ToInt32((getPos.Left + x) / _size_x) : 0;
int Top = Convert.ToInt32((getPos.Top + y) / _size_y) > 0
? Convert.ToInt32((getPos.Top + y) / _size_y) : 0;
int Bottom = Convert.ToInt32((getPos.Bottom + y) / _size_y) > 0
? Convert.ToInt32((getPos.Bottom + y) / _size_y) : 0;
for (int i = Left; i <= Right; i++)
{
for (int j = Top; j <= Bottom; j++)
{
if (_map[i, j] == _barrier) return false;
}
}
return true;
}
public Bitmap CreateMap(int width, int height, IDrawingObject drawingObject) public Bitmap CreateMap(int width, int height, IDrawingObject drawingObject)
{ {
_width = width; _width = width;
@ -32,8 +61,24 @@ namespace ProjectPlane
} }
public Bitmap MoveObject(Direction direction) public Bitmap MoveObject(Direction direction)
{ {
// TODO проверка, что объект может переместится в требуемом направлении bool isMoveable = false;
if (true) switch (direction)
{
case Direction.Right:
isMoveable = IsMoveable(_drawingObject.Step, 0);
break;
case Direction.Left:
isMoveable = IsMoveable(-_drawingObject.Step, 0);
break;
case Direction.Up:
isMoveable = IsMoveable(0, -_drawingObject.Step);
break;
case Direction.Down:
isMoveable = IsMoveable(0, _drawingObject.Step);
break;
}
if (isMoveable)
{ {
_drawingObject.MoveObject(direction); _drawingObject.MoveObject(direction);
} }
@ -48,7 +93,19 @@ namespace ProjectPlane
int x = _random.Next(0, 10); int x = _random.Next(0, 10);
int y = _random.Next(0, 10); int y = _random.Next(0, 10);
_drawingObject.SetObject(x, y, _width, _height); _drawingObject.SetObject(x, y, _width, _height);
// TODO првоерка, что объект не "накладывается" на закрытые участки
while (!IsMoveable(0, 0))
{
x += 5;
if (x < _width)
{
x = 0;
y += 5;
}
_drawingObject.SetObject(x, y, _width, _height);
}
return true; return true;
} }
private Bitmap DrawMapWithObject() private Bitmap DrawMapWithObject()

View File

@ -8,6 +8,7 @@ namespace ProjectPlane
{ {
internal enum Direction internal enum Direction
{ {
None = 0,
Up = 1, Up = 1,
Down = 2, Down = 2,
Left = 3, Left = 3,

View File

@ -34,7 +34,7 @@ namespace ProjectPlane
void IDrawingObject.DrawingObject(Graphics g) void IDrawingObject.DrawingObject(Graphics g)
{ {
// TODO _plane.DrawTransport(g);
} }
} }
} }

View File

@ -38,14 +38,6 @@ namespace ProjectPlane
/// </summary> /// </summary>
private readonly int _planeHeight = 50; private readonly int _planeHeight = 50;
/// <summary> /// <summary>
/// Левый край
/// </summary>
private readonly int _minX = 5;
/// <summary>
/// Верхний край
/// </summary>
private readonly int _minY = 40;
/// <summary>
/// Инициализация свойств /// Инициализация свойств
/// </summary> /// </summary>
/// <param name="speed">Скорость</param> /// <param name="speed">Скорость</param>
@ -80,14 +72,18 @@ namespace ProjectPlane
public void SetPosition(int x, int y, int width, int height) public void SetPosition(int x, int y, int width, int height)
{ {
if (x >= _minX && x <= width && y >= _minY && y <= height) if (x < 0 || x + _planeWidth >= width)
{ {
_startPosX = x; return;
_startPosY = y;
_pictureWidth = width;
_pictureHeight = height;
} }
else SetPosition(_minX, _minY, width, height); if (y < 0 || y + _planeHeight >= height)
{
return;
}
_startPosX = x;
_startPosY = y;
_pictureWidth = width;
_pictureHeight = height;
} }
/// <summary> /// <summary>
/// Изменение направления пермещения /// Изменение направления пермещения
@ -117,12 +113,11 @@ namespace ProjectPlane
break; break;
//вверх //вверх
case Direction.Up: case Direction.Up:
if (_startPosY - Plane.Step > 35) if (_startPosY - Plane.Step > 0)
{ {
_startPosY -= Plane.Step; _startPosY -= Plane.Step;
} }
break; break;
break;
//вниз //вниз
case Direction.Down: case Direction.Down:
if (_startPosY + _planeHeight + Plane.Step < _pictureHeight) if (_startPosY + _planeHeight + Plane.Step < _pictureHeight)
@ -146,74 +141,72 @@ namespace ProjectPlane
//границы самолета //границы самолета
Pen pen = new(Color.Black); Pen pen = new(Color.Black);
g.DrawEllipse(pen, _startPosX, _startPosY, 20, 20); g.DrawEllipse(pen, _startPosX, _startPosY + 20, 20, 20);
g.DrawRectangle(pen, _startPosX + 8, _startPosY, 100, 20); g.DrawRectangle(pen, _startPosX + 8, _startPosY + 20, 100, 20);
Point[] Triangle0 = new Point[3]; Point[] Triangle0 = new Point[3];
Triangle0[0].X = Convert.ToInt32(_startPosX + 108); Triangle0[0].Y = Convert.ToInt32(_startPosY - 2); Triangle0[0].X = Convert.ToInt32(_startPosX + 108); Triangle0[0].Y = Convert.ToInt32(_startPosY + 18);
Triangle0[1].X = Convert.ToInt32(_startPosX + 125); Triangle0[1].Y = Convert.ToInt32(_startPosY + 10); Triangle0[1].X = Convert.ToInt32(_startPosX + 125); Triangle0[1].Y = Convert.ToInt32(_startPosY + 30);
Triangle0[2].X = Convert.ToInt32(_startPosX + 108); Triangle0[2].Y = Convert.ToInt32(_startPosY + 10); Triangle0[2].X = Convert.ToInt32(_startPosX + 108); Triangle0[2].Y = Convert.ToInt32(_startPosY + 30);
g.DrawPolygon(pen, Triangle0); g.DrawPolygon(pen, Triangle0);
Point[] Triangle1 = new Point[3]; Point[] Triangle1 = new Point[3];
Triangle1[0].X = Convert.ToInt32(_startPosX + 108); Triangle1[0].Y = Convert.ToInt32(_startPosY + 10); Triangle1[0].X = Convert.ToInt32(_startPosX + 108); Triangle1[0].Y = Convert.ToInt32(_startPosY + 30);
Triangle1[1].X = Convert.ToInt32(_startPosX + 125); Triangle1[1].Y = Convert.ToInt32(_startPosY + 10); Triangle1[1].X = Convert.ToInt32(_startPosX + 125); Triangle1[1].Y = Convert.ToInt32(_startPosY + 30);
Triangle1[2].X = Convert.ToInt32(_startPosX + 108); Triangle1[2].Y = Convert.ToInt32(_startPosY + 22); Triangle1[2].X = Convert.ToInt32(_startPosX + 108); Triangle1[2].Y = Convert.ToInt32(_startPosY + 42);
g.DrawPolygon(pen, Triangle1); g.DrawPolygon(pen, Triangle1);
Point[] Triangle = new Point[3]; Point[] Triangle = new Point[3];
Triangle[0].X = Convert.ToInt32(_startPosX + 5); Triangle[0].Y = Convert.ToInt32(_startPosY); Triangle[0].X = Convert.ToInt32(_startPosX + 5); Triangle[0].Y = Convert.ToInt32(_startPosY + 20);
Triangle[1].X = Convert.ToInt32(_startPosX + 5); Triangle[1].Y = Convert.ToInt32(_startPosY - 20); Triangle[1].X = Convert.ToInt32(_startPosX + 5); Triangle[1].Y = Convert.ToInt32(_startPosY);
Triangle[2].X = Convert.ToInt32(_startPosX + 35); Triangle[2].Y = Convert.ToInt32(_startPosY); Triangle[2].X = Convert.ToInt32(_startPosX + 35); Triangle[2].Y = Convert.ToInt32(_startPosY + 20);
g.DrawPolygon(pen, Triangle); g.DrawPolygon(pen, Triangle);
////корпус ////корпус
Brush br = new SolidBrush(Plane?.BodyColor ?? Color.Black); Brush br = new SolidBrush(Plane?.BodyColor ?? Color.Black);
g.FillEllipse(br, _startPosX, _startPosY, 20, 20); g.FillEllipse(br, _startPosX, _startPosY + 20, 20, 20);
g.FillRectangle(br, _startPosX + 8, _startPosY, 100, 20); g.FillRectangle(br, _startPosX + 8, _startPosY + 20, 100, 20);
Point[] Triangle2 = new Point[3]; Point[] Triangle2 = new Point[3];
Triangle2[0].X = Convert.ToInt32(_startPosX + 5); Triangle2[0].Y = Convert.ToInt32(_startPosY); Triangle2[0].X = Convert.ToInt32(_startPosX + 5); Triangle2[0].Y = Convert.ToInt32(_startPosY + 20);
Triangle2[1].X = Convert.ToInt32(_startPosX + 5); Triangle2[1].Y = Convert.ToInt32(_startPosY - 20); Triangle2[1].X = Convert.ToInt32(_startPosX + 5); Triangle2[1].Y = Convert.ToInt32(_startPosY); //the highest point
Triangle2[2].X = Convert.ToInt32(_startPosX + 35); Triangle2[2].Y = Convert.ToInt32(_startPosY); Triangle2[2].X = Convert.ToInt32(_startPosX + 35); Triangle2[2].Y = Convert.ToInt32(_startPosY + 20);
g.FillPolygon(br, Triangle2); g.FillPolygon(br, Triangle2);
Point[] Triangle4 = new Point[3]; Point[] Triangle4 = new Point[3];
Triangle4[0].X = Convert.ToInt32(_startPosX + 108); Triangle4[0].Y = Convert.ToInt32(_startPosY + 10); Triangle4[0].X = Convert.ToInt32(_startPosX + 108); Triangle4[0].Y = Convert.ToInt32(_startPosY + 30);
Triangle4[1].X = Convert.ToInt32(_startPosX + 125); Triangle4[1].Y = Convert.ToInt32(_startPosY + 10); Triangle4[1].X = Convert.ToInt32(_startPosX + 125); Triangle4[1].Y = Convert.ToInt32(_startPosY + 30);
Triangle4[2].X = Convert.ToInt32(_startPosX + 108); Triangle4[2].Y = Convert.ToInt32(_startPosY + 22); Triangle4[2].X = Convert.ToInt32(_startPosX + 108); Triangle4[2].Y = Convert.ToInt32(_startPosY + 42);
g.FillPolygon(br, Triangle4); g.FillPolygon(br, Triangle4);
// window // window
Brush brBlue = new SolidBrush(Color.LightBlue); Brush brBlue = new SolidBrush(Color.LightBlue);
Brush brBlack = new SolidBrush(Color.Black); Brush brBlack = new SolidBrush(Color.Black);
Point[] Triangle3 = new Point[3]; Point[] Triangle3 = new Point[3];
Triangle3[0].X = Convert.ToInt32(_startPosX + 108); Triangle3[0].Y = Convert.ToInt32(_startPosY - 2); Triangle3[0].X = Convert.ToInt32(_startPosX + 108); Triangle3[0].Y = Convert.ToInt32(_startPosY + 18);
Triangle3[1].X = Convert.ToInt32(_startPosX + 125); Triangle3[1].Y = Convert.ToInt32(_startPosY + 10); Triangle3[1].X = Convert.ToInt32(_startPosX + 125); Triangle3[1].Y = Convert.ToInt32(_startPosY + 30);
Triangle3[2].X = Convert.ToInt32(_startPosX + 108); Triangle3[2].Y = Convert.ToInt32(_startPosY + 10); Triangle3[2].X = Convert.ToInt32(_startPosX + 108); Triangle3[2].Y = Convert.ToInt32(_startPosY + 30);
g.FillPolygon(brBlue, Triangle3); g.FillPolygon(brBlue, Triangle3);
g.DrawLine(pen, _startPosX + 37, _startPosY + 20, _startPosX + 37, _startPosY + 25); g.DrawLine(pen, _startPosX + 37, _startPosY + 40, _startPosX + 37, _startPosY + 45);
g.DrawLine(pen, _startPosX + 32, _startPosY + 25, _startPosX + 40, _startPosY + 25); g.DrawLine(pen, _startPosX + 32, _startPosY + 45, _startPosX + 40, _startPosY + 45);
g.FillRectangle(brBlack, _startPosX + 32, _startPosY + 25, 3, 3); g.FillRectangle(brBlack, _startPosX + 32, _startPosY + 45, 3, 3);
g.FillRectangle(brBlack, _startPosX + 39, _startPosY + 25, 3, 3); g.FillRectangle(brBlack, _startPosX + 39, _startPosY + 45, 3, 3);
g.DrawLine(pen, _startPosX + 102, _startPosY + 20, _startPosX + 102, _startPosY + 25); g.DrawLine(pen, _startPosX + 102, _startPosY + 40, _startPosX + 102, _startPosY + 45);
g.FillRectangle(brBlack, _startPosX + 101, _startPosY + 25, 3, 3); g.FillRectangle(brBlack, _startPosX + 101, _startPosY + 45, 3, 3);
g.FillRectangle(brBlack, _startPosX + 5, _startPosY - 2, 18, 7); g.FillRectangle(brBlack, _startPosX + 5, _startPosY + 18, 18, 7);
g.FillEllipse(brBlack, _startPosX, _startPosY - 2, 7, 7); g.FillEllipse(brBlack, _startPosX, _startPosY + 18, 7, 7);
g.FillEllipse(brBlack, _startPosX + 20, _startPosY - 2, 7, 7); g.FillEllipse(brBlack, _startPosX + 20, _startPosY + 18, 7, 7);
g.FillRectangle(brBlack, _startPosX + 41, _startPosY + 8, 42, 4); g.FillRectangle(brBlack, _startPosX + 41, _startPosY + 28, 42, 4);
g.FillEllipse(brBlack, _startPosX + 39, _startPosY + 8, 4, 4); g.FillEllipse(brBlack, _startPosX + 39, _startPosY + 28, 4, 4);
g.FillEllipse(brBlack, _startPosX + 81, _startPosY + 8, 4, 4); g.FillEllipse(brBlack, _startPosX + 81, _startPosY + 28, 4, 4);
} }
/// <summary> /// <summary>
/// Смена границ формы отрисовки /// Смена границ формы отрисовки

View File

@ -41,9 +41,9 @@ namespace ProjectPlane
if (warplane.SuperTurbine) if (warplane.SuperTurbine)
{ {
g.FillRectangle(Brush, _startPosX, _startPosY, 30, 22); g.FillRectangle(dopBrush, _startPosX, _startPosY + 20, 30, 22);
g.DrawLine(pen, _startPosX, _startPosY + 22, _startPosX + 30, _startPosY + 22); g.DrawLine(pen, _startPosX, _startPosY + 42, _startPosX + 30, _startPosY + 42);
g.DrawLine(pen, _startPosX, _startPosY, _startPosX + 30, _startPosY); g.DrawLine(pen, _startPosX, _startPosY + 20, _startPosX + 30, _startPosY + 20);
} }
_startPosX += 10; _startPosX += 10;
@ -54,8 +54,8 @@ namespace ProjectPlane
if (warplane.IsBomber) if (warplane.IsBomber)
{ {
g.FillEllipse(brBlack, _startPosX + 88, _startPosY, 4, 4); g.FillEllipse(brBlack, _startPosX + 88, _startPosY + 20, 4, 4);
g.FillRectangle(Brush, _startPosX + 60, _startPosY, 30, 12); g.FillRectangle(Brush, _startPosX + 60, _startPosY + 20, 30, 12);
} }
@ -64,16 +64,16 @@ namespace ProjectPlane
if (warplane.IsFighter) if (warplane.IsFighter)
{ {
Point[] Nose = new Point[4]; Point[] Nose = new Point[4];
Nose[0].X = Convert.ToInt32(_startPosX + 118); Nose[0].Y = Convert.ToInt32(_startPosY + 2); Nose[0].X = Convert.ToInt32(_startPosX + 118); Nose[0].Y = Convert.ToInt32(_startPosY + 22);
Nose[1].X = Convert.ToInt32(_startPosX + 155); Nose[1].Y = Convert.ToInt32(_startPosY + 2); Nose[1].X = Convert.ToInt32(_startPosX + 155); Nose[1].Y = Convert.ToInt32(_startPosY + 22);
Nose[2].X = Convert.ToInt32(_startPosX + 118); Nose[2].Y = Convert.ToInt32(_startPosY + 25); Nose[2].X = Convert.ToInt32(_startPosX + 118); Nose[2].Y = Convert.ToInt32(_startPosY + 45);
Nose[3].X = Convert.ToInt32(_startPosX + 98); Nose[3].Y = Convert.ToInt32(_startPosY + 25); Nose[3].X = Convert.ToInt32(_startPosX + 98); Nose[3].Y = Convert.ToInt32(_startPosY + 45);
g.FillPolygon(Brush, Nose); g.FillPolygon(Brush, Nose);
Point[] NoseWin = new Point[3]; Point[] NoseWin = new Point[3];
NoseWin[0].X = Convert.ToInt32(_startPosX + 120); NoseWin[0].Y = Convert.ToInt32(_startPosY + 4); NoseWin[0].X = Convert.ToInt32(_startPosX + 120); NoseWin[0].Y = Convert.ToInt32(_startPosY + 24);
NoseWin[1].X = Convert.ToInt32(_startPosX + 148); NoseWin[1].Y = Convert.ToInt32(_startPosY + 4); NoseWin[1].X = Convert.ToInt32(_startPosX + 148); NoseWin[1].Y = Convert.ToInt32(_startPosY + 24);
NoseWin[2].X = Convert.ToInt32(_startPosX + 132); NoseWin[2].Y = Convert.ToInt32(_startPosY + 14); NoseWin[2].X = Convert.ToInt32(_startPosX + 132); NoseWin[2].Y = Convert.ToInt32(_startPosY + 34);
g.FillPolygon(brBlue, NoseWin); g.FillPolygon(brBlue, NoseWin);
} }

View File

@ -20,6 +20,10 @@
base.Dispose(disposing); base.Dispose(disposing);
} }
private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
}
#region Windows Form Designer generated code #region Windows Form Designer generated code
/// <summary> /// <summary>

View File

@ -16,13 +16,14 @@ namespace ProjectPlane
public FormMap() public FormMap()
{ {
InitializeComponent(); InitializeComponent();
_abstractMap = new SimpleMap();
} }
/// <param name="plane"></param>
private void SetData() private void SetData(DrawingPlane plane)
{ {
toolStripStatusLabelSpeed.Text = $"Скорость: {plane.Plane.Speed}"; toolStripStatusLabelSpeed.Text = $"Speed: {plane.Plane.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {plane.Plane.Weight}"; toolStripStatusLabelWeight.Text = $"Weight: {plane.Plane.Weight}";
toolStripStatusLabelBodyColor.Text = $"Цвет: {plane.Plane.BodyColor.Name}"; toolStripStatusLabelBodyColor.Text = $"Color: {plane.Plane.BodyColor.Name}";
pictureBoxPlane.Image = _abstractMap.CreateMap(pictureBoxPlane.Width, pictureBoxPlane.Height, pictureBoxPlane.Image = _abstractMap.CreateMap(pictureBoxPlane.Width, pictureBoxPlane.Height,
new DrawingObject(plane)); new DrawingObject(plane));
} }
@ -61,11 +62,7 @@ namespace ProjectPlane
SetData(plane); SetData(plane);
} }
private void PictureBoxPlane_Resize(object sender, EventArgs e)
{
_plane?.ChangeBorders(pictureBoxPlane.Width, pictureBoxPlane.Height);
Draw();
}
/// <summary> /// <summary>
/// Обработка нажатия кнопки "Модификация" /// Обработка нажатия кнопки "Модификация"
/// </summary> /// </summary>
@ -74,15 +71,14 @@ namespace ProjectPlane
private void buttonCreateModif_Click(object sender, EventArgs e) private void buttonCreateModif_Click(object sender, EventArgs e)
{ {
Random rnd = new(); Random rnd = new();
_plane = new DrawingWarPlane(rnd.Next(100, 300), rnd.Next(1000, 2000), var _plane = new DrawingWarPlane(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData(); SetData(_plane);
Draw();
} }
} }
} }
}

View File

@ -19,7 +19,10 @@
} }
base.Dispose(disposing); base.Dispose(disposing);
} }
private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
}
#region Windows Form Designer generated code #region Windows Form Designer generated code
/// <summary> /// <summary>
@ -114,6 +117,7 @@
this.statusStrip1.Size = new System.Drawing.Size(800, 22); this.statusStrip1.Size = new System.Drawing.Size(800, 22);
this.statusStrip1.TabIndex = 9; this.statusStrip1.TabIndex = 9;
this.statusStrip1.Text = "statusStrip1"; this.statusStrip1.Text = "statusStrip1";
this.statusStrip1.ItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.statusStrip1_ItemClicked);
// //
// toolStripStatusLabelSpeed // toolStripStatusLabelSpeed
// //

View File

@ -82,5 +82,7 @@
SetData(); SetData();
Draw(); Draw();
} }
} }
} }

View File

@ -9,7 +9,7 @@ namespace ProjectPlane
static void Main() static void Main()
{ {
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new FormPlane()); Application.Run(new FormMap());
} }
} }
} }