/// <summary> /// 判断游戏是否结束 /// </summary> /// <returns>2 - 赢了; 1 - 输了; 0 - 还没结束</returns> public int isOver() { int fromP = 0; //右边牧师人数 int fromD = 0; //右边魔鬼人数 int toP = 0; //左边牧师人数 int toD = 0; //左边魔鬼人数 //获取右边对应的人数 int[] fromCount = fromLand.getChaNum(); fromP += fromCount[0]; fromD += fromCount[1]; //获取左边对应的人数 int[] toCount = toLand.getChaNum(); toP += toCount[0]; toD += toCount[1]; //如果左边有六个人,证明全部安全过河,你赢了 if (toP + toD == 6) { return(2); } //将船上人的数目也加上去 int[] boatCount = boat.getChaNum(); if (boat.getOnWhere() == -1) { toP += boatCount[0]; toD += boatCount[1]; } else { fromP += boatCount[0]; fromD += boatCount[1]; } //如果任意一边牧师人数少于魔鬼,你输了 if (fromP < fromD && fromP > 0 || toP < toD && toP > 0) { return(1); } return(0); }