Skip to content

Instantly share code, notes, and snippets.

@Brandonxy
Created September 13, 2023 22:53
Show Gist options
  • Save Brandonxy/ef48a159c9fb96fcc343e57947614dac to your computer and use it in GitHub Desktop.
Save Brandonxy/ef48a159c9fb96fcc343e57947614dac to your computer and use it in GitHub Desktop.
package pokemon;
import java.util.Random;
import java.util.Scanner;
public class Pokemon {
private int matriz1[][];
private int matriz2[][];
private int pokebolas;
private int po;
private static int size = 11;
public Pokemon() {
matriz1 = new int[size][size];
matriz2 = new int[size][size];
pokebolas = 20;
po = 0;
int fila;
int columna;
for (int i = 1; i < matriz1.length; i++) {
for (int j = 1; j < matriz1[i].length; j++) {
matriz1[i][j] = 7;
matriz2[i][j] = 0;
}
}
int i = 1;
while (i < 10) {
fila = (int) (Math.random() * 9 + 1);
columna = (int) (Math.random() * 9 + 1);
if (matriz1[fila][columna] == 7) {
i = i + 1;
matriz1[fila][columna] = 8;
}
}
int j = 1;
while (j < 20) {
fila = (int) (Math.random() * 9 + 1);
columna = (int) (Math.random() * 9 + 1);
if (matriz1[fila][columna] == 7) {
j = j + 1;
matriz1[fila][columna] = 5;
}
}
int x = 1;
while (x < 5) {
fila = (int) (Math.random() * 9 + 1);
columna = (int) (Math.random() * 9 + 1);
if (matriz1[fila][columna] == 7) {
matriz1[fila][columna] = x;
x = x + 1;
}
}
mostrarTablero();
while (pokebolas != 0 || po < 4) {
Scanner cordScanner1 = new Scanner(System.in);
Scanner cordScanner2 = new Scanner(System.in);
System.out.println("Ingrese la fila: ");
fila = cordScanner1.nextInt();
System.out.println("Ingrese la columna");
columna = cordScanner2.nextInt();
/**
* Si estoy intentando disparar a una cordenada
* con valor diferente a cero entonces
* no puedo ejecutar mi disparo. Al la cordenada
* al la que voy a disparar debe estar en cero
*/
if (matriz2[fila][columna] == 0) {
if (matriz1[fila][columna] == 1 ||
matriz1[fila][columna] == 2 ||
matriz1[fila][columna] == 3) {
System.out.println("Atrapaste un pokemon");
/**
* Restamos una pokebola
*/
pokebolas = pokebolas - 1;
po = po + 1;
/**
* Rellenamos la posicion equivalente en
* el otro tablero
*/
matriz2[fila][columna] = 1;
} else {
if (matriz1[fila][columna] == 8) {
/**
* Si eligo una posicion que contiene
* el valor 8 en el tablero entonces
* gano 5 pokebolas
*/
pokebolas = pokebolas + 5;
System.out.println("Suertudo tienes " +
" 5 pokebolas extras!!");
matriz2[fila][columna] = 8;
} else {
if (matriz1[fila][columna] == 5) {
System.out.println("Caiste en terreno" +
" Docil, no pierdes tu " +
" pokebola");
matriz2[fila][columna] = 5;
} else {
System.out.println("Caise en terreno inhospito, perdiste " +
"una pokebola");
pokebolas = pokebolas - 1;
matriz2[fila][columna] = 7;
}
}
}
mostrarTablero();
} else {
System.out.println("Ingrese una cordenada" +
" de disparo valida");
}
}
mostrarTablero();
}
public void mostrarTablero() {
System.out.println("[Tablero 2] [Tablero 1]");
System.out.println("------------------------------ ------------------------------");
for (int i = 1; i < matriz1.length; i++) {
for(int z = 1; z < matriz2[i].length; z++) {
System.out.print("[" + matriz2[i][z] + "]");
}
System.out.print(" | ");
for(int j = 1; j < matriz1[i].length; j++) {
System.out.print("[" + matriz1[i][j] + "]");
}
System.out.println();
}
System.out.println("------------------------------ ------------------------------");
System.out.print("Pokebolas: " + pokebolas);
System.out.print(" | ");
System.out.println("Po: " + po);
System.out.println("------------------------------ ------------------------------");
}
public static void main(String[] args) {
new Pokemon();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment