Commit 7da5310a authored by Boris Mühmer's avatar Boris Mühmer
Browse files

use interfaces instead of direct types

parent 4c3db6b7
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -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
}

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