diff --git a/element.go b/element.go index 39953f3..033ba85 100644 --- a/element.go +++ b/element.go @@ -16,3 +16,16 @@ type Element struct { //struttura che contiene sia cibo sia amebe func (e Element) String() string { return fmt.Sprintf("", 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 +} diff --git a/main.go b/main.go index 8d570ba..9562825 100644 --- a/main.go +++ b/main.go @@ -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 - 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++ { fmt.Printf("Riga %d:\n", i) 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") + } }