public void SendToField(Point pt, WindowRect wrBlockAdj) { // This function sends the block data to field. int blockIndex; int fieldIndex; for (int row = 0; row < wrBlockAdj.height; row++) { for (int col = 0; col < wrBlockAdj.width; col++) { blockIndex = (wrBlockAdj.left + col) + (wrBlockAdj.top + row) * Block.Size; fieldIndex = (pt.x - TetrisField.left + col) + (pt.y - TetrisField.top + row) * TetrisField.width; if (arrBlock[blockIndex]) { arrField[fieldIndex] = new StructBlockStyle(Block.Color(Block.Type), true); } } } ProcessRows(); }
public void ProcessRows() { // This function check to see if rows were completed. int w = TetrisField.width; int h = TetrisField.height; int rowCounter = h - 1; int rowTotal = 0; bool isFullLine = true; // Store rows that are not completed. StructBlockStyle[] arrData = new StructBlockStyle[TetrisField.width * TetrisField.height]; for (int row = h - 1; row >= 0; row--) { for (int col = w - 1; (col >= 0) && isFullLine; col--) { if (!((StructBlockStyle)arrField[col + row * w]).isBlock) { isFullLine = false; } } if (!isFullLine) { // copy the row for (int col = w - 1; col >= 0; col--) { arrData[col + rowCounter * w] = arrField[col + row * w]; } rowCounter--; isFullLine = true; } else { // Do not include rows that are completed. rowTotal++; } } // get all the rows that are not completed. arrField = arrData; EventArgs e = new EventArgs(rowTotal); RaiseEvent((object)this, e); }
public void BuildField() { arrField = new StructBlockStyle[TetrisField.width * TetrisField.height]; }