Fixed reset bug for block clearing.
This commit is contained in:
parent
889e31a2b6
commit
4298dfceb2
BIN
Meteo_Engine.jar
BIN
Meteo_Engine.jar
Binary file not shown.
@ -16,7 +16,7 @@ public class Block{
|
|||||||
public Block(int x,int y) {
|
public Block(int x,int y) {
|
||||||
this.x=x;
|
this.x=x;
|
||||||
this.y=y;
|
this.y=y;
|
||||||
state = STARTINGSTATES[(int)(Math.random()*1)];
|
state = STARTINGSTATES[(int)(Meteo.r.nextInt(1))];
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -43,8 +43,9 @@ public class BlockClump {
|
|||||||
public void addBlock(Block...blocks) {
|
public void addBlock(Block...blocks) {
|
||||||
//Adds the block to the strucutre. Update collision column ranges to reflect the new bounds.
|
//Adds the block to the strucutre. Update collision column ranges to reflect the new bounds.
|
||||||
for (Block b : blocks)
|
for (Block b : blocks)
|
||||||
{updateBlockCollisionRangeWithBlock(b);
|
{
|
||||||
this.blocks.add(b);
|
this.blocks.add(b);
|
||||||
|
updateBlockCollisionRangeWithBlock(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void removeBlock(Block...blocks) {
|
public void removeBlock(Block...blocks) {
|
||||||
|
@ -38,9 +38,9 @@ public class Board {
|
|||||||
this.combo_power_bonus = combo_power_bonus;
|
this.combo_power_bonus = combo_power_bonus;
|
||||||
this.blockData = new ArrayList<BlockClump>();
|
this.blockData = new ArrayList<BlockClump>();
|
||||||
|
|
||||||
List<Block> initialBlocks = new ArrayList<Block>();
|
/*List<Block> initialBlocks = new ArrayList<Block>();
|
||||||
for (int x=0;x<boardWidth;x++) {
|
for (int x=0;x<boardWidth;x++) {
|
||||||
for (int y=0;y<(int)(Math.random()*12);y++) {
|
for (int y=0;y<(int)(Meteo.r.nextInt(12));y++) {
|
||||||
initialBlocks.add(new Block(x,y));
|
initialBlocks.add(new Block(x,y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,18 +49,18 @@ public class Board {
|
|||||||
|
|
||||||
List<Block> initialBlocks2 = new ArrayList<Block>();
|
List<Block> initialBlocks2 = new ArrayList<Block>();
|
||||||
for (int x=0;x<boardWidth;x++) {
|
for (int x=0;x<boardWidth;x++) {
|
||||||
for (int y=0;y<(int)(Math.random()*12);y++) {
|
for (int y=0;y<(int)(Meteo.r.nextInt(12));y++) {
|
||||||
initialBlocks2.add(new Block(x,y));
|
initialBlocks2.add(new Block(x,y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BlockClump defaultClump2 = new BlockClump(initialBlocks2,0,540,0,width,120);
|
BlockClump defaultClump2 = new BlockClump(initialBlocks2,0,540,0,width,120);
|
||||||
|
|
||||||
blockData.add(defaultClump);
|
blockData.add(defaultClump);
|
||||||
blockData.add(defaultClump2);
|
blockData.add(defaultClump2);*/
|
||||||
}
|
}
|
||||||
public void run(long frames) {
|
public void run(long frames) {
|
||||||
if (frames%40==0) {
|
if (frames%20==0) {
|
||||||
blockData.add(new BlockClump(Arrays.asList(new Block((int)(Math.random()*width),0)),0,590,0,width,-1));
|
blockData.add(new BlockClump(Arrays.asList(new Block((int)(Meteo.r.nextInt(width)),0)),0,590,0,width,-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
outerloop:
|
outerloop:
|
||||||
@ -127,11 +127,12 @@ public class Board {
|
|||||||
//System.out.println(blocks.getSortedBlocksOnRow(y));
|
//System.out.println(blocks.getSortedBlocksOnRow(y));
|
||||||
//System.out.println(blocks.getSortedBlocksOnRow(y));
|
//System.out.println(blocks.getSortedBlocksOnRow(y));
|
||||||
List<Block> blockList = blocks.getSortedBlocksOnRow(y);
|
List<Block> blockList = blocks.getSortedBlocksOnRow(y);
|
||||||
markedBlocks.addAll(FindMatches(blockList,width,true));
|
System.out.println(" "+blockList);
|
||||||
|
markedBlocks.addAll(FindMatches(blockList));
|
||||||
}
|
}
|
||||||
for (int x=0;x<width;x++) {
|
for (int x=0;x<width;x++) {
|
||||||
List<Block> blockList = blocks.getSortedBlocksOnCol(x);
|
List<Block> blockList = blocks.getSortedBlocksOnCol(x);
|
||||||
markedBlocks.addAll(FindMatches(blockList,blocks.maxBlockHeight,false));
|
markedBlocks.addAll(FindMatches(blockList));
|
||||||
}
|
}
|
||||||
if (markedBlocks.size()>0) {
|
if (markedBlocks.size()>0) {
|
||||||
List<Block> newClumpBlocks = new ArrayList<Block>();
|
List<Block> newClumpBlocks = new ArrayList<Block>();
|
||||||
@ -146,22 +147,23 @@ public class Board {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
private List<Block> FindMatches(List<Block> blockList, int maxSearch, boolean searchingRows) {
|
private List<Block> FindMatches(List<Block> blockList) {
|
||||||
BlockState col = BlockState.IGNITED;
|
|
||||||
int matches=0;
|
|
||||||
List<Block> markedBlocks = new ArrayList<Block>();
|
List<Block> markedBlocks = new ArrayList<Block>();
|
||||||
List<Block> tempMarkedBlocks = new ArrayList<Block>();
|
List<Block> tempMarkedBlocks = new ArrayList<Block>();
|
||||||
for (int i=0;i<maxSearch;i++) {
|
if (blockList.size()==0) {return markedBlocks;}
|
||||||
if (blockList.isEmpty()) {break;}
|
BlockState col = blockList.get(0).state;
|
||||||
|
int matches= 1;
|
||||||
|
int prevX = blockList.get(0).x;
|
||||||
|
int prevY = blockList.get(0).y;
|
||||||
|
while (blockList.size()>0) {
|
||||||
Block currentBlock = blockList.get(0);
|
Block currentBlock = blockList.get(0);
|
||||||
if (searchingRows&¤tBlock.x==i||(!searchingRows&¤tBlock.y==i)) {
|
if (Math.abs(currentBlock.x-prevX)==1||Math.abs(currentBlock.y-prevY)==1) {
|
||||||
if (col!=BlockState.IGNITED&¤tBlock.state==col) {
|
if (col!=BlockState.IGNITED&¤tBlock.state==col) {
|
||||||
matches++;
|
matches++;
|
||||||
tempMarkedBlocks.add(blockList.remove(0));
|
tempMarkedBlocks.add(blockList.remove(0));
|
||||||
} else {
|
} else {
|
||||||
if (matches>=3) {
|
if (matches>=3) {
|
||||||
markedBlocks.addAll(tempMarkedBlocks);
|
markedBlocks.addAll(tempMarkedBlocks);
|
||||||
System.out.println(" Added to Marked blocks: "+tempMarkedBlocks);
|
|
||||||
}
|
}
|
||||||
matches=1;
|
matches=1;
|
||||||
col=currentBlock.state;
|
col=currentBlock.state;
|
||||||
@ -169,14 +171,19 @@ public class Board {
|
|||||||
tempMarkedBlocks.add(blockList.remove(0));
|
tempMarkedBlocks.add(blockList.remove(0));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
col = BlockState.IGNITED;
|
if (matches>=3) {
|
||||||
matches=0;
|
markedBlocks.addAll(tempMarkedBlocks);
|
||||||
tempMarkedBlocks.clear();
|
|
||||||
}
|
}
|
||||||
|
matches=1;
|
||||||
|
col=currentBlock.state;
|
||||||
|
tempMarkedBlocks.clear();
|
||||||
|
tempMarkedBlocks.add(blockList.remove(0));
|
||||||
|
}
|
||||||
|
prevX=currentBlock.x;
|
||||||
|
prevY=currentBlock.y;
|
||||||
}
|
}
|
||||||
if (matches>=3) {
|
if (matches>=3) {
|
||||||
markedBlocks.addAll(tempMarkedBlocks);
|
markedBlocks.addAll(tempMarkedBlocks);
|
||||||
System.out.println(" Added to Marked blocks: "+tempMarkedBlocks);
|
|
||||||
}
|
}
|
||||||
return markedBlocks;
|
return markedBlocks;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package sig;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
|
||||||
@ -13,6 +14,7 @@ public class Meteo {
|
|||||||
public static double GAMELOOPTIME=0;
|
public static double GAMELOOPTIME=0;
|
||||||
public static JFrame f;
|
public static JFrame f;
|
||||||
public static Board b;
|
public static Board b;
|
||||||
|
public static Random r;
|
||||||
|
|
||||||
public final static long TIMEPERTICK = 16666667l;
|
public final static long TIMEPERTICK = 16666667l;
|
||||||
public static DebugMode DEBUG_DRAWING = DebugMode.MODE2;
|
public static DebugMode DEBUG_DRAWING = DebugMode.MODE2;
|
||||||
@ -23,6 +25,7 @@ public class Meteo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
r = new Random(437210983125739812l);
|
||||||
double[] val = {0,0,};
|
double[] val = {0,0,};
|
||||||
b = new Board(SCREEN_WIDTH/2,SCREEN_HEIGHT/2,24,24,8,14,-0.065,1,4,-2,val);
|
b = new Board(SCREEN_WIDTH/2,SCREEN_HEIGHT/2,24,24,8,14,-0.065,1,4,-2,val);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user