diff --git a/element.go b/element.go index cceb27a..673c8ef 100644 --- a/element.go +++ b/element.go @@ -9,5 +9,5 @@ type Element struct { //struttura che contiene sia cibo sia amebe } func (e Element) String() string { - return fmt.Sprintf("E'Cibo=%t Salute=%d Eta=%d", e.IsFood, e.Health, e.Age) + return fmt.Sprintf("", e.IsFood, e.Health, e.Age) } diff --git a/main.go b/main.go index 8cbf675..894beb6 100644 --- a/main.go +++ b/main.go @@ -46,10 +46,10 @@ func main() { } } } + fmt.Println("Situazione iniziale: ") + stampaMatrice() - fmt.Println(Matrix) - - go aggiorna() + //go aggiorna() } func aggiorna() { @@ -61,7 +61,7 @@ func aggiorna() { func muovi(h int, w int) { // h verticale, w orizzontale elemento := Matrix[h][w] - if elemento == nil && elemento.IsFood { + if elemento == nil || elemento.IsFood { return } direzCasOriz := rand.Intn(2) @@ -91,3 +91,19 @@ func muovi(h int, w int) { // h verticale, w orizzontale Matrix[h][w] = nil } } + +func stampaMatrice() { + for i := 0; i < Altezza; i++ { + fmt.Printf("Riga %d:\n", i) + for j := 0; j < Larghezza; j++ { + var stringa string + elem := Matrix[i][j] + if elem == nil { + stringa = "Vuota" + } else { + stringa = elem.String() + } + fmt.Printf(" Colonna %d: %s\n", j, stringa) + } + } +}