-
Notifications
You must be signed in to change notification settings - Fork 0
/
Renderer.cs
55 lines (48 loc) · 1.78 KB
/
Renderer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System.Collections.Generic;
using System.Threading;
using Woopec.Core;
namespace GameOfLife
{
internal class Renderer : IRenderer
{
private readonly Figure[,] _cells;
public Renderer(int rowCount, int columnCount, int cellSize)
{
Shape shape = CreateCellShape(cellSize);
_cells = CreateAllCells(rowCount, columnCount, cellSize, shape);
}
public void SetCellState(CellPosition cellId, bool isVisible)
{
var figure = _cells[cellId.Row, cellId.Column];
figure.IsVisible = isVisible;
}
public void ShowState()
{
Thread.Sleep(10);
}
private static Shape CreateCellShape(int cellSize)
{
var coor = cellSize / 2.0;
var polygon = new List<Vec2D>() { (-coor, -coor), (-coor, coor), (coor, coor), (coor, -coor)};
return new Shape(polygon);
}
private static Figure[,] CreateAllCells(int rowCount, int columnCount, int cellSize, Shape shape)
{
var cells = new Figure[rowCount, columnCount];
for (int row = 0; row < rowCount; row++)
{
for (int column = 0; column < columnCount; column++)
{
cells[row, column] = CreateFigureAt(row, column, rowCount, columnCount, cellSize, shape);
}
}
return cells;
}
private static Figure CreateFigureAt(int row, int column, int rowCount, int columnCount, int cellSize, Shape shape)
{
var figure = new Figure() { Shape = shape, Color = Colors.Blue };
figure.SetPosition((column - columnCount / 2) * cellSize, (rowCount / 2 - row) * cellSize);
return figure;
}
}
}