45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
|
using System;
|
|||
|
using System.Drawing;
|
|||
|
using Color = System.Drawing.Color;
|
|||
|
|
|||
|
namespace Tetris.Models;
|
|||
|
|
|||
|
public class Grid {
|
|||
|
private Color[,] _grid;
|
|||
|
|
|||
|
public Point MinGrid => new Point(0,0);
|
|||
|
public Point MaxGrid => new Point(_grid.GetLength(0)-1, _grid.GetLength(1)-1);
|
|||
|
|
|||
|
public Grid(Color[,] grid) {
|
|||
|
_grid = grid;
|
|||
|
}
|
|||
|
|
|||
|
public bool CanGo(Tetrominoe tetrominoe, Point point) {
|
|||
|
bool[,] shape = tetrominoe.Shape;
|
|||
|
if (point.X < MinGrid.X || point.Y < MinGrid.Y)
|
|||
|
return false;
|
|||
|
|
|||
|
else if ((point.X + tetrominoe.Shape.GetLength(0)) > MaxGrid.X || (point.Y + tetrominoe.Shape.GetLength(1)) > MaxGrid.Y)
|
|||
|
return false;
|
|||
|
|
|||
|
for (uint x = 0; x < shape.GetLength(0); x++)
|
|||
|
for (uint y = 0; y < shape.GetLength(1); y++) {
|
|||
|
Point s = point + new Size((int) x, (int) y);
|
|||
|
if (shape[x, y] && _grid[s.X, s.Y] != Color.Empty)
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public override string ToString() {
|
|||
|
String s = "";
|
|||
|
for (uint y = 0; y < _grid.GetLength(1); y++) {
|
|||
|
for (uint x = 0; x < _grid.GetLength(0); x++)
|
|||
|
s += _grid[x,y].Name + "\t";
|
|||
|
s += "\n";
|
|||
|
}
|
|||
|
return s;
|
|||
|
}
|
|||
|
}
|