You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.4 KiB
64 lines
1.4 KiB
namespace ConsoleDisplay.Driver.Virtual
|
|
{
|
|
public class VirtualDisplay : IDisplay
|
|
{
|
|
private List<VirtualBulb> BulbList;
|
|
|
|
public VirtualDisplay(int iWidth, int iHeight)
|
|
{
|
|
Width = iWidth;
|
|
Height = iHeight;
|
|
|
|
BulbList = new List<VirtualBulb>();
|
|
h_Init(iWidth, iHeight);
|
|
IsEnabled = true;
|
|
}
|
|
|
|
|
|
private void h_Init(int width, int height)
|
|
{
|
|
for (int ii = 0; ii < width; ii++) {
|
|
for (int jj = 0; jj < height; jj++) {
|
|
BulbList.Add(new VirtualBulb(ii, jj));
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public int Width { get; }
|
|
public int Height { get; }
|
|
public bool IsEnabled { get; }
|
|
public void Reset()
|
|
{
|
|
for (int jj = 0; jj < BulbList.Count; jj++) {
|
|
BulbList[jj].IsEnabled = false;
|
|
}
|
|
}
|
|
|
|
public void Set(int iX, int iY, bool bState)
|
|
{
|
|
VirtualBulb vb = h_GetBulb(iX, iY);
|
|
if (vb == null) return;
|
|
vb.IsEnabled = bState;
|
|
}
|
|
|
|
private VirtualBulb h_GetBulb(int iX, int iY)
|
|
{
|
|
for (int jj = 0; jj < BulbList.Count; jj++) {
|
|
if (BulbList[jj].X == iX && BulbList[jj].Y == iY) {
|
|
return BulbList[jj];
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public bool Get(int iX, int iY)
|
|
{
|
|
VirtualBulb vb = h_GetBulb(iX, iY);
|
|
if (vb == null) return false;
|
|
return vb.IsEnabled;
|
|
}
|
|
}
|
|
}
|
|
|