This commit is contained in:
Giorgio Croci 2017-05-26 15:38:04 +02:00
parent c16ec833d8
commit 82ee7b4ef4
2 changed files with 27 additions and 4 deletions

View File

@ -16,3 +16,16 @@ type Element struct { //struttura che contiene sia cibo sia amebe
func (e Element) String() string { 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)
} }
func Costruttore(razza string, evoluzione int, costomov int, costosex int, premura int) *Element {
nuovo := new(Element)
nuovo.IsFood=false
nuovo.Health=100
nuovo.Age=0
nuovo.Razza=razza
nuovo.Evoluzione=evoluzione
nuovo.CostoMov=costomov
nuovo.CostoSex=costosex
nuovo.Premura=premura
return nuovo
}

18
main.go
View File

@ -117,13 +117,13 @@ func muovi(h int, w int) { //FUNZIONE MUOVI: aggiorna la posizione di tutti gli
} }
if (elemento.Health-elemento.Premura)>elemento.CostoSex { //se ha energia a sufficienza per riprodursi if (elemento.Health-elemento.Premura)>elemento.CostoSex { //se ha energia a sufficienza per riprodursi
riproduci(h, w) Matrix[h][w] = Costruttore(elemento.Razza, elemento.Evoluzione, elemento.CostoMov, elemento.CostoSex, elemento.Premura)
} }
} }
} }
func stampaMatrice() { func stampaMatrice2() {
for i := 0; i < Altezza; i++ { for i := 0; i < Altezza; i++ {
fmt.Printf("Riga %d:\n", i) fmt.Printf("Riga %d:\n", i)
for j := 0; j < Larghezza; j++ { for j := 0; j < Larghezza; j++ {
@ -139,6 +139,16 @@ func stampaMatrice() {
} }
} }
func riproduci(h int, w int) { func stampaMatrice() {
for i := 0; i < Altezza; i++ {
for j := 0; j < Larghezza; j++ {
if Matrix[i][j]!=nil {
fmt.Printf("0 ")
} else {
fmt.Printf("1 ")
}
fmt.Printf(" Colonna %d: %s\n")
}
fmt.Printf("\n")
}
} }