";
//登录页面
var htmlStart="";
//忙碌页面
var htmlCrowded="
Cowded....
房间好挤呀,你暂时进不来
";
6.2结构定义
用户对象
//状态定义
var INIT="INIT";//初始化
var WAITING="WAITING";//等待
var DISCARD="DISCARD";//发牌
var GAMEOVER="GAMEOVER";//游戏结束
var pkObj = {
data:{
status:INIT,
count:27,
pokers:[]
},
from:id,
to: fid,
success:0,
init:function (){
if(pkObj.data.status===INIT){
$("#login").click(doInit);
}
socketInit();
}
};
牌对象
var ONE = "ONE";
var TWO = "TWO";
var TWO_2 = "TWO_2";
var THREE = "THREE";
var THREE_2 = "THREE_2";
var THREE_3 = "THREE_3";
var FOUR = "FOUR";
var STRAIGHT = "STRAIGHT";
var ERROR = "ERROR";
var KING = "KING";
var poker= {
type: type, //类型
val: m, //大小
length: pokerList.length //张数
};
function doConfirm(pkObj) {
var count=0;
$(".display .poker").remove();
for(var i=0;i<27;i++){
var index=".poker"+i;
if($(index).hasClass('select')){
$(index).html();
$(".display").append($(index));
count++;
}
}
var sendMessage=$(".display").html();
pkObj.data.count-=count;
socket.emit('discard', pkObj, sendMessage);
$(".confirm").hide();
$(".no").hide();
}
放弃出牌
function doCancel() {
for(var i=0;i<13;i++){
var index=".choose .poker"+i;
if($(index).hasClass('select')){
$(index).removeClass('select');
$(index).animate({top:"+=50px"});
}
}
}
牌面大小转换
function myPoker(data) {
for(var i=0;i<27;i++){
var x=data.pokers[i]%13*(-90);
var y=parseInt(data.pokers[i]/13)*(-120);
var left=x+"px";
var top=y+"px";
var count;
//大王
if(data.pokers[i]===52)
count=17;
//小王
else if(data.pokers[i]===53)
count=16;
//A
else if((data.pokers[i]+11)%13===11){
count=14;
}
//2
else if((data.pokers[i]+11)%13===12){
count=15;
}
else {
count=(data.pokers[i])%13+1;
}
var pokeri="poker"+i;
var html = $("").addClass(pokeri).attr("data-value", count);
html.css({"background-position":left+" "+top});
$(".pokers").append(html);
}
}
接收牌
function doReceive(data,after) {
$(".confirm").show();
$(".no").show();
var before= $(".oppo-pokers").children().length;
for(var i=before;i>after;i--){
$(".oppo-pokers").children('.oppo-poker:last').remove();
}
if($(".display").children() != null){
$(".display .poker").remove();
}
$(".display").append(data);
}
牌型状态机
function typeState(type, n, m) {
switch (type) {
//单
case ONE:
if(n == m) {
type = TWO;
} else if(n == m +1 && m == 16) {
type = KING;
} else if(n == m + 1){
type = STRAIGHT;
} else {
type = ERROR;
}
break;
//对
case TWO:
if(n == m) {
type = THREE;
} else if(n == m + 1){
type = TWO_2;
} else {
type = ERROR;
}
break;
case TWO_2:
if(n == m) {
type = TWO;
} else {
type = ERROR;
}
break;
case THREE:
if(n == m) {
type = FOUR;
} else if(n == m + 1){
type = THREE_2;
} else {
type = ERROR;
}
break;
case THREE_2:
if(n == m) {
type = THREE_3;
} else {
type = ERROR;
}
break;
case THREE_3:
if(n == m) {
type = THREE;
} else {
type = ERROR;
}
break;
case STRAIGHT:
if(n == m + 1) {
type = STRAIGHT;
} else {
type = ERROR;
}
break;
default:
break
}
return type;
}
牌型获取
function getPokerType(pokerList) {
var type = ONE;
var n, m;
if(pokerList.length===1){
m=pokerList[0];
}
else {
for (var i = 0; i < pokerList.length; i++) {
n = pokerList[i];
m = pokerList[i + 1];
type = typeState(type, n, m);
}
if(type == TWO_2 || type == THREE_2 || type == THREE_3 || (type == STRAIGHT && pokerList.length < 5)) {
type = ERROR;
}
}
var poker= {
type: type,
val: m,
length: pokerList.length
};
return poker;
}
牌型大小比较
function comparePoker(pokerList,oppo_pokerList) {
var flag= false;
var data1 = getPokerType(oppo_pokerList); //对方的牌类型
var data2 = getPokerType(pokerList); //我的牌类型
if((data1.type == data2.type && (data1.length == data2.length) && pokerList[0] > oppo_pokerList[0]) || (data1.type != FOUR && data2.type == FOUR) || (data2.type == KING)) {
flag= true;
}
//flag为true可出牌,否则不能出牌
return flag;
}
利用javascript读取表单数据,可以利用以下三种方法获取:
1、通过表单ID属性:var a = document.getElementByIdx_x_x("id");
2、通过表单名称属性:var b = document.getElementsByName("name");
3、直接通过表单名字获取:var c = form.content.
什么是Spring Data Mongo
Spring Data MongoDB项目对访问MongoDB的Java客户端API进行了封装,这种封装类似于Spring封装Hibernate和JDBC而提供的HibernateTemplate和JDBCTemplate,主要能力包括
1. 封装客户端跟MongoDB的链接管理
2. 文档-对象映射,通过注解:@Document(collectio
The insertion algorithm for 2-3 trees just described is not difficult to understand; now, we will see that it is also not difficult to implement. We will consider a simple representation known