ПИ-21: практические примеры
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.

65 lines
1.4 KiB

3 years ago
namespace ConsoleDisplay.Driver.Virtual
3 years ago
{
3 years ago
public class VirtualDisplay : IDisplay
3 years ago
{
private List<VirtualBulb> BulbList;
public VirtualDisplay(int iWidth, int iHeight)
{
3 years ago
Width = iWidth;
Height = iHeight;
3 years ago
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;
}
}
}