2_Laba Kalyshev Y V PIbd-22 #3
@ -48,6 +48,34 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
|
||||
int y = _random.Next(0, 10);
|
||||
_drawningObject.SetObject(x, y, _width, _height);
|
||||
// TODO првоерка, что объект не "накладывается" на закрытые участки
|
||||
while (!CheckEnoughPlace())
|
||||
{
|
||||
x += 10;
|
||||
if (x >= _width)
|
||||
{
|
||||
y += 10;
|
||||
x = 0;
|
||||
}
|
||||
_drawningObject.SetObject(x, y, _width, _height);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private bool CheckEnoughPlace()
|
||||
{
|
||||
int right = Convert.ToInt32(_drawningObject.GetCurrentPosition().Right / _size_x);
|
||||
int left = Convert.ToInt32(_drawningObject.GetCurrentPosition().Left / _size_x);
|
||||
int up = Convert.ToInt32(_drawningObject.GetCurrentPosition().Top / _size_y);
|
||||
int down = Convert.ToInt32(_drawningObject.GetCurrentPosition().Bottom / _size_y);
|
||||
for (int i = left; i <= right; i++)
|
||||
{
|
||||
for (int j = up; j <= down; j++)
|
||||
{
|
||||
if (_map[i, j] == _barrier)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private Bitmap DrawMapWithObject()
|
||||
|
@ -51,29 +51,28 @@
|
||||
this.toolStripStatusLabelSpeed,
|
||||
this.toolStripStatusLabelWeight,
|
||||
this.toolStripStatusLabelBodyColor});
|
||||
this.statusStrip1.Location = new System.Drawing.Point(0, 318);
|
||||
this.statusStrip1.Location = new System.Drawing.Point(0, 427);
|
||||
this.statusStrip1.Name = "statusStrip1";
|
||||
this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 12, 0);
|
||||
this.statusStrip1.Size = new System.Drawing.Size(772, 22);
|
||||
this.statusStrip1.Size = new System.Drawing.Size(882, 26);
|
||||
this.statusStrip1.TabIndex = 0;
|
||||
this.statusStrip1.Text = "statusStrip1";
|
||||
//
|
||||
// toolStripStatusLabelSpeed
|
||||
//
|
||||
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
|
||||
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(62, 17);
|
||||
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(76, 20);
|
||||
this.toolStripStatusLabelSpeed.Text = "Скорость:";
|
||||
//
|
||||
// toolStripStatusLabelWeight
|
||||
//
|
||||
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
|
||||
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(29, 17);
|
||||
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(36, 20);
|
||||
this.toolStripStatusLabelWeight.Text = "Вес:";
|
||||
//
|
||||
// toolStripStatusLabelBodyColor
|
||||
//
|
||||
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
|
||||
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17);
|
||||
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(45, 20);
|
||||
this.toolStripStatusLabelBodyColor.Text = "Цвет:";
|
||||
//
|
||||
// pictureBoxBoat
|
||||
@ -81,9 +80,8 @@
|
||||
this.pictureBoxBoat.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
|
||||
this.pictureBoxBoat.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBoxBoat.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxBoat.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.pictureBoxBoat.Name = "pictureBoxBoat";
|
||||
this.pictureBoxBoat.Size = new System.Drawing.Size(772, 318);
|
||||
this.pictureBoxBoat.Size = new System.Drawing.Size(882, 427);
|
||||
this.pictureBoxBoat.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||
this.pictureBoxBoat.TabIndex = 1;
|
||||
this.pictureBoxBoat.TabStop = false;
|
||||
@ -91,10 +89,9 @@
|
||||
// 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(10, 289);
|
||||
this.buttonCreate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonCreate.Location = new System.Drawing.Point(11, 385);
|
||||
this.buttonCreate.Name = "buttonCreate";
|
||||
this.buttonCreate.Size = new System.Drawing.Size(82, 22);
|
||||
this.buttonCreate.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonCreate.TabIndex = 2;
|
||||
this.buttonCreate.Text = "Создать";
|
||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||
@ -105,10 +102,9 @@
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::PIbd_22_Kalyshev_Y_V_MotorBoat_Base.Properties.Resources.right;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonRight.Location = new System.Drawing.Point(718, 280);
|
||||
this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonRight.Location = new System.Drawing.Point(821, 373);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(35, 30);
|
||||
this.buttonRight.Size = new System.Drawing.Size(40, 40);
|
||||
this.buttonRight.TabIndex = 3;
|
||||
this.buttonRight.UseVisualStyleBackColor = true;
|
||||
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
@ -118,10 +114,9 @@
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::PIbd_22_Kalyshev_Y_V_MotorBoat_Base.Properties.Resources.left;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(637, 280);
|
||||
this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(728, 373);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(35, 30);
|
||||
this.buttonLeft.Size = new System.Drawing.Size(40, 40);
|
||||
this.buttonLeft.TabIndex = 4;
|
||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
@ -131,10 +126,9 @@
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::PIbd_22_Kalyshev_Y_V_MotorBoat_Base.Properties.Resources.up;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonUp.Location = new System.Drawing.Point(677, 246);
|
||||
this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonUp.Location = new System.Drawing.Point(774, 328);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(35, 30);
|
||||
this.buttonUp.Size = new System.Drawing.Size(40, 40);
|
||||
this.buttonUp.TabIndex = 5;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
@ -144,10 +138,9 @@
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::PIbd_22_Kalyshev_Y_V_MotorBoat_Base.Properties.Resources.down;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
|
||||
this.buttonDown.Location = new System.Drawing.Point(677, 280);
|
||||
this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.buttonDown.Location = new System.Drawing.Point(774, 373);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(35, 30);
|
||||
this.buttonDown.Size = new System.Drawing.Size(40, 40);
|
||||
this.buttonDown.TabIndex = 6;
|
||||
this.buttonDown.UseVisualStyleBackColor = true;
|
||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||
@ -155,9 +148,10 @@
|
||||
// buttonCreateModif
|
||||
//
|
||||
this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.buttonCreateModif.Location = new System.Drawing.Point(98, 289);
|
||||
this.buttonCreateModif.Location = new System.Drawing.Point(112, 385);
|
||||
this.buttonCreateModif.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||
this.buttonCreateModif.Size = new System.Drawing.Size(99, 22);
|
||||
this.buttonCreateModif.Size = new System.Drawing.Size(113, 29);
|
||||
this.buttonCreateModif.TabIndex = 7;
|
||||
this.buttonCreateModif.Text = "Модификация";
|
||||
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||
@ -168,18 +162,20 @@
|
||||
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.comboBoxSelectorMap.FormattingEnabled = true;
|
||||
this.comboBoxSelectorMap.Items.AddRange(new object[] {
|
||||
"Простая карта"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(10, 12);
|
||||
"Простая карта",
|
||||
"Своя карта"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(11, 16);
|
||||
this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(114, 23);
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(130, 28);
|
||||
this.comboBoxSelectorMap.TabIndex = 8;
|
||||
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
||||
//
|
||||
// FormMap
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(772, 340);
|
||||
this.ClientSize = new System.Drawing.Size(882, 453);
|
||||
this.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.Controls.Add(this.buttonCreateModif);
|
||||
this.Controls.Add(this.buttonDown);
|
||||
@ -189,6 +185,7 @@
|
||||
this.Controls.Add(this.buttonCreate);
|
||||
this.Controls.Add(this.pictureBoxBoat);
|
||||
this.Controls.Add(this.statusStrip1);
|
||||
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.Name = "FormMap";
|
||||
this.Text = "Карта";
|
||||
this.statusStrip1.ResumeLayout(false);
|
||||
|
@ -93,6 +93,9 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
|
||||
case "Простая карта":
|
||||
_abstractMap = new SimpleMap();
|
||||
break;
|
||||
case "Своя карта":
|
||||
_abstractMap = new MySecondMap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
54
PIbd-22_Kalyshev_Y_V_MotorBoat_Base.git/MySecondMap.cs
Normal file
54
PIbd-22_Kalyshev_Y_V_MotorBoat_Base.git/MySecondMap.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
|
||||
{
|
||||
internal class MySecondMap : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.Red);
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private readonly Brush roadColor = new SolidBrush(Color.FromArgb(242, 242, 242));
|
||||
protected override void DrawBarrierPart(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 DrawRoadPart(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[150, 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 < 10)
|
||||
{
|
||||
int x = _random.Next(0, _map.GetLength(0));
|
||||
int y = _random.Next(0, _map.GetLength(1));
|
||||
if (_map[x, y] == _freeRoad)
|
||||
{
|
||||
_map[x, y] = _barrier;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user