猜颜色优化
This commit is contained in:
parent
7ae38d5cf9
commit
0c335a1a47
@ -9,15 +9,11 @@ import (
|
||||
|
||||
const (
|
||||
CFG_GUESS_COLOR_TEMPLATE = "GuessColorTemplate"
|
||||
CFG_GUESS_COLOR_PASS = "GuessColorPass"
|
||||
CFE_GUESS_COLOR_JACKPOT = "GuessColorJackpot"
|
||||
CFG_GUESS_COLOR_REWARD = "GuessColorReward"
|
||||
)
|
||||
|
||||
func init() {
|
||||
gamedata.InitCfg(CFG_GUESS_COLOR_TEMPLATE)
|
||||
gamedata.InitCfg(CFG_GUESS_COLOR_PASS)
|
||||
gamedata.InitCfg(CFE_GUESS_COLOR_JACKPOT)
|
||||
gamedata.InitCfg(CFG_GUESS_COLOR_REWARD)
|
||||
}
|
||||
|
||||
@ -59,35 +55,35 @@ func GetActivityItemId(Id int) int {
|
||||
return gamedata.GetIntValue(data, "ItemId")
|
||||
}
|
||||
|
||||
func GetRewardItem(Id int) []*item.Item {
|
||||
func GetRewardItem(Id int, Type int) []*item.Item {
|
||||
data, err := gamedata.GetDataByIntKey(CFG_GUESS_COLOR_REWARD, Id)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return gamedata.GetItemList(data, "Items")
|
||||
}
|
||||
|
||||
func GetJackpot() []int {
|
||||
data, err := gamedata.GetData(CFE_GUESS_COLOR_JACKPOT)
|
||||
if err != nil {
|
||||
return []int{}
|
||||
if Type == 1 {
|
||||
return gamedata.GetItemList(data, "Items1")
|
||||
}
|
||||
result := make([]int, 0)
|
||||
for k := range data {
|
||||
result = append(result, GoUtil.Int(k))
|
||||
}
|
||||
return result
|
||||
return gamedata.GetItemList(data, "Items2")
|
||||
}
|
||||
|
||||
func GetPassNum(Pass int) int {
|
||||
data, err := gamedata.GetData(CFG_GUESS_COLOR_PASS)
|
||||
data, err := gamedata.GetDataByIntKey(CFG_GUESS_COLOR_REWARD, Pass)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
for _, v := range data {
|
||||
if gamedata.GetIntValue(v, "Min") <= Pass && gamedata.GetIntValue(v, "Max") >= Pass {
|
||||
return gamedata.GetIntValue(v, "Num")
|
||||
}
|
||||
}
|
||||
return 0
|
||||
return gamedata.GetIntValue(data, "Num")
|
||||
}
|
||||
|
||||
func GetWinTime(Pass int) int {
|
||||
data, err := gamedata.GetDataByIntKey(CFG_GUESS_COLOR_REWARD, Pass)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
Type := gamedata.GetIntValue(data, "Type")
|
||||
if Type == 1 {
|
||||
return gamedata.GetIntValue(data, "Win")
|
||||
}
|
||||
str := gamedata.GetStringValue(data, "Win")
|
||||
arr := strings.Split(str, "|")
|
||||
return GoUtil.RandNum(GoUtil.Int(arr[0]), GoUtil.Int(arr[1]))
|
||||
}
|
||||
|
||||
@ -97,15 +97,6 @@ func GuessColorBackData(p *Player) {
|
||||
}
|
||||
Status := GetActivityStatus(p, ACT_TYPE_GUESS_COLOR)
|
||||
GuessColorMod := p.PlayMod.getGuessColorMod()
|
||||
Color := make([]int32, 0)
|
||||
Pos := make([]int32, 0)
|
||||
for k, v := range GuessColorMod.Answer {
|
||||
if GuessColorMod.Progress[k] > 0 {
|
||||
Pos = append(Pos, int32(k))
|
||||
continue
|
||||
}
|
||||
Color = append(Color, int32(v))
|
||||
}
|
||||
p.PushClientRes(&msg.ResGuessColor{
|
||||
Id: int32(ActivityInfo.Id),
|
||||
Status: int32(Status),
|
||||
@ -117,8 +108,9 @@ func GuessColorBackData(p *Player) {
|
||||
Avatar: int32(GuessColorMod.Opponent.Avatar),
|
||||
Progress: int32(GuessColorMod.Opponent.Progress),
|
||||
},
|
||||
Color: Color,
|
||||
Pos: Pos,
|
||||
WinTime: int32(GuessColorMod.WinTime),
|
||||
Map: GuessColorMod.Map,
|
||||
OMap: GuessColorMod.OMap,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -2884,7 +2884,7 @@ func ReqGuessColorTake(player *Player, buf []byte) error {
|
||||
})
|
||||
return err
|
||||
}
|
||||
GuessColorMod.Take(req.Map)
|
||||
GuessColorMod.Take(req.Map, req.OMap)
|
||||
player.PlayMod.save()
|
||||
GuessColorBackData(player)
|
||||
player.NotifyRed(ACT_TYPE_GUESS_COLOR)
|
||||
|
||||
@ -12,9 +12,11 @@ type GuessColorMod struct {
|
||||
Id int
|
||||
Pass int
|
||||
Opponent simplePlayer
|
||||
Answer map[int]int
|
||||
Progress map[int]int
|
||||
Map map[int32]int32
|
||||
OMap map[int32]int32
|
||||
WinTime int
|
||||
First bool
|
||||
Guess int
|
||||
}
|
||||
|
||||
type simplePlayer struct {
|
||||
@ -24,12 +26,21 @@ type simplePlayer struct {
|
||||
Progress int
|
||||
}
|
||||
|
||||
const (
|
||||
GAME_STATUS_SUCCESS = 1
|
||||
GAME_STATUS_FAIL = 2
|
||||
)
|
||||
|
||||
func (g *GuessColorMod) InitData() {
|
||||
if g.Answer == nil {
|
||||
g.Answer = make(map[int]int)
|
||||
if g.Map == nil {
|
||||
g.Map = make(map[int32]int32)
|
||||
}
|
||||
if g.Progress == nil {
|
||||
g.Progress = make(map[int]int)
|
||||
if g.OMap == nil {
|
||||
g.OMap = make(map[int32]int32)
|
||||
}
|
||||
if g.Pass == 0 {
|
||||
g.Pass = 1
|
||||
g.WinTime = guesscolorCfg.GetWinTime(g.Pass)
|
||||
}
|
||||
if g.Opponent.Name == "" {
|
||||
g.Opponent = simplePlayer{
|
||||
@ -56,10 +67,9 @@ func (g *GuessColorMod) Login(Id int) {
|
||||
Avatar: GoUtil.RandNum(1, 10),
|
||||
Progress: 0,
|
||||
}
|
||||
g.Answer = make(map[int]int)
|
||||
g.Progress = make(map[int]int)
|
||||
FirstPass := guesscolorCfg.GetFirstPass(Id)
|
||||
g.Answer = FirstPass
|
||||
g.Guess = 0
|
||||
g.Map = make(map[int32]int32)
|
||||
g.OMap = make(map[int32]int32)
|
||||
}
|
||||
|
||||
func (g *GuessColorMod) ZeroUpdate(Id int) {
|
||||
@ -74,12 +84,10 @@ func (g *GuessColorMod) FirstIn() []*item.Item {
|
||||
return guesscolorCfg.GetFirstItem(g.Id)
|
||||
}
|
||||
|
||||
func (g *GuessColorMod) Take(Map map[int32]int32) {
|
||||
for k, v := range Map {
|
||||
if g.Answer[int(k)] == int(v) {
|
||||
g.Progress[int(k)] = int(v)
|
||||
}
|
||||
}
|
||||
func (g *GuessColorMod) Take(Map map[int32]int32, OMap map[int32]int32) {
|
||||
g.Map = Map
|
||||
g.OMap = OMap
|
||||
g.Guess++
|
||||
}
|
||||
|
||||
func (g *GuessColorMod) GetLoseItem() []*item.Item {
|
||||
@ -87,21 +95,22 @@ func (g *GuessColorMod) GetLoseItem() []*item.Item {
|
||||
}
|
||||
|
||||
func (g *GuessColorMod) GetReward() ([]*item.Item, error) {
|
||||
if len(g.Answer) != len(g.Progress) {
|
||||
return nil, fmt.Errorf("guess color progress error")
|
||||
if g.Pass == 0 {
|
||||
return nil, fmt.Errorf("not pass")
|
||||
}
|
||||
RewardId := 1
|
||||
if g.Opponent.Progress == len(g.Answer) {
|
||||
RewardId = 2
|
||||
}
|
||||
Item := guesscolorCfg.GetRewardItem(RewardId)
|
||||
g.Pass++
|
||||
Num := guesscolorCfg.GetPassNum(g.Pass)
|
||||
ColorList := guesscolorCfg.GetJackpot()
|
||||
RandList := GoUtil.RandSliceNum(ColorList, Num)
|
||||
g.Progress = make(map[int]int)
|
||||
for k, v := range RandList {
|
||||
g.Answer[k+1] = v
|
||||
if g.Guess < Num {
|
||||
return nil, fmt.Errorf("guess process not finish")
|
||||
}
|
||||
Type := GAME_STATUS_FAIL
|
||||
if g.Guess == guesscolorCfg.GetPassNum(g.Pass) {
|
||||
Type = GAME_STATUS_SUCCESS
|
||||
}
|
||||
Item := guesscolorCfg.GetRewardItem(g.Pass, Type)
|
||||
g.Pass++
|
||||
g.Guess = 0
|
||||
g.WinTime = guesscolorCfg.GetWinTime(g.Pass)
|
||||
g.Map = make(map[int32]int32)
|
||||
g.OMap = make(map[int32]int32)
|
||||
return Item, nil
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user