Created Mine Map and ReactivePlanner
This commit is contained in:
@@ -2,16 +2,22 @@ using System;
|
||||
|
||||
namespace ConsoleApp.Maps
|
||||
{
|
||||
public enum Coverage
|
||||
{
|
||||
Uncoverd,
|
||||
Covered
|
||||
}
|
||||
public struct Cell : ICell
|
||||
{
|
||||
public int X { get; }
|
||||
public int Y { get; }
|
||||
|
||||
|
||||
public Coverage Coverage { get; set; }
|
||||
|
||||
public Cell(int x, int y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Coverage = Coverage.Uncoverd;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,5 +4,6 @@ namespace ConsoleApp.Maps
|
||||
{
|
||||
int X { get; }
|
||||
int Y { get; }
|
||||
Coverage Coverage { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,9 @@ namespace ConsoleApp.Maps
|
||||
int Height { get; }
|
||||
int Width { get; }
|
||||
int CellWidth { get; }
|
||||
void GenerateMaps(int x, int y);
|
||||
void GenerateMaps(int x, int y, double minePercentage);
|
||||
IHexMap GetHexMap();
|
||||
ISquareMap GetSquareMap();
|
||||
IMineMap GetMineMap();
|
||||
}
|
||||
}
|
||||
7
ConsoleApp/Maps/IMineMap.cs
Normal file
7
ConsoleApp/Maps/IMineMap.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace ConsoleApp.Maps
|
||||
{
|
||||
public interface IMineMap
|
||||
{
|
||||
bool[,] Map { get; }
|
||||
}
|
||||
}
|
||||
20
ConsoleApp/Maps/MapExtensions.cs
Normal file
20
ConsoleApp/Maps/MapExtensions.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
namespace ConsoleApp.Maps
|
||||
{
|
||||
public static class MapExtensions
|
||||
{
|
||||
public static void Fill2DArray<T>(this T[,] arr, T value)
|
||||
{
|
||||
int numRows = arr.GetLength(0);
|
||||
int numCols = arr.GetLength(1);
|
||||
|
||||
for (int i = 0; i < numRows; ++i)
|
||||
{
|
||||
for (int j = 0; j < numCols; ++j)
|
||||
{
|
||||
arr[i, j] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ConsoleApp.Vehicle;
|
||||
using ConsoleApp.Sim;
|
||||
|
||||
namespace ConsoleApp.Maps
|
||||
{
|
||||
@@ -17,16 +17,20 @@ namespace ConsoleApp.Maps
|
||||
private ISquareMap _squareMap;
|
||||
|
||||
private IHexMap _hexMap;
|
||||
|
||||
private IMineMap _mineMap;
|
||||
|
||||
public void GenerateMaps(int x, int y)
|
||||
public void GenerateMaps(int x, int y, double minePercentage)
|
||||
{
|
||||
Width = x;
|
||||
Height = y;
|
||||
_squareMap = new SquareMap(x, y);
|
||||
_hexMap = new HexMap(x, y);
|
||||
_mineMap = new MineMap(x, y, minePercentage);
|
||||
}
|
||||
public IHexMap GetHexMap() => _hexMap ?? throw new NullReferenceException("hex map not initialized");
|
||||
public ISquareMap GetSquareMap() => _squareMap ?? throw new NullReferenceException("square map not initialized");
|
||||
public IMineMap GetMineMap() => _mineMap ?? throw new NullReferenceException("mine map not initialized");
|
||||
|
||||
public MapFactory(IVehicle vehicle)
|
||||
{
|
||||
|
||||
33
ConsoleApp/Maps/MineMap.cs
Normal file
33
ConsoleApp/Maps/MineMap.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ConsoleApp.Maps
|
||||
{
|
||||
public class MineMap : IMineMap
|
||||
{
|
||||
private int _mineCount;
|
||||
private int _x;
|
||||
private int _y;
|
||||
public bool[,] Map { get; }
|
||||
public MineMap(int x, int y, double minePercentage)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_mineCount = x*y*((int)minePercentage/100);
|
||||
Map = new bool[x, y];
|
||||
Map.Fill2DArray(false);
|
||||
PlaceMines();
|
||||
}
|
||||
|
||||
private void PlaceMines()
|
||||
{
|
||||
var rand = new Random();
|
||||
for (int i = 0; i < _mineCount; i++)
|
||||
{
|
||||
var x = rand.Next(_x);
|
||||
var y = rand.Next(_y);
|
||||
Map[x, y] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user