Skip to content

Instantly share code, notes, and snippets.

@Brandonxy
Created September 13, 2023 22:54
Show Gist options
  • Save Brandonxy/f8152b9dc04dd6bd10d956a59b3bdbb5 to your computer and use it in GitHub Desktop.
Save Brandonxy/f8152b9dc04dd6bd10d956a59b3bdbb5 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
"math/rand"
"strconv"
)
)
const SIZE int = 11
var matriz1 [matriz1 [SIZE][][SIZE]int
var matriz2 [matriz2 [SIZE][][SIZE]int
var pokebolas int = 20
var po int = 0
func main() {
var fila int
var columna int
for i := 1; i < len(matriz1); i++ {
for j := 1; j < len(matriz1[i]); j++ {
/**
* Asignamos un 7 a cada una de las posiciones
* de la matriz1
*/
matriz1[i][j] = 7;
/**
* Asignamos un 0 a cada una de las posiciones
* de la matriz2
*/
matriz2[i][j] = 0;
}
/**
* Aqui termina el recorrido de una fila
* TODO: hacer algo al final de cada fila
*/
}
/**
* Recorremos la matriz 1 e insertamos en una posicion
* aleatoria el valor 8, solo si quedan posiciones con el
*¨valor 7 disponibles
*/
for i := 1; i < 10; {
rand.Seed(time.Now().Unix())
fila = rand.Intn( 10 - 1) + 1
columna = rand.Intn(10 - 1) + 1
if matriz1[fila][columna] == 7 {
// Quedan 7's disponibles
// Rellenamos con un 8
matriz1[fila][columna] = 8;
i = i + 1
}
}
for j := 0; j < 10; j++ {
fila = rand.Intn(10 - 1) + 1
columna = rand.Intn( 10 - 1) + 1
if matriz1[fila][columna] == 7 {
j = j + 1;
matriz1[fila][columna] = 8;
}
}
for x := 1; x < 20; {
fila = rand.Intn(10 - 1) + 1
columna = rand.Intn( 10 - 1) + 1
if (matriz1[fila][columna] == 7) {
x = x + 1;
matriz1[fila][columna] = 5;
}
}
for z := 1; z < 5; {
fila = rand.Intn(10 - 1) + 1
columna = rand.Intn( 10 - 1) + 1
if (matriz1[fila][columna] == 7) {
matriz1[fila][columna] = z;
z = z + 1;
}
}
mostrarTablero()
for pokebolas !=0 || po < 4 {
fmt.Println("Ingrese la fila: ");
_, err := fmt.Scanf("%d", &fila)
if err != nil {
fmt.Println("Error al obtener el numero")
}
fmt.Println("Ingrese la columna");
_, err2 := fmt.Scanf("%d", &columna)
if err2 != nil {
fmt.Println("Error al obtener la columna")
}
/**
* 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 {
fmt.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;
fmt.Println("Suertudo tienes " +
" 5 pokebolas extras!!");
matriz2[fila][columna] = 8;
} else {
if (matriz1[fila][columna] == 5) {
fmt.Println("Caiste en terreno" +
" Docil, no pierdes tu " +
" pokebola");
matriz2[fila][columna] = 5;
} else {
fmt.Println("Caise en terreno inhospito, perdiste " +
"una pokebola");
pokebolas = pokebolas - 1;
matriz2[fila][columna] = 7;
}
}
}
mostrarTablero()
} else {
fmt.Println("Ingrese una cordenada" +
" de disparo valida");
}
}
mostrarTablero()
}
func mostrarTablero() {
fmt.Println("[Tablero 1] [Tablero 2]");
fmt.Println("---------------------------------------");
for i := 1; i < len(matriz1); i++ {
for j := 1; j < len(matriz1[i]); j++ {
fmt.Print("[" + strconv.Itoa(matriz1[i][j]) + "]");
}
fmt.Print(" | ")
for z := 1; z < len(matriz2[i]); z ++ {
fmt.Print("[" + strconv.Itoa(matriz2[i][z]) + "]")
}
fmt.Println()
}
fmt.Println("------------------------------ ------------------------------");
fmt.Print("Pokebolas: " + strconv.Itoa(pokebolas));
fmt.Print(" | ");
fmt.Println("Po: " + strconv.Itoa(po));
fmt.Println("------------------------------ ------------------------------");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment