From d9446d1c46ab3a8625fc345240c5aa7f92c6a2eb Mon Sep 17 00:00:00 2001 From: MaxKarme <91691525+MaxKarme@users.noreply.github.com> Date: Tue, 4 Oct 2022 21:48:21 +0300 Subject: [PATCH] change MyMap and rename buttons --- AirFighter/AirFighter/FormMap.Designer.cs | 4 +- AirFighter/AirFighter/MyMap.cs | 59 +++++++++++++++++------ 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/AirFighter/AirFighter/FormMap.Designer.cs b/AirFighter/AirFighter/FormMap.Designer.cs index fece72c..7337f25 100644 --- a/AirFighter/AirFighter/FormMap.Designer.cs +++ b/AirFighter/AirFighter/FormMap.Designer.cs @@ -51,7 +51,7 @@ this.CreateButton.Name = "CreateButton"; this.CreateButton.Size = new System.Drawing.Size(94, 29); this.CreateButton.TabIndex = 0; - this.CreateButton.Text = "create"; + this.CreateButton.Text = "создание"; this.CreateButton.UseVisualStyleBackColor = true; this.CreateButton.Click += new System.EventHandler(this.CreateButton_Click); // @@ -156,7 +156,7 @@ this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(148, 29); this.button1.TabIndex = 7; - this.button1.Text = "create modern"; + this.button1.Text = "модификация"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.CreateModernButton_Click); // diff --git a/AirFighter/AirFighter/MyMap.cs b/AirFighter/AirFighter/MyMap.cs index b06218d..3f50303 100644 --- a/AirFighter/AirFighter/MyMap.cs +++ b/AirFighter/AirFighter/MyMap.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -13,6 +13,7 @@ namespace AirFighter /// Цвет участка закрытого /// private readonly Brush barrierColor = new SolidBrush(Color.Black); + /// /// Цвет участка открытого /// @@ -27,22 +28,52 @@ namespace AirFighter } protected override void GenerateMap() { - _map = new int[10, 10] { - { 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 }, - }; - + _map = new int[100, 100]; _size_x = (float)_width / _map.GetLength(0); _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); + } } }