Build Tetrominoe from parser and support print of grid with current Tetrominoe
This commit is contained in:
parent
3f03709cea
commit
e49cfb2c78
2 changed files with 23 additions and 16 deletions
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Media;
|
||||
using Pastel;
|
||||
using Color = System.Drawing.Color;
|
||||
|
||||
|
@ -8,6 +9,8 @@ namespace Tetris.Models;
|
|||
public class Grid {
|
||||
private Color[,] _grid;
|
||||
|
||||
public Color[,] CGrid => (Color[,])_grid.Clone();
|
||||
|
||||
public Point MinGrid => new Point(0,0);
|
||||
public Point MaxGrid => new Point(_grid.GetLength(0)-1, _grid.GetLength(1)-1);
|
||||
|
||||
|
@ -33,6 +36,17 @@ public class Grid {
|
|||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
String s = "";
|
||||
for (uint y = 0; y < _grid.GetLength(1); y++) {
|
||||
|
@ -45,16 +59,8 @@ public class Grid {
|
|||
}
|
||||
|
||||
public string ToString(Tetrominoe t) {
|
||||
Color[,] grid = (Color[,]) _grid.Clone();
|
||||
Boolean[,] 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;
|
||||
}
|
||||
|
||||
return new Grid(grid).ToString();
|
||||
Grid g = new((Color[,]) _grid.Clone());
|
||||
g.PrintTetrominoe(t);
|
||||
return g.ToString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,12 +70,13 @@ public class Tetrominoe {
|
|||
// ToDO: ascpect technique test
|
||||
}
|
||||
|
||||
public Tetrominoe(Grid grid, String shape, Point coordinates, short orientation, Color color) {
|
||||
public Tetrominoe(Grid grid, String name) {
|
||||
_grid = grid;
|
||||
_shape = TetrominoeParser.Get(shape);
|
||||
_coordinates = coordinates;
|
||||
_orientation = orientation;
|
||||
_color = color;
|
||||
_shape = TetrominoeParser.GetShape(name);
|
||||
_coordinates = new Point(Convert.ToInt32(Math.Floor(_grid.CGrid.GetLength(0) / 2.0) - Math.Floor(_shape.GetLength(0) / 2.0)), 0);
|
||||
// ToDo fixme, not rounded to left
|
||||
_orientation = 0;
|
||||
_color = TetrominoeParser.GetColor(name);
|
||||
}
|
||||
|
||||
private bool[,] _rotateLeft(bool[,] shape) {
|
||||
|
|
Reference in a new issue