當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。