Kashin M.I. Lab work 2 #2

Merged
eegov merged 5 commits from LabWork02 into LabWork01 2022-09-30 11:14:43 +04:00
4 changed files with 51 additions and 71 deletions
Showing only changes of commit 74bedf29c8 - Show all commits

View File

@ -38,17 +38,17 @@ namespace GasolineTanker
private int CheckCollision(float Left, float Right, float Top, float Bottom)
{
int starCellX = (int)(Left / _size_x);
int starCellY = (int)(Right / _size_y);
int endCellX = (int)(Top / _size_x);
int endCellY = (int)(Bottom / _size_y);
if (starCellX < 0 || starCellY < 0 || endCellX >= _map.GetLength(1) || endCellY >= _map.GetLength(0))
int starCoordinateX = (int)(Left / _size_x);
int starCoordinateY = (int)(Right / _size_y);
int endCoordinateX = (int)(Top / _size_x);
int endCoordinateY = (int)(Bottom / _size_y);
if (starCoordinateX < 0 || starCoordinateY < 0 || endCoordinateX >= _map.GetLength(1) || endCoordinateY >= _map.GetLength(0))
{
return 2;
}
for (int x = starCellX; x <= endCellX; x++)
for (int x = starCoordinateX; x <= endCoordinateX; x++)
{
for (int y = starCellY; y <= endCellY; y++)
for (int y = starCoordinateY; y <= endCoordinateY; y++)
{
if (_map[x, y] == _barrier)
{
@ -95,28 +95,25 @@ namespace GasolineTanker
int y = _random.Next(0, 10);
_drawningObject.SetObject(x, y, _width, _height);
(float Left, float Right, float Top, float Bottom) = _drawningObject.GetCurrentPosition();
float nowX = Left;
float nowY = Right;
float lenX = Top - Left;
float lenY = Bottom - Right;
while (CheckCollision(nowX, nowY, nowX + lenX, nowY + lenY) != 2)
while (CheckCollision(Left, Right, Top, Bottom) != 2)
{
int resout;
int resoult;
do
{
resout = CheckCollision(nowX, nowY, nowX + lenX, nowY + lenY);
if (resout == 0)
resoult = CheckCollision(Left, Right, Top, Bottom);
if (resoult == 0)
{
_drawningObject.SetObject((int)nowX, (int)nowY, _width, _height);
_drawningObject.SetObject((int)Left, (int)Right, _width, _height);
return true;
}
else
{
nowX += _size_x;
Left += _size_x;
}
} while (resout != 2);
nowX = x;
nowY += _size_y;
} while (resoult != 2);
Left = x;
Right += _size_y;
}
return false;
}

View File

@ -48,9 +48,8 @@
//
this.pictureBoxGasolineTanker.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxGasolineTanker.Location = new System.Drawing.Point(0, 0);
this.pictureBoxGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.pictureBoxGasolineTanker.Name = "pictureBoxGasolineTanker";
this.pictureBoxGasolineTanker.Size = new System.Drawing.Size(922, 574);
this.pictureBoxGasolineTanker.Size = new System.Drawing.Size(807, 428);
this.pictureBoxGasolineTanker.TabIndex = 0;
this.pictureBoxGasolineTanker.TabStop = false;
//
@ -61,38 +60,36 @@
this.toolStripStatusSpeed,
this.toolStripStatusWeight,
this.toolStripStatusBodyColor});
this.statusStrip1.Location = new System.Drawing.Point(0, 574);
this.statusStrip1.Location = new System.Drawing.Point(0, 428);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 16, 0);
this.statusStrip1.Size = new System.Drawing.Size(922, 26);
this.statusStrip1.Size = new System.Drawing.Size(807, 22);
this.statusStrip1.TabIndex = 1;
this.statusStrip1.Text = "statusStrip1";
//
// toolStripStatusSpeed
//
this.toolStripStatusSpeed.Name = "toolStripStatusSpeed";
this.toolStripStatusSpeed.Size = new System.Drawing.Size(51, 20);
this.toolStripStatusSpeed.Size = new System.Drawing.Size(39, 17);
this.toolStripStatusSpeed.Text = "Speed";
//
// toolStripStatusWeight
//
this.toolStripStatusWeight.Name = "toolStripStatusWeight";
this.toolStripStatusWeight.Size = new System.Drawing.Size(56, 20);
this.toolStripStatusWeight.Size = new System.Drawing.Size(45, 17);
this.toolStripStatusWeight.Text = "Weight";
//
// toolStripStatusBodyColor
//
this.toolStripStatusBodyColor.Name = "toolStripStatusBodyColor";
this.toolStripStatusBodyColor.Size = new System.Drawing.Size(45, 20);
this.toolStripStatusBodyColor.Size = new System.Drawing.Size(36, 17);
this.toolStripStatusBodyColor.Text = "Color";
//
// buttonCreate
//
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreate.Location = new System.Drawing.Point(14, 524);
this.buttonCreate.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonCreate.Location = new System.Drawing.Point(12, 393);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(86, 31);
this.buttonCreate.Size = new System.Drawing.Size(75, 23);
this.buttonCreate.TabIndex = 2;
this.buttonCreate.Text = "Create";
this.buttonCreate.UseVisualStyleBackColor = true;
@ -103,10 +100,9 @@
this.keyDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.keyDown.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyDown;
this.keyDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.keyDown.Location = new System.Drawing.Point(827, 515);
this.keyDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.keyDown.Location = new System.Drawing.Point(724, 386);
this.keyDown.Name = "keyDown";
this.keyDown.Size = new System.Drawing.Size(34, 40);
this.keyDown.Size = new System.Drawing.Size(30, 30);
this.keyDown.TabIndex = 3;
this.keyDown.UseVisualStyleBackColor = true;
this.keyDown.Click += new System.EventHandler(this.ButtonMove_Click);
@ -116,10 +112,9 @@
this.keyUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.keyUp.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyUp;
this.keyUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.keyUp.Location = new System.Drawing.Point(827, 467);
this.keyUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.keyUp.Location = new System.Drawing.Point(724, 350);
this.keyUp.Name = "keyUp";
this.keyUp.Size = new System.Drawing.Size(34, 40);
this.keyUp.Size = new System.Drawing.Size(30, 30);
this.keyUp.TabIndex = 4;
this.keyUp.UseVisualStyleBackColor = true;
this.keyUp.Click += new System.EventHandler(this.ButtonMove_Click);
@ -129,10 +124,9 @@
this.keyLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.keyLeft.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyLeft;
this.keyLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.keyLeft.Location = new System.Drawing.Point(786, 515);
this.keyLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.keyLeft.Location = new System.Drawing.Point(688, 386);
this.keyLeft.Name = "keyLeft";
this.keyLeft.Size = new System.Drawing.Size(34, 40);
this.keyLeft.Size = new System.Drawing.Size(30, 30);
this.keyLeft.TabIndex = 5;
this.keyLeft.UseVisualStyleBackColor = true;
this.keyLeft.Click += new System.EventHandler(this.ButtonMove_Click);
@ -142,20 +136,18 @@
this.keyRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.keyRight.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyRight;
this.keyRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.keyRight.Location = new System.Drawing.Point(869, 515);
this.keyRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.keyRight.Location = new System.Drawing.Point(760, 386);
this.keyRight.Name = "keyRight";
this.keyRight.Size = new System.Drawing.Size(34, 40);
this.keyRight.Size = new System.Drawing.Size(30, 30);
this.keyRight.TabIndex = 6;
this.keyRight.UseVisualStyleBackColor = true;
this.keyRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
// ButtonCreateImproved
//
this.ButtonCreateImproved.Location = new System.Drawing.Point(106, 524);
this.ButtonCreateImproved.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.ButtonCreateImproved.Location = new System.Drawing.Point(93, 393);
this.ButtonCreateImproved.Name = "ButtonCreateImproved";
this.ButtonCreateImproved.Size = new System.Drawing.Size(86, 31);
this.ButtonCreateImproved.Size = new System.Drawing.Size(75, 23);
this.ButtonCreateImproved.TabIndex = 7;
this.ButtonCreateImproved.Text = "Improved";
this.ButtonCreateImproved.UseVisualStyleBackColor = true;
@ -167,19 +159,18 @@
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Simple map",
"Box map"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(14, 16);
this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
"Long map"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(138, 28);
this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23);
this.comboBoxSelectorMap.TabIndex = 8;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged);
//
// FormMap
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(922, 600);
this.ClientSize = new System.Drawing.Size(807, 450);
this.Controls.Add(this.comboBoxSelectorMap);
this.Controls.Add(this.ButtonCreateImproved);
this.Controls.Add(this.keyRight);
@ -189,7 +180,6 @@
this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.pictureBoxGasolineTanker);
this.Controls.Add(this.statusStrip1);
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormMap";
this.Text = "Map";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxGasolineTanker)).EndInit();

View File

@ -75,8 +75,8 @@ namespace GasolineTanker
case "Simple map":
_abstractMap = new SimpleMap();
break;
case "Box map":
_abstractMap = new BoxMap();
case "Long map":
_abstractMap = new LongMap();
break;
}
}

View File

@ -6,12 +6,9 @@ using System.Threading.Tasks;
namespace GasolineTanker
{
internal class BoxMap : AbstractMap
internal class LongMap : AbstractMap
{
/// <summary>
/// Цвет участка закрытого
/// </summary>
private readonly Brush barrierColor = new SolidBrush(Color.Blue);
private readonly Brush barrierColor = new SolidBrush(Color.Black);
private readonly Brush roadColor = new SolidBrush(Color.Gray);
protected override void DrawBarrierPart(Graphics g, int i, int j)
{
@ -34,20 +31,16 @@ namespace GasolineTanker
_map[i, j] = _freeRoad;
}
}
while (counter < 10)
while (counter < 5)
{
int sx = _random.Next(0, 100);
int sy = _random.Next(0, 100);
int ex = sx + _random.Next(0, 100 - sx);
int ey = sy + _random.Next(0, 100 - sy);
for (int i = sx; i <= ex; ++i)
int xStart = _random.Next(0, 100);
int xEnd = _random.Next(80, 100);
for (int i = xStart; i <= xEnd; ++i)
{
_map[i, ey] = _barrier;
}
for (int i = sy; i <= ey; i++)
{
_map[sx, i] = _barrier;
_map[i, xStart] = _barrier;
}
counter++;
}
}