Funzione stampa matrice

This commit is contained in:
Claudio Maggioni 2017-05-26 14:26:59 +02:00
parent d19bb2684b
commit 490ff1d6d4
2 changed files with 21 additions and 5 deletions

View File

@ -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'Cibo=%t Salute=%d Eta=%d>", e.IsFood, e.Health, e.Age)
}

24
main.go
View File

@ -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)
}
}
}