public bool CollisionDetect(int x, int y, Tetris piece) { bool _returnValue = false; //Check bounds if (y > _columns || x > _rows || y < 0 || x < 0) { _returnValue = true; } //check can drop _returnValue = !CanDrop(x, y, piece); if (_returnValue) { for (int yi = 0; yi <= 3; yi++) { for (int xi = 0; xi <= 3; xi++) { if (piece.Piece[xi + yi * 4]) { _lines[y + yi][x + xi] = (byte)piece.Character; } } } } //check completed rows int _completedRows = 0; for (int i = 0; i < _lines.Count; i++) { if (FullRow(_lines[i])) { _completedRows++; _lines.RemoveAt(i); } } if (_completedRows > 0 && CountScore != null) { CountScore(_completedRows); } //Add new empty rows to the top of the screen for (int i = 0; i < _lines.Count - _rows; i++) { _lines.Insert(0, NewLine()); } return(_returnValue); }
public bool CanRight(int x, int y, Tetris piece) { if (x >= _columns) { return(false); } int yp, xp; int _rightMost = _columns; for (int xi = 0; xi <= 3; xi++) { for (int yi = 0; yi <= 3; yi++) { yp = y + yi; xp = x + xi - 1; if (piece.Piece[xi + yi * 4]) { if (x > _rightMost) { _rightMost = x; } if (_lines[yp][xp] != 0xff) { return(false); } } } } if (_rightMost - x >= _columns) { return(false); } return(true); }
public bool CanLeft(int x, int y, Tetris piece) { if (x <= 0) { return(false); } int yp, xp; int _leftMost = _columns; for (int xi = 0; xi <= 3; xi++) { for (int yi = 0; yi <= 3; yi++) { yp = y + yi; xp = x + xi; if (piece.Piece[xi + yi * 4]) { if (x < _leftMost) { _leftMost = x; } if (_lines[yp][xp] != 0xff) { return(false); } } } } if (_leftMost + x < 0) { return(false); } return(true); }