Archived
1
0
Fork 0

Build Tetrominoe from parser and support print of grid with current Tetrominoe

This commit is contained in:
Ethanell 2022-05-04 10:15:16 +02:00
parent 3f03709cea
commit e49cfb2c78
2 changed files with 23 additions and 16 deletions

View file

@ -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);
@ -32,6 +35,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 = "";
@ -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();
}
}

View file

@ -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) {