Loading ocean.go +10 −10 Original line number Diff line number Diff line Loading @@ -11,15 +11,15 @@ import ( // Ocean is the container for fish and sharks. type Ocean struct { Cells map[position]Celler Food map[position]*fish.Fish Hunters map[position]*shark.Shark Food map[position]Food Hunters map[position]Hunter } // CreateOcean initializes a new ocean. func createOcean() (*Ocean, error) { o := &Ocean{Cells: make(map[position]Celler)} o.Food = make(map[position]*fish.Fish) o.Hunters = make(map[position]*shark.Shark) o.Food = make(map[position]Food) o.Hunters = make(map[position]Hunter) return o, nil } Loading @@ -27,7 +27,7 @@ func (o *Ocean) populateWater(w *Wator) error { for x := 0; x < w.Width; x++ { for y := 0; y < w.Height; y++ { p := position{x: x, y: y} o.Cells[p] = &water.Water{} o.Cells[p] = water.New() } } return nil Loading @@ -41,7 +41,7 @@ func (o *Ocean) populateFishes(w *Wator) error { y := rand.Intn(w.Height) p := position{x: x, y: y} switch o.Cells[p].(type) { case *water.Water: case Celler: a := rand.Intn(w.BreedFish) f := fish.New(a) o.Cells[p] = f Loading @@ -61,7 +61,7 @@ func (o *Ocean) populateSharks(w *Wator) error { y := rand.Intn(w.Height) p := position{x: x, y: y} switch o.Cells[p].(type) { case *water.Water: case Celler: a := rand.Intn(w.BreedShark) s := shark.New(a) o.Cells[p] = s Loading @@ -76,7 +76,7 @@ func (o *Ocean) populateSharks(w *Wator) error { func (o *Ocean) isWater(p position) bool { r := false switch o.Cells[p].(type) { case *water.Water: case Celler: r = true } return r Loading @@ -85,7 +85,7 @@ func (o *Ocean) isWater(p position) bool { func (o *Ocean) isFish(p position) bool { r := false switch o.Cells[p].(type) { case *fish.Fish: case Food: r = true } return r Loading @@ -94,7 +94,7 @@ func (o *Ocean) isFish(p position) bool { func (o *Ocean) isShark(p position) bool { r := false switch o.Cells[p].(type) { case *shark.Shark: case Hunter: r = true } return r Loading Loading
ocean.go +10 −10 Original line number Diff line number Diff line Loading @@ -11,15 +11,15 @@ import ( // Ocean is the container for fish and sharks. type Ocean struct { Cells map[position]Celler Food map[position]*fish.Fish Hunters map[position]*shark.Shark Food map[position]Food Hunters map[position]Hunter } // CreateOcean initializes a new ocean. func createOcean() (*Ocean, error) { o := &Ocean{Cells: make(map[position]Celler)} o.Food = make(map[position]*fish.Fish) o.Hunters = make(map[position]*shark.Shark) o.Food = make(map[position]Food) o.Hunters = make(map[position]Hunter) return o, nil } Loading @@ -27,7 +27,7 @@ func (o *Ocean) populateWater(w *Wator) error { for x := 0; x < w.Width; x++ { for y := 0; y < w.Height; y++ { p := position{x: x, y: y} o.Cells[p] = &water.Water{} o.Cells[p] = water.New() } } return nil Loading @@ -41,7 +41,7 @@ func (o *Ocean) populateFishes(w *Wator) error { y := rand.Intn(w.Height) p := position{x: x, y: y} switch o.Cells[p].(type) { case *water.Water: case Celler: a := rand.Intn(w.BreedFish) f := fish.New(a) o.Cells[p] = f Loading @@ -61,7 +61,7 @@ func (o *Ocean) populateSharks(w *Wator) error { y := rand.Intn(w.Height) p := position{x: x, y: y} switch o.Cells[p].(type) { case *water.Water: case Celler: a := rand.Intn(w.BreedShark) s := shark.New(a) o.Cells[p] = s Loading @@ -76,7 +76,7 @@ func (o *Ocean) populateSharks(w *Wator) error { func (o *Ocean) isWater(p position) bool { r := false switch o.Cells[p].(type) { case *water.Water: case Celler: r = true } return r Loading @@ -85,7 +85,7 @@ func (o *Ocean) isWater(p position) bool { func (o *Ocean) isFish(p position) bool { r := false switch o.Cells[p].(type) { case *fish.Fish: case Food: r = true } return r Loading @@ -94,7 +94,7 @@ func (o *Ocean) isFish(p position) bool { func (o *Ocean) isShark(p position) bool { r := false switch o.Cells[p].(type) { case *shark.Shark: case Hunter: r = true } return r Loading