Hi, I’m trying to make a game which consists of joining two points without touching the bombs that were generated.
I have advanced a lot in the game, I have to do that when the player wins everything is restarted and the bombs are repainted, could you help me? Thank you
Code :
import javax.swing.JOptionPane;
int [][] cuadricula;
int[]ran;
int[]rann;
Bombas minas;
int w = 100;
int h = 100;
int margen = 100;
int dif;
Cuadricula c;
int contador;
int vidabomba;
int xv, yv;
int tx, ty;
boolean ganar;
boolean pintarc;
int a, b;
void setup() {
background(51);
size(800, 800);
cuadricula = new int[6][6];
ganar =true ;
pintarc = true;
vidabomba=255;
c = new Cuadricula();
dif=6;
ran= new int[dif];
rann= new int[dif];
tx=(int)random(3, 5);
ty=(int)random(3, 5);
minas = new Bombas();
minas.generarMinas();
c.DibujarC();
}
void draw() {
minas.pintarBombas();
vidabomba-=4;
fill(#0000FF);
rect(margen, margen, w, h);
rect(margen+w*tx, margen+h*ty, w, h);
}
void mouseClicked() {
for (int i=1; i< dif; i++) {
if (mouseX >= margen+w*ran[i] && mouseX <= (margen+w*ran[i])+100 && mouseY >= margen+h*rann[i] && mouseY <= (margen+h*rann[i])+100) {
textSize(48);
text("BOOM! :(", width/2-100, height/2);
println("TOCO 11111111111");
noLoop();
}
}
for (int f = 0; f < cuadricula.length; f++) {
for (int c = 0; c < cuadricula[f].length; c++) {
if (mouseX >= margen + c*w && mouseX <= (margen + c*w)+100 &&
mouseY >= margen + f*h && mouseY <= (margen+f*h)+100) {
fill(0, 0, 255);
rect(margen + c*w, margen + f*h, 100, 100);
}
}
}
for (int i=1; i< dif; i++) {
xv=margen+w*tx;
yv=margen+h*ty;
if (mouseX >= xv && mouseX <= xv+100 && mouseY >= yv && mouseY <= yv+100 ) {
tx=(int)random(3, 5);
ty=(int)random(3, 5);
c.DibujarC();
minas.generarMinas();
if (ganar==true) {
contador++;
}
ganar = false;
JOptionPane.showMessageDialog(null, "Ganaste, puntos: "+contador);
vidabomba=255;
redraw();
} else {
ganar=true;
}
}
}
class Bombas {
Bombas() {
}
void dibujarBombas(int xb, int yb ) {
noStroke();
fill(#FF0000, vidabomba);
ellipse(xb, yb, 70, 70);
fill(255, vidabomba);
ellipse(xb-20, yb-10, 15, 15);
fill(#FF0000, vidabomba);
}
void pintarBombas() {
for (int i=1; i<dif; i++) {
fill(51);
noStroke();
rect(margen+w*ran[i]+5, margen+h*rann[i]+5, w-10, h-10);
minas.dibujarBombas(margen + w*ran[i]+50, margen+h*rann[i]+60 );
}
}
void generarMinas() {
//Generar minas
for (int i=1; i<dif; i++) {
ran[i]=(int)random(6);
rann[i]=(int)random(6);
if (ran[i] == ran[i-1]) {
ran[i]=(int)random(5);
}
if (rann[i] == ran[i-1]) {
rann[i]=(int)random(5);
}
if (ran[i]==0&&rann[i]==0) {
ran[i]=(int)random(5);
rann[i]=(int)random(5);
}
if (ran[i]==tx && rann[i] ==ty) {
ran[i]=(int)random(5);
rann[i]=(int)random(5);
}
if (ran[i]==0 && rann[i] == 0) {
ran[i]=(int)random(5);
rann[i]=(int)random(5);
}
}
}
}
class Cuadricula {
Cuadricula() {
}
void DibujarC() {
for (int f = 0; f < cuadricula.length; f++) {
for (int c = 0; c < cuadricula[f].length; c++) {
//Dibujar el cuadro
fill(51);
stroke(0);
strokeWeight(2);
rect(margen + w*c, margen + h*f, w, h);
}
}
}
}