117 lines
4.4 KiB
C#
117 lines
4.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Drawing;
|
|
namespace NonoGramme
|
|
{
|
|
internal class Grid
|
|
{
|
|
private readonly Color DEFAULT_FULL_COLOR = Color.Black;
|
|
private readonly Color DEFAULT_EMPTY_COLOR = Color.LightGray;
|
|
private readonly Color DEFAULT_BORDER_COLOR = Color.Pink;
|
|
private readonly Color DEFAULT_ERROR_COLOR = Color.Purple;
|
|
|
|
private Size _gridSize;
|
|
private Line[] _horizontalLines;
|
|
private Line[] _verticalLines;
|
|
|
|
public Size GridSize { get => _gridSize; set => _gridSize = value; }
|
|
internal Line[] HorizontalLines { get => _horizontalLines; set => _horizontalLines = value; }
|
|
internal Line[] VerticalLines { get => _verticalLines; set => _verticalLines = value; }
|
|
|
|
public Grid(Size size)
|
|
{
|
|
GridSize = size;
|
|
HorizontalLines = new Line[size.Height];
|
|
VerticalLines = new Line[size.Width];
|
|
Populate();
|
|
}
|
|
private void Populate()
|
|
{
|
|
Random rnd = new Random();
|
|
for (int y = 0; y < GridSize.Height; y++)
|
|
{
|
|
HorizontalLines[y] = new Line(GridSize.Width);
|
|
for (int x = 0; x < GridSize.Width; x++)
|
|
{
|
|
if (y == 0)
|
|
{
|
|
VerticalLines[x] = new Line(GridSize.Height);
|
|
}
|
|
|
|
Tile.State state;
|
|
int rndResult = rnd.Next(1, 4);
|
|
switch (rndResult)
|
|
{
|
|
case 2:
|
|
state = Tile.State.Empty;
|
|
break;
|
|
case 3:
|
|
state = Tile.State.Full;
|
|
break;
|
|
default:
|
|
state = Tile.State.Empty;
|
|
break;
|
|
}
|
|
HorizontalLines[y].Edit(x, state);
|
|
VerticalLines[x].Edit(y, state);
|
|
}
|
|
}
|
|
Console.WriteLine("Coucou");
|
|
}
|
|
public Bitmap Draw(Bitmap UI,Point offset)
|
|
{
|
|
Size actualSize = new Size(UI.Width - offset.X, UI.Height - offset.Y);
|
|
Size blocSize = new Size(actualSize.Width/GridSize.Width,actualSize.Height/GridSize.Height);
|
|
|
|
//Drawing the rows Text
|
|
|
|
//TODO
|
|
|
|
//Drawing the columns Text
|
|
|
|
//TODO
|
|
|
|
//Drawing the grid
|
|
using (Graphics g = Graphics.FromImage(UI))
|
|
{
|
|
int row = 0;
|
|
foreach (Line line in HorizontalLines)
|
|
{
|
|
int column = 0;
|
|
foreach (Tile tile in line.Data)
|
|
{
|
|
Point position = new Point((column*blocSize.Width) + offset.X,(row*blocSize.Height) + offset.Y);
|
|
switch (tile.CurrentState)
|
|
{
|
|
case Tile.State.Full:
|
|
g.FillRectangle(new SolidBrush(DEFAULT_FULL_COLOR),new Rectangle(position,blocSize));
|
|
break;
|
|
case Tile.State.Empty:
|
|
g.FillRectangle(new SolidBrush(DEFAULT_EMPTY_COLOR), new Rectangle(position, blocSize));
|
|
break;
|
|
case Tile.State.Discovered:
|
|
g.FillRectangle(new SolidBrush(DEFAULT_EMPTY_COLOR), new Rectangle(position, blocSize));
|
|
break;
|
|
case Tile.State.Undiscovered:
|
|
g.FillRectangle(new SolidBrush(DEFAULT_FULL_COLOR), new Rectangle(position, blocSize));
|
|
break;
|
|
default:
|
|
g.FillRectangle(new SolidBrush(DEFAULT_ERROR_COLOR), new Rectangle(position, blocSize));
|
|
break;
|
|
}
|
|
//We need to draw the outline AFTER the fill or it will be covered
|
|
g.DrawRectangle(new Pen(DEFAULT_BORDER_COLOR), new Rectangle(position, blocSize));
|
|
column++;
|
|
}
|
|
row++;
|
|
}
|
|
}
|
|
|
|
return UI;
|
|
}
|
|
}
|
|
}
|