-
Notifications
You must be signed in to change notification settings - Fork 0
/
dog.go
72 lines (60 loc) · 1.47 KB
/
dog.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"io"
)
// Dog represents a four legged friend
type Dog struct {
Name string
Hunger int
Tiredness int
Age int
Output io.Writer
}
// NewDog creates a new dog and returns a pointer to it
func NewDog(name string, output io.Writer) *Dog {
return &Dog{
Name: name,
Hunger: 0,
Tiredness: 0,
Output: output,
}
}
// Birthday makes the dog get older
func (d *Dog) Birthday() {
d.Age++
}
// Sleep makes the dog take a rest. resets tiredness to 0
func (d *Dog) Sleep() {
d.Output.Write([]byte(d.Name + " sleeps...<br>\n"))
d.Tiredness = 0
}
// Bark makes the dog bark
func (d *Dog) Bark() {
d.Output.Write([]byte(d.Name + " goes BARK BARK BARK<br>\n"))
d.Tiredness = d.Tiredness + 20
}
// Eat makes the dog eat. returns hunger to 0
func (d *Dog) Eat() {
d.Output.Write([]byte(d.Name + " eats some food<br>\n"))
d.Hunger = 0
}
// Play makes the dog play
func (d *Dog) Play() {
d.Output.Write([]byte(d.Name + " plays with toys<br>\n"))
d.Tiredness = d.Tiredness + 30
}
// Run makes the dog run around for awhile
func (d *Dog) Run() {
d.Output.Write([]byte(d.Name + " runs around<br>\n"))
d.Tiredness = d.Tiredness + 40
}
//ChaseBird makes the dog chase a bird
func (d *Dog) ChaseBird() {
d.Output.Write([]byte(d.Name + " chases a bird<br>\n"))
d.Tiredness = d.Tiredness + 50
}
//StopsCrime makes Ace stop a crime
func (d *Dog) StopsCrime() {
d.Output.Write([]byte(d.Name + " stops a crime<br>\n"))
d.Hunger = d.Hunger + 50
}