func (room *DixitRoom) Guess(uid string, card int) { room.guess[uid] = card flag := true for _, u := range room.gworkRoom.Userlist { if u.Uid != room.host { _, exist := room.guess[u.Uid] if exist == false { flag = false } } } if flag == true { score, gameover := gameResult(room) room.score = score cards := room.falsecard cards[room.host] = room.realcard replyBody := make(map[string]interface{}) replyBody["type"] = "result" replyBody["gameover"] = gameover replyBody["cards"] = cards replyBody["score"] = score if gameover == false { fillCards := room.roundInit() replyBody["round"] = room.round replyBody["host"] = room.host for _, u := range room.gworkRoom.Userlist { replyBody["fillcard"] = fillCards[u.Uid] room.gworkRoom.Push(u, gwork.JsonEncode(replyBody)) } } else { room.gworkRoom.Broadcast(gwork.JsonEncode(replyBody)) } } DixitRoomList[room.RoomId] = *room }
func (room *DixitRoom) GuestPick(uid string, card int) { room.falsecard[uid] = card flag := true for _, u := range room.gworkRoom.Userlist { if u.Uid != room.host { _, exist := room.falsecard[u.Uid] if exist == false { flag = false } } } if flag == true { cards := []int{} for _, c := range room.falsecard { cards = append(cards, c) } cards = append(cards, room.realcard) sort.Ints(cards) replyBody := make(map[string]interface{}) replyBody["type"] = "showcards" replyBody["cards"] = cards room.gworkRoom.Broadcast(gwork.JsonEncode(replyBody)) } DixitRoomList[room.RoomId] = *room }
func (room *DixitRoom) StartGame(creator string) { gwork.MysqlQuery("UPDATE `game` SET status = 1 WHERE `id`= " + room.RoomId) room.host = creator room.score = make(map[string]int) room.round = 1 room.realcard = 0 room.falsecard = make(map[string]int) room.guess = make(map[string]int) room.keyword = "" var stack []int for index := 1; index < MAX_CARD_NUM+1; index++ { stack = append(stack, index) } room.cardStack = stack //抽牌 for _, user := range room.gworkRoom.Userlist { cards, cardStack := drawCards(6, room.cardStack) room.cardStack = cardStack //user.cards = cards // room.Userlist[index] = user replyBody := make(map[string]interface{}) replyBody["type"] = "start" replyBody["cards"] = cards replyBody["host"] = room.host room.gworkRoom.Push(user, gwork.JsonEncode(replyBody)) } DixitRoomList[room.RoomId] = *room }
func (room *DixitRoom) HostPick(keyword string, card int) { room.keyword = keyword room.realcard = card reply := make(map[string]string) reply["type"] = "hostpick" reply["keyword"] = keyword replyBody := gwork.JsonEncode(reply) room.gworkRoom.Broadcast(replyBody) DixitRoomList[room.RoomId] = *room }