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


Golang GameDat.GID方法代碼示例

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


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

示例3: 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

示例4: 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

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