Bom dia programadores! Estou com uma dor de cabeça das grandes já testei todas possibilidades de dar premiação no meu Caça Niquel sou iniciante ainda na programação disponibilizarei meu código para quem quiser me ajuda…Não sei qual é meu erro , porem acho que está no meu metódo ganhar… porque fiz teste de mesa no testarjogada() não houve erro.
public void testaJogada() {
int [][] matriz = new int [3][3];
for (i = 0; i < matriz.length; i++) {
for (j = 0; j < matriz.length; j++) {
if (this.matriz[0][0] == this.matriz[1][1]) {
if (this.matriz[1][1] == this.matriz[2][2]) {
this.ganhar(this.matriz[0][0]);
} else {
// Diagonal secundaria
if (this.matriz[0][2] == this.matriz[1][1]) {
if (this.matriz[1][1] == this.matriz[2][0]) {
this.ganhar(valor= this.matriz[1][1]);
} else {
// 1° linha
if (this.matriz[0][0] == this.matriz[0][1]) {
if (this.matriz[0][1] == this.matriz[1][1]) {
this.ganhar(valor=this.matriz[0][0]);
} else {
// 2° linha
if (this.matriz[1][0] == this.matriz[1][1]) {
if (this.matriz[1][1] == this.matriz[1][2]) {
this.ganhar(valor=this.matriz[1][0]);
} else {
// 3° linha
if (this.matriz[2][0] == this.matriz[2][1]) {
if (this.matriz[2][1] == this.matriz[1][2]) {
this.ganhar(valor=this.matriz[2][0]);
} else {
// 1° Coluna
if (this.matriz[0][0] == this.matriz[1][0]) {
if (this.matriz[1][0] == this.matriz[2][0]) {
this.ganhar(valor=this.matriz[0][0]);
} else {
// 2°Coluna
if (this.matriz[0][1] == this.matriz[1][1]) {
if (this.matriz[1][1] == this.matriz[2][1]) {
this.ganhar(valor=this.matriz[0][1]);
} else {
// 3°Coluna
if (this.matriz[0][2] == this.matriz[1][2]) {
if (this.matriz[1][2] == this.matriz[2][2]) {
this.ganhar(valor=this.matriz[0][2]);
} else {
System.out.println(
"Nenhum acerto!!Você acaba de perde 1 vida!"
+ this.retiraVida(-1));
System.out.println(
"Saldo atual de vidas: "
+ this.getGuardavida());
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
// Chamada de pontuacao
public void ganhar(int valor) {
switch (valor) {
case 1:
System.out.println("Parabens! você acaba de ganhar 25 pontos");
this.guardaPontos(25);
System.out.println("Saldo de pontos: " + this.getGuardapontos());
break;
case 2:
System.out.println("Parabens! você acaba de ganhar 35 pontos");
this.guardaPontos(35);
System.out.println("Saldo de pontos: " + this.getGuardapontos());
break;
case 3:
System.out.println("Parabens!Você acaba de ganhar 15 pontos");
this.guardaPontos(15);
System.out.println("Saldo de pontos: " + this.getGuardapontos());
break;
case 4:
System.out.println("Parabens! você acaba de ganhar 50 pontos");
this.guardaPontos(50);
System.out.println("Saldo de pontos: " + this.getGuardapontos());
break;
case 5:
System.out.println("Parabens! você acaba de ganhar 80 pontos");
this.guardaPontos(80);
System.out.println("Saldo de pontos: " + this.getGuardapontos());
break;
case 6:
System.out.println("Parabens !Você acaba de ganhar 100 pontos");
this.guardaPontos(100);
System.out.println("Saldo de pontos: " + this.getGuardapontos());
}
}
public void sortear() {
while (decisao != 2) {
Random gerar = new Random();
int[][] matriz = new int[3][3];
int i, j;
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
matriz[i][j] = gerar.nextInt(120);
if (matriz[i][j] < 10) {
matriz[i][j] = 1;
} else {
if (matriz[i][j] > 10 && matriz[i][j] < 30) {
matriz[i][j] = 2;
} else {
if (matriz[i][j] > 30 && matriz[i][j] < 50) {
matriz[i][j] = 3;
} else {
if (matriz[i][j] > 50 && matriz[i][j] < 80) {
matriz[i][j] = 4;
} else {
if (matriz[i][j] > 80 && matriz[i][j] < 115) {
matriz[i][j] = 5;
} else {
matriz[i][j] = 6;
}
}
}
}
}
}
}
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
this.testaJogada();
System.out.print("[" + matriz[i][j] + "]");
}
System.out.println();
}
System.out.println("deseja continuar?[1] Sim | [2] Nao");
decisao = teclado.nextInt();
if(decisao == 1 && this.guardapontos > 25) {
System.out.println("Deseja com seus pontos de conhecimento compra vida (diamantes)?[1] Sim | [2] Não");
decisao=teclado.nextInt();
if(decisao ==1) {
System.out.println("Insira quantidade de conhecimento: ");
int valor= teclado.nextInt();
switch(valor) {
case 25:
this.retiraPontos(valor);
this.guardaVida(1);
break;
case 50:
this.retiraPontos(valor);
this.guardaVida(2);
break;
case 75:
this.retiraPontos(valor);
this.guardaVida(3);
break;
}
if(this.guardavida>= 8) {
System.out.println("Parabens investigador!!Acaba de juntar todos diamantes roubados pelo poderoso Marcone!Game over! ");
}else {
this.sortear();
}
}
}
}
}
}