當前位置: 首頁>>代碼示例>>Golang>>正文


Golang JsonString.GetRound方法代碼示例

本文整理匯總了Golang中casino/game.JsonString.GetRound方法的典型用法代碼示例。如果您正苦於以下問題:Golang JsonString.GetRound方法的具體用法?Golang JsonString.GetRound怎麽用?Golang JsonString.GetRound使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在casino/game.JsonString的用法示例。


在下文中一共展示了JsonString.GetRound方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: OnOpenDice

func OnOpenDice(m game.JsonString, c net.Conn) {
	fmt.Println("OnOpenDice")
	uid := m.GetUid()

	rep := game.OpenRep{}
	rep.Op = "open_dice"
	rep.Uid = uid

	r, ok := m.GetRound(Casino)
	if ok == false || r.Status != common.GS_ROLL {
		rep.Ret = common.RET_FL
		game.SendMsg(c, rep)
		fmt.Println("OnOpenDice fail", ok, r.Status)
		return
	}
	rep.Ret = common.RET_OK
	r.Open()

	ubl := GetPlayerBalance(r.Players)
	rep.PointsList = make([]game.PointRep, 0)
	for _, player := range r.Players {
		pr := game.PointRep{player.Uid, player.Points, ubl[player.Uid]}
		rep.PointsList = append(rep.PointsList, pr)
	}

	r.Broadcast(rep)
	fmt.Println("OnOpenDice rep:", rep)
}
開發者ID:lsaint,項目名稱:casino,代碼行數:28,代碼來源:casino.go

示例2: OnLogin

func OnLogin(m game.JsonString, c net.Conn) {
	fmt.Println("OnLogin")
	uid, cid, t, name := m.GetUid(), m.GetCid(), m.GetTime(), m.GetName()
	diff := time.Now().Unix() - t

	if diff >= common.ENDURE_SEC || diff < 0 {
		rep := game.LoginRep{common.RET_TME, uid, 0, 0, 0, "login"}
		game.SendMsg(c, rep)
		return
	}

	award, lost := TimeCheck(uid)
	fmt.Println("time check", award, lost)
	bal, _ := db.ModifyBalance(uid, int32(award-lost))
	//bal := mod_ret.Balance
	db.SetLoginTime(uid)
	db.SetName(uid, name)

	r, ok := m.GetRound(Casino)
	if ok == false { // 創建
		r = &game.Round{0, make(map[uint32]game.User, common.MAX_USER), make(map[uint32]game.Player, common.MAX_PLAYER), 0}
		Casino[cid] = r
	}
	user := game.User{c, uid}
	ret := r.Login(user, cid)

	rep := game.LoginRep{ret, uid, award, lost, bal, "login"}
	if ret == common.RET_OK {
		r.Broadcast(rep)
	} else {
		game.SendMsg(c, rep)
	}
	fmt.Println("Login rep:", rep)
}
開發者ID:lsaint,項目名稱:casino,代碼行數:34,代碼來源:casino.go

示例3: OnRollingDice

func OnRollingDice(m game.JsonString, c net.Conn) {
	fmt.Println("OnRollingice")

	r, ok := m.GetRound(Casino)

	if ok == false || r.Status != common.GS_OPEN {
		uid := m.GetUid()
		rep := game.RollRep{common.RET_FL, uid, "", "rolling_dice"}
		game.SendMsg(c, rep)
		fmt.Println("OnRollingDice fail", ok, r.Status)
		return
	}

	r.Roll()

	for _, player := range r.Players {
		rep := game.RollRep{common.RET_OK, player.Uid, player.Points, "rolling_dice"}
		game.SendMsg(player.Conn, rep)
		fmt.Println("OnRollingDice rep:", rep)
	}

	for _, user := range r.Users {
		rep := game.RollRep{common.RET_OK, user.Uid, "", "rolling_dice"}
		game.SendMsg(user.Conn, rep)
	}
}
開發者ID:lsaint,項目名稱:casino,代碼行數:26,代碼來源:casino.go

示例4: OnUserList

func OnUserList(m game.JsonString, c net.Conn) {
	fmt.Println("OnUserList")
	uid, cid := m.GetUid(), m.GetCid()

	rep := game.UserListRep{}
	rep.Ret = common.RET_OK
	rep.Uid = uid
	rep.Cid = cid

	r, ok := m.GetRound(Casino)
	if ok == false {
		rep.Ret = common.RET_FL
		game.SendMsg(c, rep)
		fmt.Println("OnUserList did not found round")
		return
	}

	rep.Status = r.Status
	rep.Op = "user_list"
	rep.UserList = make([]game.UserRep, 0) //+

	ubl := GetPlayerBalance(r.Players)
	for _, player := range r.Players {
		ur := game.UserRep{player.Uid, player.Pos, ubl[player.Uid]}
		rep.UserList = append(rep.UserList, ur)
	}
	for _, user := range r.Users {
		ur := game.UserRep{user.Uid, 0, 0}
		rep.UserList = append(rep.UserList, ur)
	}

	game.SendMsg(c, rep)
	fmt.Println("OnUserList rep:", rep)
}
開發者ID:lsaint,項目名稱:casino,代碼行數:34,代碼來源:casino.go

示例5: OnLogout

func OnLogout(m game.JsonString, c net.Conn) {
	fmt.Println("OnLogout")
	uid, cid := m.GetUid(), m.GetCid()
	r, ok := m.GetRound(Casino)
	if ok {
		uid := m.GetUid()
		r.Logout(uid)
	}
	_, ok = ticker.Active[cid]
	if ok {
		delete(ticker.Active[cid], uid)
	}
	db.SetLogoutTime(uid)

	rep := game.LogoutRep{0, uid, "logout"}
	r.Broadcast(rep)
	fmt.Println("OnLogout rep:", rep)
}
開發者ID:lsaint,項目名稱:casino,代碼行數:18,代碼來源:casino.go

示例6: OnGiveCoin

func OnGiveCoin(m game.JsonString, c net.Conn) {
	fmt.Println("OnGiveCoin")
	coin, uid, tuid := m.GetCoin(), m.GetUid(), m.GetTargetUid()
	r, ok := m.GetRound(Casino)
	if ok == false {
		rep := game.GiveCoinRep{common.RET_FL, uid, tuid, coin, "give_coin"}
		game.SendMsg(c, rep)
		return
	}

	ret := common.RET_OK
	_, err1 := db.ModifyBalance(uid, -coin)
	_, err2 := db.ModifyBalance(tuid, coin)
	db.SetDayCounter(uid, -coin)
	db.SetDayCounter(tuid, coin)
	if err1 != nil || err2 != nil {
		ret = common.RET_FL
	}
	rep := game.GiveCoinRep{ret, uid, tuid, coin, "give_coin"}
	r.Broadcast(rep)
}
開發者ID:lsaint,項目名稱:casino,代碼行數:21,代碼來源:casino.go

示例7: OnJoin

func OnJoin(m game.JsonString, c net.Conn) {
	fmt.Println("OnJoin")
	uid := m.GetUid()
	rep := game.JoinRep{common.RET_FL, uid, 0, 0, "join"}

	r, ok := m.GetRound(Casino)
	if ok == false {
		game.SendMsg(c, rep)
		fmt.Println("OnJoin did not found round")
		return
	}

	pos := m.GetPos()
	rep.Pos, rep.Ret = pos, r.Join(game.Player{game.User{c, uid}, pos, ""})
	if rep.Ret == common.RET_OK {
		bal, _ := db.GetBalance([]uint32{uid})
		rep.Coin = bal[uid]
		r.Broadcast(rep)
	} else {
		game.SendMsg(c, rep)
	}
	fmt.Println("OnJoin rep:", rep)
}
開發者ID:lsaint,項目名稱:casino,代碼行數:23,代碼來源:casino.go


注:本文中的casino/game.JsonString.GetRound方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。