var game = {
conf:roomInfo.conf,
roomInfo:roomInfo,
gameIndex:roomInfo.numOfGames,
button:roomInfo.nextButton,
mahjongs:new Array(108),
currentIndex:0,
gameSeats:new Array(4),
numOfQue:0,
turn:0,
chuPai:-1,
state:"idle",
firstHupai:-1,
yipaoduoxiang:-1,
fangpaoshumu:-1,
actionList:[],
chupaiCnt:0,
};
代表一局游戏对象
conf,游戏相关参数配置
roomInfo,游戏相关房间信息
gameIndex,当前在第几局游戏
button,游戏出牌方
mahjongs,游戏中的麻将对象,相当于牌,共108张
currentIndex,待定
gameSeats,游戏中的座位
numOfQue,待定
turn,轮到谁出牌
chuPai,待定
state,当前游戏状态
firstHupai,待定
yipaoduoxiang,待定
fangpaoshumu,待定
actionList,动作列表
chupaiCnt,待定
接下来是gameSeat对象
for(var i = 0; i < 4; ++i){
var data = game.gameSeats[i] = {};
data.game = game;
data.seatIndex = i;
data.userId = seats[i].userId;
//持有的牌
data.holds = [];
//打出的牌
data.folds = [];
//暗杠的牌
data.angangs = [];
//点杠的牌
data.diangangs = [];
//弯杠的牌
data.wangangs = [];
//碰了的牌
data.pengs = [];
//缺一门
data.que = -1;
//换三张的牌
data.huanpais = null;
//玩家手上的牌的数目,用于快速判定碰杠
data.countMap = {};
//玩家听牌,用于快速判定胡了的番数
data.tingMap = {};
data.pattern = "";
//是否可以杠
data.canGang = false;
//用于记录玩家可以杠的牌
data.gangPai = [];
//是否可以碰
data.canPeng = false;
//是否可以胡
data.canHu = false;
//是否可以出牌
data.canChuPai = false;
//如果guoHuFan >=0 表示处于过胡状态,
//如果过胡状态,那么只能胡大于过胡番数的牌
data.guoHuFan = -1;
//是否胡了
data.hued = false;
//
data.actions = [];
//是否是自摸
data.iszimo = false;
data.isGangHu = false;
data.fan = 0;
data.score = 0;
data.huInfo = [];
data.lastFangGangSeat = -1;
//统计信息
data.numZiMo = 0;
data.numJiePao = 0;
data.numDianPao = 0;
data.numAnGang = 0;
data.numMingGang = 0;
data.numChaJiao = 0;
gameSeatsOfUsers[data.userId] = data;
}
gameSeatsOfUsers[data.userId] = data;包含的是userId对应的gameSeats对象
rooms对象是roomInfo对象的集合列表
var roomInfo = {
uuid:dbdata.uuid,
id:dbdata.id,
numOfGames:dbdata.num_of_turns,
createTime:dbdata.create_time,
nextButton:dbdata.next_button,
seats:new Array(4),
conf:JSON.parse(dbdata.base_info)
};
uuid,房间的uuid
id,房间id
numOfgames,游戏总局数
createTime,创建时间
nextButton,待定
seats,游戏内的座位对象
conf,房间参数配置
for(var i = 0; i < 4; ++i){
var s = roomInfo.seats[i] = {};
s.userId = dbdata["user_id" + i];
s.score = dbdata["user_score" + i];
s.name = dbdata["user_name" + i];
s.ready = false;
s.seatIndex = i;
s.numZiMo = 0;
s.numJiePao = 0;
s.numDianPao = 0;
s.numAnGang = 0;
s.numMingGang = 0;
s.numChaJiao = 0;
if(s.userId > 0){
userLocation[s.userId] = {
roomId:roomId,
seatIndex:i
};
}
}
seat对象
userId,用户id
score,用户积分
name,用户姓名
ready,是否准备好
seatIndex,用户座位号
numZiMo,自摸数量
numJiePao,待定
numDianPao,点炮数量
numAnGang,暗杠数量
numMingGang,明杠数量
numChaJiao,待定
userLocation[userId] = {
roomId:roomId,
seatIndex:i
};
用户坐标数组,是用户id和坐标信息的对应关系,包括,房间id和座位号