Добавлены новые карты

This commit is contained in:
ker73rus 2022-11-01 03:30:37 +04:00
parent 987d1fafa8
commit 8c5bb5b4a4
5 changed files with 141 additions and 9 deletions

View File

@ -0,0 +1,61 @@
using Cars;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
internal class CloudMap: AbstractMap
{
private readonly Brush barrierColor = new SolidBrush(Color.Gray);
/// <summary>
/// Цвет участка открытого
/// </summary>
private readonly Brush roadColor = new SolidBrush(Color.White);
protected override void DrawBarrierPart(Graphics g, int i, int j)
{
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, (i + 1) * _size_x, (j + 1) * _size_y);
}
protected override void DrawRoadPart(Graphics g, int i, int j)
{
g.FillRectangle(roadColor, i * _size_x, j * _size_y, (i + 1) * _size_x, (j + 1) * _size_y);
}
protected override void GenerateMap()
{
_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 c = _random.Next(1, 5); c > 0; c--)
{
int i = _random.Next(0, 100);
int j = _random.Next(0, 100);
int wight = _random.Next(0, Math.Min(100 - j, j));
int height = _random.Next(0, Math.Min(100 - i,i));
for (int k = 0; k <= wight; k++, height--)
{
for(int l = 0; l <= height; l++)
{
_map[i + l, j + k] = _barrier;
_map[i -l, j - k] = _barrier;
_map[i - l, j + k] = _barrier;
_map[i + l, j - k] = _barrier;
}
}
}
}
}
}

View File

@ -0,0 +1,52 @@
using Cars;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Stormtrooper
{
internal class DangerMap : AbstractMap
{
private readonly Brush barrierColor = new SolidBrush(Color.Red);
/// <summary>
/// Цвет участка открытого
/// </summary>
private readonly Brush roadColor = new SolidBrush(Color.Black);
protected override void DrawBarrierPart(Graphics g, int i, int j)
{
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, (i + 1) * _size_x, (j + 1) * _size_y);
}
protected override void DrawRoadPart(Graphics g, int i, int j)
{
g.FillRectangle(roadColor, i * _size_x, j * _size_y, (i + 1) * _size_x, (j + 1) * _size_y);
}
protected override void GenerateMap()
{
_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 c = _random.Next(1, 10); c > 0; c--)
{
int i = _random.Next(0, 100);
int maxj = _random.Next(30, 70);
for (int j = 0; j < maxj; j++)
{
_map[i, j] = _barrier;
}
}
}
}
}

View File

@ -130,6 +130,25 @@ namespace Stormtrooper
g.DrawRectangle(pen, _startPosX + _airplaneWidth * 0.1f, _startPosY + _airplaneHeight * 0.45f, _airplaneWidth * 0.9f, _airplaneHeight * 0.1f); g.DrawRectangle(pen, _startPosX + _airplaneWidth * 0.1f, _startPosY + _airplaneHeight * 0.45f, _airplaneWidth * 0.9f, _airplaneHeight * 0.1f);
} }
public void ChangeBorders(int width, int height)
{
_pictureWidth = width;
_pictureHeight = height;
if (_pictureWidth <= _airplaneWidth || _pictureHeight <= _airplaneHeight)
{
_pictureWidth = null;
_pictureHeight = null;
return;
}
if (_startPosX + _airplaneWidth > _pictureWidth)
{
_startPosX = _pictureWidth.Value - _airplaneWidth;
}
if (_startPosY + _airplaneHeight > _pictureHeight)
{
_startPosY = _pictureHeight.Value - _airplaneHeight;
}
}
public (float Left, float Top, float Right, float Bottom) GetCurrentPosition() public (float Left, float Top, float Right, float Bottom) GetCurrentPosition()
{ {

View File

@ -161,7 +161,9 @@ namespace Stormtrooper
// //
this.comboBoxMapSelector.FormattingEnabled = true; this.comboBoxMapSelector.FormattingEnabled = true;
this.comboBoxMapSelector.Items.AddRange(new object[] { this.comboBoxMapSelector.Items.AddRange(new object[] {
"Простая карта"}); "Простая карта",
"Опасная карта",
"Облачная карта"});
this.comboBoxMapSelector.Location = new System.Drawing.Point(31, 27); this.comboBoxMapSelector.Location = new System.Drawing.Point(31, 27);
this.comboBoxMapSelector.Name = "comboBoxMapSelector"; this.comboBoxMapSelector.Name = "comboBoxMapSelector";
this.comboBoxMapSelector.Size = new System.Drawing.Size(117, 23); this.comboBoxMapSelector.Size = new System.Drawing.Size(117, 23);

View File

@ -20,20 +20,12 @@ namespace Stormtrooper
InitializeComponent(); InitializeComponent();
_abstractMap = new SimpleMap(); _abstractMap = new SimpleMap();
} }
private void Draw()
{
Bitmap bmp = new Bitmap (pictureBoxAirplane.Width, pictureBoxAirplane.Height);
Graphics gr = Graphics.FromImage(bmp);
_airplane?.DrawAirplane(gr);
pictureBoxAirplane.Image = bmp;
}
private void buttonCreate_Click(object sender, EventArgs e) private void buttonCreate_Click(object sender, EventArgs e)
{ {
Random random = new Random(); Random random = new Random();
_airplane = new DrawningMilitaryAirplane(10, 50); _airplane = new DrawningMilitaryAirplane(10, 50);
_airplane.SetPosition(random.Next(100,150), random.Next(100,150), pictureBoxAirplane.Width, pictureBoxAirplane.Height); _airplane.SetPosition(random.Next(100,150), random.Next(100,150), pictureBoxAirplane.Width, pictureBoxAirplane.Height);
SetData(); SetData();
Draw();
} }
private void buttonMove_Click(object sender,EventArgs e) private void buttonMove_Click(object sender,EventArgs e)
@ -85,6 +77,12 @@ namespace Stormtrooper
case "Простая карта": case "Простая карта":
_abstractMap = new SimpleMap(); _abstractMap = new SimpleMap();
break; break;
case "Опасная карта":
_abstractMap = new DangerMap();
break;
case "Облачная карта":
_abstractMap = new CloudMap();
break;
} }
} }
} }