mirror of
https://github.com/crazybber/go-pattern-examples.git
synced 2024-11-28 14:46:01 +03:00
48 lines
856 B
Go
48 lines
856 B
Go
package visitor
|
||
|
||
import "testing"
|
||
|
||
func TestSingleVisitor(t *testing.T) {
|
||
|
||
//汽油提供给,制衣工厂
|
||
g := gas{density: 100}
|
||
|
||
//柴油,提供给军工厂
|
||
d := diesel{energy: 897}
|
||
|
||
//购买石油的客户
|
||
m := &militaryFactory{}
|
||
|
||
c := &clothFactory{}
|
||
|
||
g.Accept(c)
|
||
|
||
d.Accept(m)
|
||
|
||
}
|
||
|
||
func TestGameVisitorsList(t *testing.T) {
|
||
|
||
retriveSetting := SettingVisitor{}
|
||
attacker := Attacker{}
|
||
|
||
pA := Player{"snow dance", 100} //角色名名:snow dance 100级
|
||
pB := Player{"fire dragon", 120}
|
||
npc := NPC{"groceries", true} //卖杂货的NPC,是能被打死的
|
||
env := SystemEnv{"made by china", "v1.2.11"}
|
||
|
||
//游戏对象
|
||
gameObjects := []IGameObject{pA, npc, env, pB}
|
||
|
||
for _, v := range gameObjects {
|
||
v.Accept(retriveSetting)
|
||
}
|
||
|
||
t.Log("\n---- !!!attack!!!- --")
|
||
|
||
for _, v := range gameObjects {
|
||
v.Accept(attacker)
|
||
}
|
||
|
||
}
|