Olá!
Estou iniciando com Java, e estou com algumas dúvidas na resolução de um trabalho.
Preciso implementar o jogo Combate.
Cada peça, necessita ser um vetor? [linha][coluna]. (no caso de soldados por exemplo, devo criar 8 peças… sol1, sol2, sol3… ?
Preciso instanciar um contador para cada peça pra saber quantas peças foram incluídas e quantas ainda restam?
Preciso cirar as variáveis para identificar quais eu perdi?
Abaixo, o que eu já fiz…
import java.util.Scanner;
public class T111 {
Scanner s = new Scanner(System.in);
// 1 - MARECHAL -- GRAU - 10
// 1 - GENERAL -- GRAU - 9
// 2 - CORONEL -- GRAU - 8
// 3 - MAJOR -- GRAU - 7
// 4 - CAPITAO -- GRAU - 6
// 4 - TENENTE -- GRAU - 5
// 4 - SARGENTO -- GRAU - 4
// 5 - CABO ARMEIRO -- GRAU - 3
// 8 - SOLDADO -- GRAU - 2
// 1 - ESPIAO -- GRAU - 1
// 6 - BOMBA -- GRAU -
// 1 - BANDEIRA -- GRAU -
private int[][] mar; // MARECHAL
private int[][] ger; // GENERAL
private int[][] cor1; // CORONEL
private int[][] cor2; // CORONEL
private int[][] maj1; // MAJOR
private int[][] maj2; // MAJOR
private int[][] maj3; // MAJOR
private int[][] cap1; // CAPITAO
private int[][] cap2; // CAPITAO
private int[][] cap3; // CAPITAO
private int[][] cap4; // CAPITAO
private int[][] ten1; // TENENTE
private int[][] ten2; // TENENTE
private int[][] ten3; // TENENTE
private int[][] ten4; // TENENTE
private int[][] sar1; // SARGENTO
private int[][] sar2; // SARGENTO
private int[][] sar3; // SARGENTO
private int[][] sar4; // SARGENTO
private int[][] cab1; // CABO ARMEIRO
private int[][] cab2; // CABO ARMEIRO
private int[][] cab3; // CABO ARMEIRO
private int[][] cab4; // CABO ARMEIRO
private int[][] cab5; // CABO ARMEIRO
private int[][] sol1; // SOLDADO
private int[][] sol2; // SOLDADO
private int[][] sol3; // SOLDADO
private int[][] sol4; // SOLDADO
private int[][] sol5; // SOLDADO
private int[][] sol6; // SOLDADO
private int[][] sol7; // SOLDADO
private int[][] sol8; // SOLDADO
private int[][] esp; // ESPIAO
private int[][] bom1; // BOMBA
private int[][] bom2; // BOMBA
private int[][] bom3; // BOMBA
private int[][] bom4; // BOMBA
private int[][] bom5; // BOMBA
private int[][] bom6; // BOMBA
private int[][] ban; // BANDEIRA
private int quantosMar, quantosGer, quantosCor1, quantosCor2, quantosMaj1, quantosMaj2, quantosMaj3,
quantosCap1, quantosCap2, quantosCap3, quantosCap4, quantosTen1, quantosTen2, quantosTen3,
quantosTen4, quantosSar1, quantosSar2, quantosSar3, quantosSar4, quantosCab1, quantosCab2,
quantosCab3, quantosCab4, quantosCab5, quantosSol1, quantosSol2, quantosSol3, quantosSol4,
quantosSol5, quantosSol6, quantosSol7, quantosSol8, quantosEsp, quantosBom1, quantosBom2,
quantosBom3, quantosBom4, quantosBom5, quantosBom6, quantosBan;
private int contMar, contGer, contCor1, contCor2, contMaj1, contMaj2, contMaj3, contCap1, contCap2,
contCap3, contCap4, contTen1, contTen2, contTen3, contTen4, contSar1, contSar2, contSar3,
contSar4, contCab1, contCab2, contCab3, contCab4, contCab5, contSol1, contSol2, contSol3,
contSol4, contSol5, contSol6, contSol7, contSol8, contEsp, contBom1, contBom2, contBom3,
contBom4, contBom5, contBom6, contBan; //cont dos vetores para saber posição
private int linha, coluna, tabuleiro[][], tabuleiroAtaca[][], peca, grau,
enviaPosicao, tabuleiroMostra[][];
private int Pmar, Pger, Pcor1, Pcor2, Pmaj1, Pmaj2, Pmaj3, Pcap1, Pcap2, Pcap3, Pcap4, Pten1, Pten2,
Pten3, Pten4, Psar1, Psar2, Psar3, Psar4, Pcab1, Pcab2, Pcab3, Pcab4, Pcab5, Psol1, Psol2,
Psol3, Psol4, Psol5, Psol6, Psol7, Psol8, Pesp, Pbom1, Pbom2, Pbom3, Pbom4, Pbom5, Pbom6,
Pban; //para saber se Perdeu
String r = new String();
public T111(int l, int c) {
linha = l;
coluna = c;
tabuleiro = new int[l][c];
tabuleiroMostra = new int[l][c];
tabuleiroAtaca = new int[l][c];
mar = new int[1][1];
ger = new int[1][1];
cor1 = new int[1][1];
cor2 = new int[1][1];
maj1 = new int[1][1];
maj2 = new int[1][1];
maj3 = new int[1][1];
cap1 = new int[1][1];
cap2 = new int[1][1];
cap3 = new int[1][1];
cap4 = new int[1][1];
ten1 = new int[1][1];
ten2 = new int[1][1];
ten3 = new int[1][1];
ten4 = new int[1][1];
sar1 = new int[1][1];
sar2 = new int[1][1];
sar3 = new int[1][1];
sar4 = new int[1][1];
cab1 = new int[1][1];
cab2 = new int[1][1];
cab3 = new int[1][1];
cab4 = new int[1][1];
cab5 = new int[1][1];
sol1 = new int[1][1];
sol2 = new int[1][1];
sol3 = new int[1][1];
sol4 = new int[1][1];
sol5 = new int[1][1];
sol6 = new int[1][1];
sol7 = new int[1][1];
sol8 = new int[1][1];
esp = new int[1][1];
bom1 = new int[1][1];
bom2 = new int[1][1];
bom3 = new int[1][1];
bom4 = new int[1][1];
bom5 = new int[1][1];
bom6 = new int[1][1];
ban = new int[1][1];
Pmar = Pger = Pcor1 = Pcor2 = Pmaj1 = Pmaj2 = Pmaj3 = Pcap1 = Pcap2 = Pcap3 = Pcap4 = Pten1
= Pten2 = Pten3 = Pten4 = Psar1 = Psar2 = Psar3 = Psar4 = Pcab1 = Pcab2 = Pcab3 = Pcab4
= Pcab5 = Psol1 = Psol2 = Psol3 = Psol4 = Psol5 = Psol6 = Psol7 = Psol8 = Pesp = Pbom1
= Pbom2 = Pbom3 = Pbom4 = Pbom5 = Pbom6 = Pban = 0;
//DESENVOLVIMENTO....
}
public void Mostrar(int tabmostra[][]) {
int contl = 9, contc = 9;
System.out.print(" ");
for (int contcol = 0; contcol < coluna; contcol++) {
if (contcol < 9) {
System.out.print(" " + (contcol + 1) + " ");
} else {
System.out.print(" " + (contcol + 1));
}
}
System.out.println("");
System.out.print(" ");
for (contl = 0; contl < linha; contl++) {
System.out.print(" ");
if (contl == 0) {
System.out.printf("%c", 218);
} else {
System.out.print(" ");
System.out.printf("%c", 195);
}
for (contc = 0; contc < coluna; contc++) {
if (contc == coluna - 1) {
System.out.printf("%c", 196);
System.out.printf("%c", 196);
} else {
System.out.printf("%c", 196);
System.out.printf("%c", 196);
System.out.printf("%c", 196);
}
}
if (contl == 0) {
System.out.printf("%c\n", 191);
} else {
System.out.printf("%c\n", 180);
}
if (contl < 9) {
System.out.print((contl + 1) + " ");
} else {
System.out.print((contl + 1));
}
System.out.printf("%c", 179);
for (contc = 0; contc < coluna; contc++) {
if (tabmostra[contl][contc] == 1) {
System.out.printf(" X"); //SUBSTITUIR X PELA PEÇA
} else if (tabmostra[contl][contc] == 0) {
System.out.printf("%c", 32);
System.out.printf("%c", 32);
} else if (tabmostra[contl][contc] == 2) {
System.out.printf(" Y"); //SUBSTITUIR Y PELA PEÇA
} else if (tabmostra[contl][contc] == 4) {
System.out.printf(" Z"); //SUBSTITUIR Z PELA PEÇA
} else if (tabmostra[contl][contc] == 5) {
System.out.printf(" T"); //SUBSTITUIR T PELA PEÇA
} else if (tabmostra[contl][contc] == -1) {
System.out.printf(" *");
}
System.out.printf("%c", 179);
}
System.out.printf("\n");
if (contl == linha - 1) {
System.out.print(" ");
System.out.printf("%c", 192);
for (contc = 0; contc <
coluna; contc++) {
if (contc == coluna - 1) {
System.out.printf("%c", 196);
System.out.printf("%c", 196);
} else {
System.out.printf("%c", 196);
System.out.printf("%c", 196);
System.out.printf("%c", 196);
}
}
if (contl != linha - 1) {
System.out.printf("%c\n", 180);
} else {
System.out.printf("%c", 217);
}
}
}
System.out.println(" ");
}
public int[][] getTabuleiro() {
return tabuleiro;
}
public int[][] getTabuleiroMostra() {
return tabuleiroMostra;
}
}
Obrigado!!!