change MyMap and rename buttons

This commit is contained in:
MaxKarme 2022-10-04 21:48:21 +03:00
parent c60f61ba18
commit d9446d1c46
2 changed files with 47 additions and 16 deletions

View File

@ -51,7 +51,7 @@
this.CreateButton.Name = "CreateButton"; this.CreateButton.Name = "CreateButton";
this.CreateButton.Size = new System.Drawing.Size(94, 29); this.CreateButton.Size = new System.Drawing.Size(94, 29);
this.CreateButton.TabIndex = 0; this.CreateButton.TabIndex = 0;
this.CreateButton.Text = "create"; this.CreateButton.Text = "создание";
this.CreateButton.UseVisualStyleBackColor = true; this.CreateButton.UseVisualStyleBackColor = true;
this.CreateButton.Click += new System.EventHandler(this.CreateButton_Click); this.CreateButton.Click += new System.EventHandler(this.CreateButton_Click);
// //
@ -156,7 +156,7 @@
this.button1.Name = "button1"; this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(148, 29); this.button1.Size = new System.Drawing.Size(148, 29);
this.button1.TabIndex = 7; this.button1.TabIndex = 7;
this.button1.Text = "create modern"; this.button1.Text = "модификация";
this.button1.UseVisualStyleBackColor = true; this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.CreateModernButton_Click); this.button1.Click += new System.EventHandler(this.CreateModernButton_Click);
// //

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -13,6 +13,7 @@ namespace AirFighter
/// Цвет участка закрытого /// Цвет участка закрытого
/// </summary> /// </summary>
private readonly Brush barrierColor = new SolidBrush(Color.Black); private readonly Brush barrierColor = new SolidBrush(Color.Black);
/// <summary> /// <summary>
/// Цвет участка открытого /// Цвет участка открытого
/// </summary> /// </summary>
@ -27,22 +28,52 @@ namespace AirFighter
} }
protected override void GenerateMap() protected override void GenerateMap()
{ {
_map = new int[10, 10] { _map = new int[100, 100];
{ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 },
{ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
};
_size_x = (float)_width / _map.GetLength(0); _size_x = (float)_width / _map.GetLength(0);
_size_y = (float)_height / _map.GetLength(1); _size_y = (float)_height / _map.GetLength(1);
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 < 20; ++i)
{
int x = _random.Next(0, 100);
int y = _random.Next(0, 100);
GenerateMap(x, y, _random.Next(13, 23));
}
} }
private void GenerateMap(int x, int y, int depth)
{
if (depth <= 0) return;
bool check = false;
while (!check)
{
int deltaX = _random.Next(-1, 2);
int deltaY = _random.Next(-1, 2);
if (x + deltaX < 0 || x + deltaX >= 100) continue;
if (y + deltaY < 0 || y + deltaY >= 100) continue;
if (_map[y + deltaY, x + deltaX] == _barrier) depth--;
x += deltaX;
y += deltaY;
_map[y, x] = _barrier;
check = true;
}
GenerateMap(x, y, depth - 1);
}
} }
} }