Archived
1
0
Fork 0

Merge branch 'core-game' into 'master'

Add grid line full, clear line and game hit top functions

See merge request tetris-dotnet/tetris!4
This commit is contained in:
Ethanell 2022-05-18 08:02:29 +00:00
commit 3707e05e6a
2 changed files with 39 additions and 6 deletions

View file

@ -52,6 +52,23 @@ public class Game : INotifyPropertyChanged {
return !_grid.CanGo(_currentTetrominoe, _currentTetrominoe.Coordinates + new Size(0, 1));
}
public bool HitTop() {
if (_currentTetrominoe == null)
return false;
else if (_grid.CanGo(_currentTetrominoe, _currentTetrominoe.Coordinates + new Size(0, 1)))
return false;
return _grid.MinGrid.Y == _currentTetrominoe.Coordinates.Y;
}
public bool LineFull() {
return _grid.LineFull();
}
public void ClearLine() {
_grid.ClearLine();
}
public void PrintTetrominoe() {
if (_currentTetrominoe == null)
return;

View file

@ -1,5 +1,7 @@
using System;
using System.Drawing;
using System.Linq;
using System.Windows.Documents;
using System.Windows.Media;
using Pastel;
using Color = System.Drawing.Color;
@ -9,7 +11,7 @@ namespace Tetris.Models;
public class Grid {
private Color[,] _grid;
public Color[,] CGrid => (Color[,])_grid.Clone();
public Color[,] CGrid => _grid;
public Point MinGrid => new Point(0,0);
public Point MaxGrid => new Point(_grid.GetLength(0)-1, _grid.GetLength(1)-1);
@ -36,6 +38,20 @@ public class Grid {
return true;
}
public bool LineFull() {
return Enumerable.Range(0, _grid.GetLength(0)).Select(x => _grid[x, MaxGrid.Y]).All(x => x != Color.Empty);
}
public void ClearLine() {
for (int x = 0; x <= MaxGrid.X; x++)
for (int y = MaxGrid.Y; y > 0; y--) {
_grid[x, y] = _grid[x, y - 1];
}
for (int x = 0; x <= MaxGrid.X; x++)
_grid[x,0] = Color.Empty;
}
public void PrintTetrominoe(Tetrominoe t) {
bool[,] shape = t.Shape;