This commit is contained in:
shadowik 2022-09-23 14:53:53 +04:00
parent c38737fa61
commit 5ee4ef719c
4 changed files with 86 additions and 36 deletions

View File

@ -116,16 +116,11 @@ namespace DoubleDeckerBus
if (startX < 0 || startY < 0 || endX > _map.GetLength(1) || endY > _map.GetLength(0)) { return false; } if (startX < 0 || startY < 0 || endX > _map.GetLength(1) || endY > _map.GetLength(0)) { return false; }
/* startX = (int)((pos.Left - 5) / _size_x);
endX = (int)((pos.Right + 5) / _size_x);
startY = (int)((pos.Top - 5) / _size_y);
endY = (int)((pos.Bottom + 5) / _size_y);*/
for (int y = startY; y <= endY + 1; y++)
for (int y = startY - 1; y <= endY + 1; y++)
{ {
for (int x = startX - 1; x <= endX + 1; x++) for (int x = startX; x <= endX + 1; x++)
{ {
if (_map[x, y] == _barrier) if (_map[x, y] == _barrier)
{ {

View File

@ -47,10 +47,9 @@
// buttonCreate // buttonCreate
// //
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreate.Location = new System.Drawing.Point(0, 292); this.buttonCreate.Location = new System.Drawing.Point(0, 389);
this.buttonCreate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonCreate.Name = "buttonCreate"; this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(87, 21); this.buttonCreate.Size = new System.Drawing.Size(99, 28);
this.buttonCreate.TabIndex = 2; this.buttonCreate.TabIndex = 2;
this.buttonCreate.Text = "Создать"; this.buttonCreate.Text = "Создать";
this.buttonCreate.UseVisualStyleBackColor = true; this.buttonCreate.UseVisualStyleBackColor = true;
@ -61,10 +60,9 @@
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::DoubleDeckerBus.Properties.Resources.UpArrow; this.buttonUp.BackgroundImage = global::DoubleDeckerBus.Properties.Resources.UpArrow;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(628, 253); this.buttonUp.Location = new System.Drawing.Point(718, 337);
this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonUp.Name = "buttonUp"; this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(26, 22); this.buttonUp.Size = new System.Drawing.Size(30, 29);
this.buttonUp.TabIndex = 3; this.buttonUp.TabIndex = 3;
this.buttonUp.Text = " "; this.buttonUp.Text = " ";
this.buttonUp.UseVisualStyleBackColor = true; this.buttonUp.UseVisualStyleBackColor = true;
@ -75,10 +73,9 @@
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::DoubleDeckerBus.Properties.Resources.LeftArrow; this.buttonLeft.BackgroundImage = global::DoubleDeckerBus.Properties.Resources.LeftArrow;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(606, 272); this.buttonLeft.Location = new System.Drawing.Point(693, 363);
this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(26, 22); this.buttonLeft.Size = new System.Drawing.Size(30, 29);
this.buttonLeft.TabIndex = 4; this.buttonLeft.TabIndex = 4;
this.buttonLeft.Text = " "; this.buttonLeft.Text = " ";
this.buttonLeft.UseVisualStyleBackColor = true; this.buttonLeft.UseVisualStyleBackColor = true;
@ -89,10 +86,9 @@
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::DoubleDeckerBus.Properties.Resources.DownArrow; this.buttonDown.BackgroundImage = global::DoubleDeckerBus.Properties.Resources.DownArrow;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(629, 291); this.buttonDown.Location = new System.Drawing.Point(719, 388);
this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonDown.Name = "buttonDown"; this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(26, 22); this.buttonDown.Size = new System.Drawing.Size(30, 29);
this.buttonDown.TabIndex = 5; this.buttonDown.TabIndex = 5;
this.buttonDown.Text = " "; this.buttonDown.Text = " ";
this.buttonDown.UseVisualStyleBackColor = true; this.buttonDown.UseVisualStyleBackColor = true;
@ -103,10 +99,9 @@
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::DoubleDeckerBus.Properties.Resources.RightArrow; this.buttonRight.BackgroundImage = global::DoubleDeckerBus.Properties.Resources.RightArrow;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(652, 272); this.buttonRight.Location = new System.Drawing.Point(745, 363);
this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonRight.Name = "buttonRight"; this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(26, 22); this.buttonRight.Size = new System.Drawing.Size(30, 29);
this.buttonRight.TabIndex = 6; this.buttonRight.TabIndex = 6;
this.buttonRight.Text = " "; this.buttonRight.Text = " ";
this.buttonRight.UseVisualStyleBackColor = true; this.buttonRight.UseVisualStyleBackColor = true;
@ -116,18 +111,18 @@
// //
this.pictureBoxBus.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBoxBus.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBoxBus.Location = new System.Drawing.Point(0, 0); this.pictureBoxBus.Location = new System.Drawing.Point(0, 0);
this.pictureBoxBus.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.pictureBoxBus.Name = "pictureBoxBus"; this.pictureBoxBus.Name = "pictureBoxBus";
this.pictureBoxBus.Size = new System.Drawing.Size(700, 316); this.pictureBoxBus.Size = new System.Drawing.Size(800, 425);
this.pictureBoxBus.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.pictureBoxBus.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxBus.TabIndex = 7; this.pictureBoxBus.TabIndex = 7;
this.pictureBoxBus.TabStop = false; this.pictureBoxBus.TabStop = false;
// //
// buttonСreateExtra // buttonСreateExtra
// //
this.buttonСreateExtra.Location = new System.Drawing.Point(103, 291); this.buttonСreateExtra.Location = new System.Drawing.Point(118, 388);
this.buttonСreateExtra.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonСreateExtra.Name = "buttonСreateExtra"; this.buttonСreateExtra.Name = "buttonСreateExtra";
this.buttonСreateExtra.Size = new System.Drawing.Size(99, 21); this.buttonСreateExtra.Size = new System.Drawing.Size(113, 28);
this.buttonСreateExtra.TabIndex = 8; this.buttonСreateExtra.TabIndex = 8;
this.buttonСreateExtra.Text = "Модификация"; this.buttonСreateExtra.Text = "Модификация";
this.buttonСreateExtra.UseVisualStyleBackColor = true; this.buttonСreateExtra.UseVisualStyleBackColor = true;
@ -136,19 +131,19 @@
// toolStripStatusLabelSpeed // toolStripStatusLabelSpeed
// //
this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(65, 17); this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(80, 20);
this.toolStripStatusLabelSpeed.Text = "Скорость: "; this.toolStripStatusLabelSpeed.Text = "Скорость: ";
// //
// toolStripStatusLabelWeight // toolStripStatusLabelWeight
// //
this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(32, 17); this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(40, 20);
this.toolStripStatusLabelWeight.Text = "Вес: "; this.toolStripStatusLabelWeight.Text = "Вес: ";
// //
// toolStripStatusLabelBodyColor // toolStripStatusLabelBodyColor
// //
this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(39, 17); this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(49, 20);
this.toolStripStatusLabelBodyColor.Text = "Цвет: "; this.toolStripStatusLabelBodyColor.Text = "Цвет: ";
// //
// statusStrip1 // statusStrip1
@ -158,10 +153,9 @@
this.toolStripStatusLabelSpeed, this.toolStripStatusLabelSpeed,
this.toolStripStatusLabelWeight, this.toolStripStatusLabelWeight,
this.toolStripStatusLabelBodyColor}); this.toolStripStatusLabelBodyColor});
this.statusStrip1.Location = new System.Drawing.Point(0, 316); this.statusStrip1.Location = new System.Drawing.Point(0, 425);
this.statusStrip1.Name = "statusStrip1"; this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 12, 0); this.statusStrip1.Size = new System.Drawing.Size(800, 26);
this.statusStrip1.Size = new System.Drawing.Size(700, 22);
this.statusStrip1.TabIndex = 1; this.statusStrip1.TabIndex = 1;
this.statusStrip1.Text = "statusStrip1"; this.statusStrip1.Text = "statusStrip1";
// //
@ -170,18 +164,20 @@
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSelectorMap.FormattingEnabled = true; this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] { this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Простая карта"}); "Простая карта",
"Водная карта"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(0, 0); this.comboBoxSelectorMap.Location = new System.Drawing.Point(0, 0);
this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23); this.comboBoxSelectorMap.Size = new System.Drawing.Size(138, 28);
this.comboBoxSelectorMap.TabIndex = 9; this.comboBoxSelectorMap.TabIndex = 9;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
// //
// FormMap // 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.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(700, 338); this.ClientSize = new System.Drawing.Size(800, 451);
this.Controls.Add(this.comboBoxSelectorMap); this.Controls.Add(this.comboBoxSelectorMap);
this.Controls.Add(this.buttonСreateExtra); this.Controls.Add(this.buttonСreateExtra);
this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonRight);
@ -191,6 +187,7 @@
this.Controls.Add(this.buttonCreate); this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.pictureBoxBus); this.Controls.Add(this.pictureBoxBus);
this.Controls.Add(this.statusStrip1); this.Controls.Add(this.statusStrip1);
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormMap"; this.Name = "FormMap";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxBus)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxBus)).EndInit();
this.statusStrip1.ResumeLayout(false); this.statusStrip1.ResumeLayout(false);

View File

@ -17,6 +17,7 @@ namespace DoubleDeckerBus
{ {
InitializeComponent(); InitializeComponent();
_abstractMap = new SimpleMap(); _abstractMap = new SimpleMap();
comboBoxSelectorMap.SelectedIndex = 0;
} }
private void ButtonCreate_Click(object sender, EventArgs e) private void ButtonCreate_Click(object sender, EventArgs e)
@ -74,6 +75,9 @@ namespace DoubleDeckerBus
case "Простая карта": case "Простая карта":
_abstractMap = new SimpleMap(); _abstractMap = new SimpleMap();
break; break;
case "Водная карта":
_abstractMap = new WaterMap();
break;
} }
} }
} }

View File

@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DoubleDeckerBus
{
internal class WaterMap : AbstractMap
{
private readonly Brush barrierColor = new SolidBrush(Color.Blue);
private readonly Brush grassColor = new SolidBrush(Color.Green);
private readonly Brush lightGrassColor = new SolidBrush(Color.LightGreen);
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)
{
Random rnd = new Random();
if (rnd.Next(0, 7) == 6)
{
g.FillRectangle(grassColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1));
}
else {
g.FillRectangle(lightGrassColor, 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 < 50)
{
int x = _random.Next(0, 100);
int y = _random.Next(0, 100);
if (_map[x, y] == _freeRoad)
{
_map[x, y] = _barrier;
counter++;
}
}
}
}
}