private void PostDropColumns() //happens after drop animation { //dispose every pointlabel and remake the list foreach (Label PointLabel in PointLabelList) { PointLabel.Dispose(); } PointLabelList = new List <Label>(); Random r = new Random(); List <Point> MovedTilesToCheck = new List <Point>(); //tiles to check for new matches foreach (int Col in ColumnsToDrop) { int EmptySpacesInColumn = 0; //reset the location of each tile in the columns and count number of empty spaces for (int Row = 0; Row < 9; Row++) { mBoard.Tiles[Row, Col].Location = new Point(BoardOffset + Col * TileSize, BoardOffset + Row * TileSize); if (IntArray[Row, Col] == 0) { EmptySpacesInColumn++; } } //iterating from bottom to top for (int Row = 8; Row >= 0; Row--) { if (Row >= EmptySpacesInColumn) //for each row in the column, except for the ones that will be empty spaces at the top { if (IntArray[Row, Col] == 0) //if it is blank: find the closest valid value above it, copy that value down, and turn the original value to 0 to represent how the tile moved down { for (int UpperRow = Row - 1; UpperRow >= 0; UpperRow--) { if (IntArray[UpperRow, Col] != 0) { IntArray[Row, Col] = IntArray[UpperRow, Col]; IntArray[UpperRow, Col] = 0; //update its image and check it for a match later mBoard.SetNewImage(Row, Col); MovedTilesToCheck.Add(new Point(Col, Row)); break; } } } } else { //for each empty space in the column, which would have bubbled to the top, assign it a new random value and check it for a match later IntArray[Row, Col] = r.Next(1, 7); MovedTilesToCheck.Add(new Point(Col, Row)); mBoard.SetNewImage(Row, Col); } } } CheckNewTiles(MovedTilesToCheck); }
private void PostDropColumns() //после анимации падения { foreach (Label PointLabel in PointLabelList) { PointLabel.Dispose(); } PointLabelList = new List <Label>(); Random r = new Random(); List <Point> MovedTilesToCheck = new List <Point>(); foreach (int Col in ColumnsToDrop) { int EmptySpacesInColumn = 0; for (int Row = 0; Row < 8; Row++) { mBoard.Tiles[Row, Col].Location = new Point(BoardOffset + Col * TileSize, BoardOffset + Row * TileSize); if (IntArray[Row, Col] == 0) { EmptySpacesInColumn++; } } for (int Row = 7; Row >= 0; Row--) { if (Row >= EmptySpacesInColumn) { if (IntArray[Row, Col] == 0) { for (int UpperRow = Row - 1; UpperRow >= 0; UpperRow--) { if (IntArray[UpperRow, Col] != 0) { IntArray[Row, Col] = IntArray[UpperRow, Col]; IntArray[UpperRow, Col] = 0; mBoard.SetNewImage(Row, Col); MovedTilesToCheck.Add(new Point(Col, Row)); break; } } } } else { IntArray[Row, Col] = r.Next(1, 6); MovedTilesToCheck.Add(new Point(Col, Row)); mBoard.SetNewImage(Row, Col); } } } CheckNewTiles(MovedTilesToCheck); }