本文整理汇总了Golang中msgpasser.GameRoomData类的典型用法代码示例。如果您正苦于以下问题:Golang GameRoomData类的具体用法?Golang GameRoomData怎么用?Golang GameRoomData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GameRoomData类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
log.Println("Version: 1.0")
index, _ := strconv.Atoi(os.Args[1])
log.Println("index:", index)
var passer msgpasser.Passer
passer.Init(9999)
time.Sleep(3 * time.Second)
for z := 0; z < 30; z++ {
log.Println("Start the", z, "round!")
addr, _ := net.ResolveUDPAddr("udp", "127.0.0.1:9999")
conn, _ := net.DialUDP("udp", nil, addr)
data := msgpasser.GameRoomData{"game room info", 0, nil, len(names), names[index], "start", ""}
data.Players = make([]msgpasser.PlayerInfo, len(names))
for i := range names {
data.Players[i].Ip = addrs[i]
data.Players[i].Name = names[i]
}
b, err := json.Marshal(&data)
log.Println(string(b))
if err != nil {
log.Println(err)
}
_, err = conn.Write(b)
if err != nil {
log.Println(err)
}
// To avoid too many input happen
time.Sleep(10 * time.Second)
x := 120
y := 3
for i := 0; i < x; i++ {
for j := 0; j < y; j++ {
msg := msgpasser.Data{fmt.Sprintf("%v %d", names[index], i*y+j), true}
b, _ = json.Marshal(&msg)
conn.Write(b)
}
time.Sleep(300 * time.Millisecond)
}
// time.Sleep(10 * time.Second)
data = msgpasser.GameRoomData{"game room info", 0, nil, len(names), names[index], "close", ""}
b, err = json.Marshal(&data)
_, err = conn.Write(b)
time.Sleep(10 * time.Second)
log.Println("Finish the", z, "round!")
}
}
示例2: main
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
log.Println("Version: 1.0")
var passer msgpasser.Passer
passer.Init(9999)
time.Sleep(3 * time.Second)
for i, addrS := range addrs {
addr, _ := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:9999", addrS))
conn, _ := net.DialUDP("udp", nil, addr)
data := msgpasser.GameRoomData{"game room info", 0, nil, len(names), names[i], "join", localName}
data.Players = make([]msgpasser.PlayerInfo, len(names))
for i := range names {
data.Players[i].Ip = addrs[i]
data.Players[i].Name = names[i]
}
b, err := json.Marshal(&data)
log.Println(string(b))
if err != nil {
log.Println(err)
}
_, err = conn.Write(b)
if err != nil {
log.Println(err)
}
}
addr, _ := net.ResolveUDPAddr("udp", "127.0.0.1:9999")
conn, _ := net.DialUDP("udp", nil, addr)
// To avoid too many input happen
time.Sleep(3 * time.Second)
x := 10000
y := 3
for i := 0; i < x; i++ {
for j := 0; j < y; j++ {
msg := msgpasser.Data{fmt.Sprintf("%v %d", localName, i*y+j), true}
b, _ := json.Marshal(&msg)
conn.Write(b)
}
time.Sleep(300 * time.Millisecond)
}
for {
time.Sleep(30 * time.Second)
log.Println("I am still alive!")
}
}