using System; using System.ComponentModel; using System.Drawing; using Pastel; namespace Tetris.Models; public class Tetrominoe { public event PropertyChangedEventHandler PropertyChanged; private Grid _grid; private bool[,] _shape; public bool[,] Shape { get { bool[,] shape = (bool[,]) _shape.Clone(); for (int i = 0; i < _orientation; i++) shape = _rotateLeft(shape); return shape; } } private Point _coordinates; public Point Coordinates { get => _coordinates; set { if (! _grid.CanGo(this, value)) return; _coordinates = value; OnPropertyChanged("Coordinates"); } } private short _orientation = 0; public short Orientation { get => _orientation; set { if (value > 3) value = 0; else if (value < 0) value = 3; short oldOrientation = _orientation; _orientation = value; Point newCoords = _coordinates; //ToDo: move position when hit a wall if (!_grid.CanGo(this, newCoords)) { _orientation = oldOrientation; } else { OnPropertyChanged("Orientation"); } } } private Color _color; public Color Color { get => _color; } public Tetrominoe(Grid grid, bool[,] shape, Point coordinates, short orientation, Color color) { _grid = grid; _shape = shape; _coordinates = coordinates; _orientation = orientation; _color = color; // ToDo: UML: Sequand, classe, déploiement // ToDo: pb techniques // ToDO: ascpect technique test } public Tetrominoe(Grid grid, String name) { _grid = grid; _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) { bool[,] rotatedArr = new bool[shape.GetLength(1), shape.GetLength(0)]; for (int i=shape.GetLength(0)-1;i>=0;--i) for (int j=0;j