LabWork02 #3
@ -49,6 +49,65 @@ namespace AircraftCarrier
|
||||
int y = _random.Next(0, 10);
|
||||
_drawingObject.SetObject(x, y, _width, _height);
|
||||
// TODO првоерка, что объект не "накладывается" на закрытые участки
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*(float left, float right, float top, float bottom) = _drawingObject.GetCurrentPosition();
|
||||
float step = _drawingObject?.Step ?? 0;
|
||||
|
||||
int searchX = 0,
|
||||
searchY = 0,
|
||||
startX = 0,
|
||||
startY = 0;
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.UP:
|
||||
searchX = (int)right;
|
||||
searchY = (int)top;
|
||||
startX = (int)left;
|
||||
startY = (int)(top - step);
|
||||
break;
|
||||
case Direction.DOWN:
|
||||
searchX = (int)right;
|
||||
searchY = (int)(bottom + step);
|
||||
startX = (int)left;
|
||||
startY = (int)bottom;
|
||||
break;
|
||||
case Direction.LEFT:
|
||||
searchX = (int)left;
|
||||
searchY = (int)bottom;
|
||||
startX = (int)(left - step);
|
||||
startY = (int)top;
|
||||
break;
|
||||
case Direction.RIGHT:
|
||||
searchX = (int)(right + step);
|
||||
searchY = (int)bottom;
|
||||
startX = (int)right;
|
||||
startY = (int)top;
|
||||
break;
|
||||
}
|
||||
|
||||
searchX = (int)(searchX / _size_x) + 1;
|
||||
searchY = (int)(searchY / _size_y) + 1;
|
||||
startX = (int)(startX / _size_x);
|
||||
startY = (int)(startY / _size_y);
|
||||
|
||||
if (searchX < 0 || searchX > _width || searchY < 0 || searchY > _height) return false;
|
||||
|
||||
for (int i = startY; i < searchY; i++)
|
||||
{
|
||||
for (int j = startX; j < searchX; j++)
|
||||
{
|
||||
if (_map[j, i] == _barrier) return false;
|
||||
}
|
||||
}
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
private Bitmap DrawMapWithObject()
|
||||
|
@ -161,7 +161,8 @@
|
||||
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(12, 12);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23);
|
||||
|
@ -95,6 +95,9 @@ namespace AircraftCarrier
|
||||
case "Простая карта":
|
||||
_abstractMap = new SimpleMap();
|
||||
break;
|
||||
case "Преграды линии":
|
||||
_abstractMap = new LineMap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
64
AircraftCarrier/AircraftCarrier/LineMap.cs
Normal file
64
AircraftCarrier/AircraftCarrier/LineMap.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AircraftCarrier
|
||||
{
|
||||
internal class LineMap : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
/// Цвет участка закрытого
|
||||
/// </summary>
|
||||
private readonly Brush barrierColor = new SolidBrush(Color.Blue);
|
||||
/// <summary>
|
||||
/// Цвет участка открытого
|
||||
/// </summary>
|
||||
private readonly Brush roadColor = new SolidBrush(Color.Gray);
|
||||
protected override void DrawBarrierPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y);
|
||||
}
|
||||
protected override void DrawRoadPart(Graphics g, int i, int j)
|
||||
{
|
||||
g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _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);
|
||||
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;
|
||||
}
|
||||
}
|
||||
bool flag = true;
|
||||
while (counter < 10)
|
||||
{
|
||||
int lineX = _random.Next(0, 100);
|
||||
int lineY = _random.Next(0, 100);
|
||||
if (flag)
|
||||
{
|
||||
for (int i = 0; i <= 10; i++)
|
||||
_map[lineX, i] = _barrier;
|
||||
flag = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i <= 10; i++)
|
||||
_map[i, lineY] = _barrier;
|
||||
flag = true;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user