Add sorted block gets on row and col blocks

This commit is contained in:
sigonasr2, Sig, Sigo 2021-09-23 04:34:36 +00:00
parent 287d8d3912
commit 80ab9c9f23
3 changed files with 11 additions and 8 deletions

Binary file not shown.

View File

@ -2,8 +2,8 @@ package sig;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.awt.Color;
public class BlockClump {
@ -77,6 +77,12 @@ public class BlockClump {
public List<Block> getBlocks() {
return blocks;
}
public List<Block> getSortedBlocksOnRow(int row) {
return getBlocks().stream().filter((block)->block.y==row).sorted((b1,b2)->b1.x-b2.x).collect(Collectors.toList());
}
public List<Block> getSortedBlocksOnCol(int col) {
return getBlocks().stream().filter((block)->block.x==col).sorted((b1,b2)->b1.y-b2.y).collect(Collectors.toList());
}
private void updateBlockCollisionRangeWithBlock(Block b) {
if (collisionColumnRanges[b.x][0]==-1||collisionColumnRanges[b.x][0]>b.y) {
collisionColumnRanges[b.x][0]=b.y;

View File

@ -112,13 +112,10 @@ public class Board {
//Start from one block and work our way across, seeing if we can make a match of 3 or more. Go to the next row, repeat. Then do the columns. Once all blocks marked for ignition, ignite them and send them.
//Lowest block is used as the block clump starting point.
for (int y=0;y<blocks.maxBlockHeight;y++) {
for (int x=0;x<width;x++) {
final int xx=x,yy=y;
List<Block> bl = blocks.getBlocks().stream().filter((block)->block.x==xx&&block.y==yy).collect(Collectors.toList());
if (bl.size()>0) {
//System.out.println("Found a block at ("+x+","+y+")");
}
}
System.out.println(blocks.getSortedBlocksOnRow(y));
}
for (int x=0;x<width;x++) {
System.out.println(blocks.getSortedBlocksOnCol(x));
}
return false;
}