Отрисовка монорельса

This commit is contained in:
Данила 2022-11-06 21:06:35 +04:00
parent 557dc963c5
commit d8b20b7584
9 changed files with 189 additions and 59 deletions

View File

@ -36,7 +36,7 @@ namespace Locomative
switch (direction) switch (direction)
{ {
case Direction.Up: case Direction.Up:
for (int i = 0; i < _map.GetLength(0); i++) for (int i = 0; i < _map?.GetLength(0); i++)
{ {
for (int j = 0; j < _map.GetLength(1); j++) for (int j = 0; j < _map.GetLength(1); j++)
{ {
@ -46,7 +46,7 @@ namespace Locomative
} }
break; break;
case Direction.Down: case Direction.Down:
for (int i = 0; i < _map.GetLength(0); i++) for (int i = 0; i < _map?.GetLength(0); i++)
{ {
for (int j = 0; j < _map.GetLength(1); j++) for (int j = 0; j < _map.GetLength(1); j++)
{ {
@ -59,7 +59,7 @@ namespace Locomative
} }
break; break;
case Direction.Left: case Direction.Left:
for (int i = 0; i < _map.GetLength(0); i++) for (int i = 0; i < _map?.GetLength(0); i++)
{ {
for (int j = 0; j < _map.GetLength(1); j++) for (int j = 0; j < _map.GetLength(1); j++)
{ {
@ -72,7 +72,7 @@ namespace Locomative
} }
break; break;
case Direction.Right: case Direction.Right:
for (int i = 0; i < _map.GetLength(0); i++) for (int i = 0; i < _map?.GetLength(0); i++)
{ {
for (int j = 0; j < _map.GetLength(1); j++) for (int j = 0; j < _map.GetLength(1); j++)
{ {
@ -85,7 +85,7 @@ namespace Locomative
} }
break; break;
} }
_drawningObject.MoveObject(direction); _drawningObject?.MoveObject(direction);
return DrawMapWithObject(); return DrawMapWithObject();
} }

View File

@ -1,17 +1,11 @@
using System; namespace Locomative
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Locomative
{ {
internal class DrawningFastLoco : DrawningLocomative internal class DrawningFastLoco : DrawningLocomative
{ {
public DrawningFastLoco(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool rockettoobe) : public DrawningFastLoco(int speed, float weight, Color bodyColor, Color dopColor, bool widow, bool room) :
base(speed, weight, bodyColor, 110, 60) base(speed, weight, bodyColor, 110, 60)
{ {
Locomative = new EntityFastLocomative(speed, weight, bodyColor, dopColor, bodyKit, wing, rockettoobe); Locomative = new EntityFastLocomative(speed, weight, bodyColor, dopColor, widow, room);
} }
public override void DrawTransport(Graphics g) public override void DrawTransport(Graphics g)
{ {
@ -24,33 +18,52 @@ namespace Locomative
Pen pen = new(Color.Black); Pen pen = new(Color.Black);
Brush brWhite = new SolidBrush(Color.White); Brush brWhite = new SolidBrush(Color.White);
Brush bodyBrush = new SolidBrush(fastLocomative.BodyColor); Brush bodyBrush = new SolidBrush(fastLocomative.BodyColor);
Brush dopBrush = new SolidBrush(fastLocomative.DopColor);
Brush brBlack = new SolidBrush(Color.Black); Brush brBlack = new SolidBrush(Color.Black);
if (fastLocomative.BodyKit) //вид слева
{ Point point1 = new Point(Convert.ToInt32(_startPosX), Convert.ToInt32(_startPosY));
//поезд Point point2 = new Point(Convert.ToInt32(_startPosX+90), Convert.ToInt32(_startPosY + 2));
g.FillRectangle(brWhite, _startPosX, _startPosY, 120, 40); Point point3 = new Point(Convert.ToInt32(_startPosX+100), Convert.ToInt32(_startPosY + 42));
g.DrawRectangle(pen, _startPosX, _startPosY, 120, 40); Point point4 = new Point(Convert.ToInt32(_startPosX), Convert.ToInt32(_startPosY + 40));
//окно Point[] points = { point1, point2, point3, point4 };
g.FillRectangle(bodyBrush, _startPosX+90, _startPosY+5, 20, 30); g.FillPolygon(brWhite, points);
g.DrawRectangle(pen, _startPosX + 90, _startPosY + 5, 20, 30); g.DrawPolygon(pen, points);
//верхние края //окна
g.DrawLine(pen, _startPosX, _startPosY + 5, _startPosX + 90, _startPosY + 5); Point p_1_1 = new Point(Convert.ToInt32(_startPosX + 5), Convert.ToInt32(_startPosY + 10));
g.DrawLine(pen, _startPosX, _startPosY + 35, _startPosX + 90, _startPosY + 35); Point p_1_2 = new Point(Convert.ToInt32(_startPosX + 45), Convert.ToInt32(_startPosY + 11));
//отверстие под рельсы Point p_1_3 = new Point(Convert.ToInt32(_startPosX + 45), Convert.ToInt32(_startPosY + 31));
Point point1 = new Point(Convert.ToInt32(_startPosX + 120), Convert.ToInt32(_startPosY + 4)); Point p_1_4 = new Point(Convert.ToInt32(_startPosX + 5), Convert.ToInt32(_startPosY + 30));
Point point2 = new Point(Convert.ToInt32(_startPosX + 115), Convert.ToInt32(_startPosY + 8)); Point[] points1 = { p_1_1, p_1_2, p_1_3, p_1_4 };
Point point3 = new Point(Convert.ToInt32(_startPosX + 115), Convert.ToInt32(_startPosY + 32)); g.DrawPolygon(pen, points1);
Point point4 = new Point(Convert.ToInt32(_startPosX + 120), Convert.ToInt32(_startPosY + 36)); Point p_2_1 = new Point(Convert.ToInt32(_startPosX + 55), Convert.ToInt32(_startPosY + 11));
Point[] points = { point1, point2, point3, point4 }; Point p_2_2 = new Point(Convert.ToInt32(_startPosX + 89), Convert.ToInt32(_startPosY + 12));
g.FillPolygon(brBlack, points); Point p_2_3 = new Point(Convert.ToInt32(_startPosX + 95), Convert.ToInt32(_startPosY + 32));
Point p_2_4 = new Point(Convert.ToInt32(_startPosX + 55), Convert.ToInt32(_startPosY + 31));
Point[] points2 = { p_2_1, p_2_2, p_2_3, p_2_4 };
g.DrawPolygon(pen, points2);
//поезд спереди
Point p_3_1 = new Point(Convert.ToInt32(_startPosX + 90), Convert.ToInt32(_startPosY + 2));
Point p_3_2 = new Point(Convert.ToInt32(_startPosX + 110), Convert.ToInt32(_startPosY));
Point p_3_3 = new Point(Convert.ToInt32(_startPosX + 120), Convert.ToInt32(_startPosY + 40));
Point p_3_4 = new Point(Convert.ToInt32(_startPosX + 100), Convert.ToInt32(_startPosY + 42));
Point[] points3 = { p_3_1, p_3_2, p_3_3, p_3_4 };
g.FillPolygon(brWhite, points3);
g.DrawPolygon(pen, points3);
//окно спереди
Point p_4_1 = new Point(Convert.ToInt32(_startPosX + 90), Convert.ToInt32(_startPosY + 2));
Point p_4_2 = new Point(Convert.ToInt32(_startPosX + 110), Convert.ToInt32(_startPosY));
Point p_4_3 = new Point(Convert.ToInt32(_startPosX + 120), Convert.ToInt32(_startPosY + 40));
Point p_4_4 = new Point(Convert.ToInt32(_startPosX + 100), Convert.ToInt32(_startPosY + 42));
Point[] points4 = { p_4_1, p_4_2, p_4_3, p_4_4 };
g.DrawPolygon(pen, points4);////////////////////////////////////
//окно зараска
if (fastLocomative.bodyKit) {
} }
//вторая кабина //вторая кабина
if (fastLocomative.Room) if (fastLocomative.room)
{ {
g.FillRectangle(brWhite, _startPosX-125, _startPosY, 120, 40);
g.DrawRectangle(pen, _startPosX-125, _startPosY, 120, 40);
g.DrawRectangle(pen, _startPosX-5, _startPosY+18, 5, 4);
} }
} }
} }

View File

@ -8,17 +8,17 @@ namespace Locomative
{ {
internal class EntityFastLocomative : EntityLocomative internal class EntityFastLocomative : EntityLocomative
{ {
public Color DopColor { get; private set; } public Color dopColor { get; private set; }
public bool Wing { get; private set; } public bool wing { get; private set; }
public bool BodyKit { get; private set; } public bool bodyKit { get; private set; }
public bool Room { get; private set; } public bool room { get; private set; }
public EntityFastLocomative(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool room) : public EntityFastLocomative(int speed, float weight, Color bodyColor, Color dopColor, bool widow, bool room) :
base(speed, weight, bodyColor) base(speed, weight, bodyColor)
{ {
DopColor = dopColor; this.dopColor = dopColor;
BodyKit = bodyKit; this.bodyKit = widow;
Wing = wing; this.wing = wing;
Room = room; this.room = room;
} }
} }
} }

View File

@ -52,7 +52,7 @@
this.buttonСreate.Name = "buttonСreate"; this.buttonСreate.Name = "buttonСreate";
this.buttonСreate.Size = new System.Drawing.Size(88, 27); this.buttonСreate.Size = new System.Drawing.Size(88, 27);
this.buttonСreate.TabIndex = 0; this.buttonСreate.TabIndex = 0;
this.buttonСreate.Text = "Создание"; this.buttonСreate.Text = "Create";
this.buttonСreate.UseVisualStyleBackColor = true; this.buttonСreate.UseVisualStyleBackColor = true;
this.buttonСreate.Click += new System.EventHandler(this.buttonСreate_Click); this.buttonСreate.Click += new System.EventHandler(this.buttonСreate_Click);
// //
@ -95,20 +95,20 @@
// toolStripStatusLabelSpeed // toolStripStatusLabelSpeed
// //
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(59, 17); this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(39, 17);
this.toolStripStatusLabelSpeed.Text = "Скорость"; this.toolStripStatusLabelSpeed.Text = "Speed";
// //
// toolStripStatusLabelWeight // toolStripStatusLabelWeight
// //
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(26, 17); this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(42, 17);
this.toolStripStatusLabelWeight.Text = "Вес"; this.toolStripStatusLabelWeight.Text = "Weght";
// //
// toolStripStatusLabelColor // toolStripStatusLabelColor
// //
this.toolStripStatusLabelColor.Name = "toolStripStatusLabelColor"; this.toolStripStatusLabelColor.Name = "toolStripStatusLabelColor";
this.toolStripStatusLabelColor.Size = new System.Drawing.Size(33, 17); this.toolStripStatusLabelColor.Size = new System.Drawing.Size(36, 17);
this.toolStripStatusLabelColor.Text = "Цвет"; this.toolStripStatusLabelColor.Text = "Color";
// //
// buttonLeft // buttonLeft
// //
@ -157,7 +157,7 @@
this.ButtonFastCreate.Name = "ButtonFastCreate"; this.ButtonFastCreate.Name = "ButtonFastCreate";
this.ButtonFastCreate.Size = new System.Drawing.Size(113, 27); this.ButtonFastCreate.Size = new System.Drawing.Size(113, 27);
this.ButtonFastCreate.TabIndex = 7; this.ButtonFastCreate.TabIndex = 7;
this.ButtonFastCreate.Text = "Модификация"; this.ButtonFastCreate.Text = "Modicated";
this.ButtonFastCreate.UseVisualStyleBackColor = true; this.ButtonFastCreate.UseVisualStyleBackColor = true;
this.ButtonFastCreate.Click += new System.EventHandler(this.ButtonFastCreate_Click); this.ButtonFastCreate.Click += new System.EventHandler(this.ButtonFastCreate_Click);
// //
@ -166,7 +166,9 @@
this.comboBoxSelectirMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxSelectirMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSelectirMap.FormattingEnabled = true; this.comboBoxSelectirMap.FormattingEnabled = true;
this.comboBoxSelectirMap.Items.AddRange(new object[] { this.comboBoxSelectirMap.Items.AddRange(new object[] {
"Простая карта"}); "SimpleMap",
"UserMap #1",
"UserMap #2"});
this.comboBoxSelectirMap.Location = new System.Drawing.Point(14, 14); this.comboBoxSelectirMap.Location = new System.Drawing.Point(14, 14);
this.comboBoxSelectirMap.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); this.comboBoxSelectirMap.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
this.comboBoxSelectirMap.Name = "comboBoxSelectirMap"; this.comboBoxSelectirMap.Name = "comboBoxSelectirMap";

View File

@ -68,7 +68,7 @@ namespace Locomative
var loco = new DrawningFastLoco(rnd.Next(50, 250), rnd.Next(100, 300), var loco = new DrawningFastLoco(rnd.Next(50, 250), rnd.Next(100, 300),
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)),
true, true, true); Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData(loco); SetData(loco);
} }
@ -76,9 +76,15 @@ namespace Locomative
{ {
switch (comboBoxSelectirMap.Text) switch (comboBoxSelectirMap.Text)
{ {
case "Простая карта": case "SimpleMap":
_abstractMap = new SimpleMap(); _abstractMap = new SimpleMap();
break; break;
case "UserMap #1":
_abstractMap = new UserMap_BigBox();
break;
case "UserMap #2":
_abstractMap = new UserMap_Rally();
break;
} }
} }
} }

View File

@ -79,7 +79,7 @@ namespace Locomative
_loco = new DrawningFastLoco(rnd.Next(1, 200), rnd.Next(100, 300), _loco = new DrawningFastLoco(rnd.Next(1, 200), rnd.Next(100, 300),
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)),
true, true, true); Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData(); SetData();
Draw(); Draw();
} }

View File

@ -31,7 +31,7 @@ namespace Locomative
_map[i, j] = _freeRoad; _map[i, j] = _freeRoad;
} }
} }
while(counter < 50) while(counter < 30)
{ {
int x = _random.Next(0, 100); int x = _random.Next(0, 100);
int y = _random.Next(0, 100); int y = _random.Next(0, 100);

View File

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Locomative
{
internal class UserMap_BigBox : AbstractMap
{
Brush barrierColor = new SolidBrush(Color.DarkGray);
Brush roadColor = new SolidBrush(Color.Aqua);
protected override void DrawBarrielPart(Graphics g, int i, int j)
{
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
}
protected override void DrawRailPart(Graphics g, int i, int j)
{
g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
}
protected override void GenerateMap()
{
_map = new int[100, 100];
_size_x = (float)_width / _map.GetLength(0);
_size_y = (float)_height / _map.GetLength(1);
int counter = 0;
for (int i = 0; i < _map.GetLength(0); ++i)
{
for (int j = 0; j < _map.GetLength(1); ++j)
{
_map[i, j] = _freeRoad;
}
}
while (counter < 30)
{
int x = _random.Next(0, 100);
int y = _random.Next(0, 100);
if (_map[x, y] == _freeRoad)
{
_map[x, y] = _barrier;
counter++;
}
}
}
}
}

View File

@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Locomative
{
internal class UserMap_Rally : AbstractMap
{
Brush barrielColor = new SolidBrush(Color.Red);
Brush railColor = new SolidBrush(Color.Gray);
protected override void DrawBarrielPart(Graphics g, int i, int j)
{
g.FillRectangle(barrielColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
}
protected override void DrawRailPart(Graphics g, int i, int j)
{
g.FillRectangle(railColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
}
protected override void GenerateMap()
{
int sizeKub = 3;
_map = new int[100, 100];
_size_x = (float)_width / _map.GetLength(0);
_size_y = (float)_height / _map.GetLength(1);
int counter = 0;
for (int i = 0; i < _map.GetLength(0); ++i)
{
for (int j = 0; j < _map.GetLength(1); ++j)
{
_map[i, j] = _freeRoad;
}
}
for (int i = 0; i < _map.GetLength(0); ++i)
{
_map[i, 1] = _barrier;
_map[i, 99] = _barrier;
_map[1, i] = _barrier;
_map[99, i] = _barrier;
}
while (counter < 10)
{
Random rand = new Random();
int i = rand.Next(10, 80);
int j = rand.Next(10, 80);
if (i > _map.GetLength(0) - sizeKub || j > _map.GetLength(0) - sizeKub)
continue;
for (int iKub = i; iKub < i + sizeKub; iKub++)
{
for (int jKub = j; jKub < j + sizeKub; jKub++)
{
_map[iKub, jKub] = _barrier;
}
}
counter++;
}
}
}
}