当前位置: 首页>>代码示例>>Golang>>正文


Golang Passer.Init方法代码示例

本文整理汇总了Golang中msgpasser.Passer.Init方法的典型用法代码示例。如果您正苦于以下问题:Golang Passer.Init方法的具体用法?Golang Passer.Init怎么用?Golang Passer.Init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在msgpasser.Passer的用法示例。


在下文中一共展示了Passer.Init方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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)

	cmd := exec.Command("python", "bSserver.py", os.Args[1], os.Args[2])
	go cmd.Run()
	/*if err != nil {
		log.Println(err)
	}*/

	time.Sleep(3 * time.Second)

	cmd2 := exec.Command("java", "-jar", "ttt.jar", os.Args[1], os.Args[2])
	go cmd2.Run()
	/*if err != nil {
		log.Println(err)
	}*/

	for {
		time.Sleep(30 * time.Second)
		log.Println("I am still alive!")
	}
}
开发者ID:weimingtom,项目名称:tank_battle,代码行数:27,代码来源:uuu.go

示例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)

	/*	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]}
		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)
		}*/

	for {
		time.Sleep(30 * time.Second)
		log.Println("I am still alive!")
	}
}
开发者ID:weimingtom,项目名称:tank_battle,代码行数:31,代码来源:passer.go

示例3: 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!")
	}
}
开发者ID:weimingtom,项目名称:tank_battle,代码行数:56,代码来源:start5PGames.go

示例4: 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!")
	}
}
开发者ID:weimingtom,项目名称:tank_battle,代码行数:50,代码来源:join3PGame.go


注:本文中的msgpasser.Passer.Init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。