Add grid line full, clear line and game hit top functions
This commit is contained in:
parent
ba5b820159
commit
917806d0bd
2 changed files with 39 additions and 6 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Reference in a new issue