diff --git a/Models/Game.cs b/Models/Game.cs index abbb891..2a1483f 100644 --- a/Models/Game.cs +++ b/Models/Game.cs @@ -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; diff --git a/Models/Grid.cs b/Models/Grid.cs index 4119fce..6547716 100644 --- a/Models/Grid.cs +++ b/Models/Grid.cs @@ -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,15 +38,29 @@ 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; for (uint x = 0; x < shape.GetLength(0); x++) - for (uint y = 0; y < shape.GetLength(1); y++) { - Point s = t.Coordinates + new Size((int) x, (int) y); - if (shape[x, y]) - _grid[s.X, s.Y] = t.Color; - } + for (uint y = 0; y < shape.GetLength(1); y++) { + Point s = t.Coordinates + new Size((int) x, (int) y); + if (shape[x, y]) + _grid[s.X, s.Y] = t.Color; + } } public override string ToString() {