This repository has been archived on 2026-07-13. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
servicepoint-tanks/TanksServer/Graphics/GamePixelGrid.cs
2024-04-15 20:34:23 +02:00

47 lines
1.1 KiB
C#

using System.Collections;
using System.Diagnostics;
namespace TanksServer.Graphics;
internal sealed class GamePixelGrid : IEnumerable<GamePixel>
{
public int Width { get; }
public int Height { get; }
private readonly GamePixel[,] _pixels;
public GamePixelGrid(int width, int height)
{
Width = width;
Height = height;
_pixels = new GamePixel[height, width];
for (var row = 0; row < height; row++)
for (var column = 0; column < width; column++)
_pixels[row, column] = new GamePixel();
}
public GamePixel this[int x, int y]
{
get
{
Debug.Assert(y * Width + x < _pixels.Length);
return _pixels[y, x];
}
}
public void Clear()
{
foreach (var pixel in _pixels)
pixel.Clear();
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
public IEnumerator<GamePixel> GetEnumerator()
{
for (var row = 0; row < Height; row++)
for (var column = 0; column < Width; column++)
yield return _pixels[row, column];
}
}