-
Notifications
You must be signed in to change notification settings - Fork 0
/
NOinterfacesRPG.go
47 lines (32 loc) · 1.02 KB
/
NOinterfacesRPG.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
/* Alta3 Research | rzfeeser@alta3.com
Interfaces - Simple RPG example with NO interfaces */
package main
import (
"fmt"
"reflect"
)
// Create Wizard struct
type Wizard struct{}
// Wizard Receiver Function (method) - This is how we want the Wizard to Defend()
func (w Wizard) Defend() string {
return "Expelliarmus"
}
// Wizard Receiver Function (method) - A Wizard has the unique ability to cast a Forget() spell
func (w Wizard) Forget() string {
return "Obliviate"
}
// Create Barbarian struct
type Barbarian struct{}
// Barbarian Receiver Function (method) - This is how we want the Barbarian to Defend()
func (b Barbarian) Defend() string {
return "Dodge"
}
func main() {
gandalf := Wizard{}
fmt.Println("Wizard defends:", gandalf.Defend())
// repeat the same pattern for the Barbarian
conan := Barbarian{}
fmt.Println("Barbarian defends:", conan.Defend())
// continue the pattern for any other players
fmt.Println("Wizard makes us all forget:", gandalf.Forget())
}