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


Golang overpower.GameDat类代码示例

本文整理汇总了Golang中mule/overpower.GameDat的典型用法代码示例。如果您正苦于以下问题:Golang GameDat类的具体用法?Golang GameDat怎么用?Golang GameDat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: CommandNewFaction

func (h *Handler) CommandNewFaction(g overpower.GameDat, facs []overpower.FactionDat, f overpower.FactionDat, password, facname string) (errServer, errUser error) {
	if g.Turn() > 0 {
		return nil, NewError("GAME IN PROGRESS")
	}
	if f != nil {
		return nil, NewError("USER ALREADY HAS FACTION FOR THIS GAME")
	}
	if g.HasPassword() {
		if !ValidText(password) || !g.IsPassword(password) {
			return nil, NewError("BAD PASSWORD")
		}
	}
	if !ValidText(facname) {
		return nil, NewError("BAD FACTION NAME")
	}
	lwFName := strings.ToLower(facname)
	for _, f := range facs {
		if strings.ToLower(f.Name()) == lwFName {
			return nil, NewError("FACTION NAME ALREADY IN USE FOR THIS GAME")
		}
	}
	newF := &models.Faction{
		GID:   g.GID(),
		Owner: h.User.String(),
		Name:  facname,
	}
	h.M.CreateFaction(newF)
	err := h.M.Close()
	if my, bad := Check(err, "data creation error", "type", "faction", "gid", g.GID(), "user", h.User, "facname", facname); bad {
		return my, nil
	}
	return nil, nil
}
开发者ID:sore0159,项目名称:overpower,代码行数:33,代码来源:commandPost.go

示例2: CommandQuitGame

func (h *Handler) CommandQuitGame(g overpower.GameDat, f overpower.FactionDat, turnStr string) (errServer, errUser error) {
	turnI, err := strconv.Atoi(turnStr)
	if err != nil || turnI != g.Turn() {
		return nil, NewError("FORM SUBMISSION TURN DOES NOT MATCH GAME TURN")
	}
	f.DELETE()
	return h.M.Close(), nil
}
开发者ID:sore0159,项目名称:overpower,代码行数:8,代码来源:commandPost.go

示例3: CommandDropGame

func (h *Handler) CommandDropGame(g overpower.GameDat) (errServer, errUser error) {
	if g == nil {
		return nil, NewError("USER HAS NO GAME IN PROGRESS")
	}
	g.DELETE()
	err := h.M.Close()
	if my, bad := Check(err, "drop game failure", "gid", g.GID()); bad {
		return my, nil
	}
	return nil, nil
}
开发者ID:sore0159,项目名称:overpower,代码行数:11,代码来源:commandPost.go

示例4: CommandSetAutos

func (h *Handler) CommandSetAutos(g overpower.GameDat, dayBools [7]bool) (errServer, errUser error) {
	if g == nil {
		return nil, NewError("USER HAS NO GAME IN PROGRESS")
	}
	g.SetAutoDays(dayBools)
	err := h.M.Close()
	if my, bad := Check(err, "command setauto failure on updating game", "game", g); bad {
		return my, nil
	}
	return nil, nil
}
开发者ID:sore0159,项目名称:overpower,代码行数:11,代码来源:commandPost.go

示例5: CommandDropFaction

func (h *Handler) CommandDropFaction(g overpower.GameDat, f overpower.FactionDat) (errServer, errUser error) {
	if g.Turn() > 0 {
		return nil, NewError("GAME IN PROGRESS")
	}
	if f == nil {
		return nil, NewError("USER HAS NO FACTION FOR THIS GAME")
	}
	f.DELETE()
	err := h.M.Close()
	if my, bad := Check(err, "command drop faction failure", "game", g, "faction", f); bad {
		return my, nil
	}
	return nil, nil
}
开发者ID:sore0159,项目名称:overpower,代码行数:14,代码来源:commandPost.go

示例6: CommandSetDoneBuffer

func (h *Handler) CommandSetDoneBuffer(g overpower.GameDat, f overpower.FactionDat, turnStr, buffStr string) (errServer, errUser error) {
	if g.Turn() < 1 {
		return nil, NewError("GAME HAS NOT YET BEGUN")
	}
	turnI, err := strconv.Atoi(turnStr)
	if err != nil || turnI != g.Turn() {
		return nil, NewError("FORM SUBMISSION TURN DOES NOT MATCH GAME TURN")
	}
	buffI, err := strconv.Atoi(buffStr)
	if err != nil {
		return nil, NewError("UNPARSABLE TURN BUFFER VALUE")
	}
	if buffI < 0 {
		buffI = -1
	}
	if buffI == f.DoneBuffer() {
		return nil, nil
	}
	return InternalSetDoneBuffer(f.GID(), f.FID(), buffI)
}
开发者ID:sore0159,项目名称:overpower,代码行数:20,代码来源:commandPost.go

示例7: CommandForceTurn

func (h *Handler) CommandForceTurn(g overpower.GameDat, turnStr string) (errServer, errUser error) {
	if g == nil {
		return nil, NewError("USER HAS NO GAME TO PROGRESS")
	}
	if g.Turn() < 1 {
		return nil, NewError("GAME HAS NOT YET BEGUN")
	}
	turnI, err := strconv.Atoi(turnStr)
	if err != nil || turnI != g.Turn() {
		return nil, NewError("FORM SUBMISSION TURN DOES NOT MATCH GAME TURN")
	}
	logE, failE := OPDB.SourceTransact(g.GID(), overpower.RunGameTurn)
	if my, bad := Check(failE, "failure on running turn", "gid", g.GID()); bad {
		return my, nil
	}
	if logE != nil {
		Log(logE)
	}
	return nil, nil
}
开发者ID:sore0159,项目名称:overpower,代码行数:20,代码来源:commandPost.go

示例8: CommandStartGame

func (h *Handler) CommandStartGame(g overpower.GameDat, facs []overpower.FactionDat, exodus bool) (errServer, errUser error) {
	if g == nil {
		return nil, NewError("USER HAS NO GAME TO START")
	}
	if g.Turn() > 0 {
		return nil, NewError("GAME ALREADY IN PROGRESS")
	}
	if len(facs) < 1 {
		return nil, NewError("GAME HAS NO PLAYERS")
	}
	f := func(source overpower.Source) (logE, failE error) {
		return nil, overpower.MakeGalaxy(source, exodus)
	}
	logE, failE := OPDB.SourceTransact(g.GID(), f)
	if my, bad := Check(failE, "command startgame failure", "gid", g.GID()); bad {
		return my, nil
	}
	if logE != nil {
		Log(logE)
	}
	return nil, nil
}
开发者ID:sore0159,项目名称:overpower,代码行数:22,代码来源:commandPost.go

示例9: pageOPHome

func pageOPHome(w http.ResponseWriter, r *http.Request) {
	h := MakeHandler(w, r)
	if !h.LoggedIn {
		http.Redirect(w, r, "/auth/login", http.StatusFound)
		return
	}
	if r.URL.Path != "/overpower/home" {
		http.Redirect(w, r, "/overpower/home", http.StatusFound)
		return
	}
	var hasG bool
	var g overpower.GameDat

	games, err := h.M.Game().Select("owner", h.User.String())
	if my, bad := Check(err, "resource failure on OP home page", "resource", "game", "owner", h.User.String()); bad {
		h.HandleServerError(w, r, my)
		return
	}
	if len(games) != 0 {
		g = games[0]
		hasG = true
	}

	var gFacs []overpower.FactionDat
	var gHasF bool
	if hasG {
		gFacs, err = h.M.Faction().SelectWhere(h.GID(g.GID()))
		if my, bad := Check(err, "resource error in homepage", "resource", "faction", "user", h.User, "gid", g.GID()); bad {
			h.HandleServerError(w, r, my)
			return
		}
		gHasF = len(gFacs) > 0
	}
	if r.Method == "POST" {
		if DBLOCK {
			h.HandleUserError(w, r, "GAME DOWN FOR DAYLY MAINT: 10-20MIN")
			return
		}
		action := r.FormValue("action")
		var errS, errU error
		switch action {
		case "nextturn":
			turn := r.FormValue("turn")
			errS, errU = h.CommandForceTurn(g, turn)
		case "setautos":
			dayBool := [7]bool{}
			dayBool[0] = r.FormValue("sunday") == "on"
			dayBool[1] = r.FormValue("monday") == "on"
			dayBool[2] = r.FormValue("tuesday") == "on"
			dayBool[3] = r.FormValue("wednesday") == "on"
			dayBool[4] = r.FormValue("thursday") == "on"
			dayBool[5] = r.FormValue("friday") == "on"
			dayBool[6] = r.FormValue("saturday") == "on"

			errS, errU = h.CommandSetAutos(g, dayBool)

		case "startgame":
			exodus := r.FormValue("exodus") == "on"
			errS, errU = h.CommandStartGame(g, gFacs, exodus)
		case "newgame":
			gamename, password := r.FormValue("gamename"), r.FormValue("password")
			facname, towin := r.FormValue("facname"), r.FormValue("towin")
			errS, errU = h.CommandNewGame(g, password, gamename, facname, towin)
		case "dropgame":
			errS, errU = h.CommandDropGame(g)
		default:
			errU = NewError("UNKNOWN ACTION TYPE")
		}
		if my, bad := Check(errS, "page op home action failure", "action", action, "user", h.User.String(), "game", g); bad {
			h.HandleServerError(w, r, my)
		} else if errU != nil {
			h.HandleUserError(w, r, errU.Error())
		} else {
			http.Redirect(w, r, r.URL.Path, http.StatusFound)
		}
		return
	}
	m := h.DefaultApp()
	m["user"] = h.User.String()
	if hasG {
		m["game"] = g
		m["active"] = g.Turn() > 0
	}
	if gHasF {
		m["gfactions"] = gFacs
		days := g.AutoDays()
		var any bool
		for _, b := range days {
			if b {
				any = true
				break
			}
		}
		if !any {
			m["noauto"] = true
		}
	}
	oFacs, err := h.M.Faction().Select("owner", h.User.String())
	if my, bad := Check(err, "resource error in homepage", "resource", "faction", "owner", h.User); bad {
		h.HandleServerError(w, r, my)
//.........这里部分代码省略.........
开发者ID:sore0159,项目名称:overpower,代码行数:101,代码来源:pageOPHome.go


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