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;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Windows.Media;
|
||||||
using Pastel;
|
using Pastel;
|
||||||
using Color = System.Drawing.Color;
|
using Color = System.Drawing.Color;
|
||||||
|
|
||||||
|
@ -8,6 +9,8 @@ namespace Tetris.Models;
|
||||||
public class Grid {
|
public class Grid {
|
||||||
private Color[,] _grid;
|
private Color[,] _grid;
|
||||||
|
|
||||||
|
public Color[,] CGrid => (Color[,])_grid.Clone();
|
||||||
|
|
||||||
public Point MinGrid => new Point(0,0);
|
public Point MinGrid => new Point(0,0);
|
||||||
public Point MaxGrid => new Point(_grid.GetLength(0)-1, _grid.GetLength(1)-1);
|
public Point MaxGrid => new Point(_grid.GetLength(0)-1, _grid.GetLength(1)-1);
|
||||||
|
|
||||||
|
@ -32,6 +35,17 @@ public class Grid {
|
||||||
|
|
||||||
return true;
|
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() {
|
public override string ToString() {
|
||||||
String s = "";
|
String s = "";
|
||||||
|
@ -45,16 +59,8 @@ public class Grid {
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ToString(Tetrominoe t) {
|
public string ToString(Tetrominoe t) {
|
||||||
Color[,] grid = (Color[,]) _grid.Clone();
|
Grid g = new((Color[,]) _grid.Clone());
|
||||||
Boolean[,] shape = t.Shape;
|
g.PrintTetrominoe(t);
|
||||||
|
return g.ToString();
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,12 +70,13 @@ public class Tetrominoe {
|
||||||
// ToDO: ascpect technique test
|
// ToDO: ascpect technique test
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tetrominoe(Grid grid, String shape, Point coordinates, short orientation, Color color) {
|
public Tetrominoe(Grid grid, String name) {
|
||||||
_grid = grid;
|
_grid = grid;
|
||||||
_shape = TetrominoeParser.Get(shape);
|
_shape = TetrominoeParser.GetShape(name);
|
||||||
_coordinates = coordinates;
|
_coordinates = new Point(Convert.ToInt32(Math.Floor(_grid.CGrid.GetLength(0) / 2.0) - Math.Floor(_shape.GetLength(0) / 2.0)), 0);
|
||||||
_orientation = orientation;
|
// ToDo fixme, not rounded to left
|
||||||
_color = color;
|
_orientation = 0;
|
||||||
|
_color = TetrominoeParser.GetColor(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool[,] _rotateLeft(bool[,] shape) {
|
private bool[,] _rotateLeft(bool[,] shape) {
|
||||||
|
|
Reference in a new issue