I’m trying to create a match 3 & made a check function that works & tell me when there are 3 in a row. I tried giving each one a float but when I go to remove the letters assign to each i that met nothing happened. Can anyone tell me why? here the code for the block. I’m typing in java using processing.
first page
ArrayList<block> Block = new ArrayList<block>(); // making a new array
int wide = 5; // declaring the width
int hei = 5; // declaring the height
float time; // declaring time
// time is part of the falling system every time something moves I want time to go to like 5
void addBlock(){// decided to take some advise and add an add block at least for now
for (int i = 0; i < wide; i++){// here to the next lines is where I make my blocks
for (int j = 0; j < hei; j++){
float t = random(5);
t = round(t);
Block.add(new block(10 + (50*i),10 + (50*j),50,t));
}
}
}
void setup(){ // setup
size(500,500);// setting the size
addBlock();
}
void draw(){// draw
background(0);// black background
for (int i = 0; i < Block.size(); i++){ // going through blocks
block b = Block.get(i);// I forgot what this part is called getting block
b.show();// showing block
b.update(); // updating block
b.move(); // moving block
}//////////////////////////////////////////////
}
void keyPressed(){// looking at what keys are being pressed
if (key == 'r'){// checking the r key so I can reset
for (int i = Block.size()-1; i >= 0; i--){ // erasing all old blocks for my reset
Block.remove(i);
}///////////////////////////////////////////////
addBlock();
}
if (key == ' '){// checking space
for (int i = Block.size()-1; i >= 0; i--){ // running through blocks
block b = Block.get(i);// getting blocks
if (b.check == true){// checking if check = true
Block.remove(i);// removing any that equal true
}
}/////////////////
}
}
block page
class block{// making a new class
float x,y,w,type,a,d,c,e,f;// setting a bunch of floats will say why later
boolean first, second, third, fourth, check = false; // setting a bunch of booleans
boolean collide = false; // setting collide currently not working correct
block(float x, float y, float w, float type){ // making my block or whatever this is called
this.x = x;// setting the x position to the x float above
this.y = y;// setting the y position to the y above
this.w = w;// setting the width
this.type = type;// setting the type
}
void show(){// showing the block
if (type == 0){fill(255,0,0);}// setting color determined by type
if (type == 1){fill(0,255,0);}
if (type == 2){fill(0,0,255);}
if (type == 3){fill(255,0,255);}
if (type == 4){fill(255,255,0);}
if (type == 5){fill(0,255,255);}
rect(x,y,w,w);// drawing a rectangle
}
void move(){// not working yet it suppose to move them
for (int i = 0; i < Block.size(); i++){// runs through all blocks
block b = Block.get(i);// get blocks
// the idea behind this is run through them all and stop if a block is a certain height above another
}
}// move
void update(){// updating
textSize(15);
// here I check for matches
for (int i = 0; i < Block.size(); i++){// running through blocks
block b = Block.get(i);// getting blocks
if (b.type == type){// checking type
if (b.x == x && b.y == y){ // checking position
c = i; // setting c the block that is checking all the rest
}
if (b.x + w == x && b.y == y){ // checking 60 x away for a match
first = true;// turning first to true so I know which blocks found both matches
a = i; // setting a to i to save the i number
}
if (b.x + (w*2) == x && b.y == y && first == true){ // checking 120 x away I should do these by width
second = true; // checking second which means the first one been found
// I only check for 3 because with all the blocks checking 3 all matches should be gone
d = i; // setting d to i to save i
}
if (b.y + w == y && b.x == x){ //checking 60 y
third = true;// setting third to true
e = i; // setting e to i to save i
}
if (b.y + (w*2) == y && b.x == x && third == true){ // check 120 y
fourth = true; // setting fourth to true
f = i;// setting f to i
}
}
}
if (first == true && second == true){// checking to see if there 3 in a row x
for (int i = 0; i < Block.size(); i++){// running through the blocks
block b = Block.get(i);// getting blocks
if (a == i){// getting a
b.check = true;// setting the a block to true
}
if (d == i){ // getting d
b.check = true;// setting the d block to true
}
if (c == i){// getting c
b.check = true; // setting the c block to true
}
}//////
}
if (third == true && fourth == true){// checking third and fourth y
for (int i = 0; i < Block.size(); i++){// running through blocks
block b = Block.get(i);// gettig blocks
if (e == i){// getting e
b.check = true; // setting e to true
}
if (f == i){ // getting f
b.check = true; // setting f to true
}
if (c == i){ // getting c
b.check = true; // setting c to true
}
}//////
}
}
}