html5扑克源码,扑克牌代码该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
var compeleteCards = new Array();
var mytimer;
var cardSequence = 1;
var player1 = new Array();
//储存玩家⼀的⼿牌
var player2 = new Array();
//储存玩家⼆的⼿牌
var player3 = new Array();
//储存玩家三的⼿牌
var player4 = new Array();
/
/储存玩家四的⼿牌
function Cards(number,type){
var card = {
number: number,
type: type
}
return card;
}
function CreatCompeleteCard() {
var arr = new Array();
for (var i = 3; i <= 15; i++) {
for (var j = 1; j <= 4; j++) {
var card = Cards(i, j);
arr.push(card);
}
}
return arr;
}
function Show() {
function typeShow(type) {
var t;
switch(type) {
html导航源码t = "♠";
break;
case 2:
t = "♣";
break;
case 3:
t = "♦";
break;
case 4:
t = "♥";
break;
}
return t;
};
function numberShow(number) { var n = number;
switch(number) {
case 11:
n = "J";
break;
case 12:
n = "Q";
break;
case 13:
n = "K";
break;
case 14:
n = "A";
break;
case 15:
n = "2";
break;
}
};
function arrayToShow(array, id) {
var html = "";
for (var i = 0; i < array.length; i++) {
html += "
" + typeShow(array[i].type) + "
" + numberShow(array[i].number) + "
";
}
};
arrayToShow(compeleteCards, "compeleteCards");
arrayToShow(player1, "player1");
arrayToShow(player2, "player2");
arrayToShow(player3, "player3");
arrayToShow(player4, "player4");
}
function SortCards() {
if (compeleteCards.length == 52) {
compeleteCards.sort(function(a, b) {
return 0.5 - Math.random();
});
}
}
function DealCards() {
if (compeleteCards.length == 52) {
mytimer = setInterval("GetCards(compeleteCards.shift())", 100); }
}
function GetCards(CardObj) {
switch(cardSequence) {
case 1:
var k = InCardsIndex(player1, CardObj);
player1.splice(k, 0, CardObj);
cardSequence = 2;
break;
case 2:
var k = InCardsIndex(player2, CardObj); player2.splice(k, 0, CardObj); cardSequence = 3;
break;
case 3:
var k = InCardsIndex(player3, CardObj); player3.splice(k, 0, CardObj); cardSequence = 4;
break;
case 4:
var k = InCardsIndex(player4, CardObj); player4.splice(k, 0, CardObj); cardSequence = 1;
break;
}
if (compeleteCards.length == 0) { window.clearTimeout(mytimer);
}
Show();
}
//在此添加代码
function InCardsIndex(arr, obj) {
var len = arr.length;
if (len == 0) {
return 0;
} else if (len == 1) {
if (obj.number >= arr[0].number) { return 1;
} else {
return 0;
}
} else {
var backi = -1;
for (var i = 0; i < len; i++) {
if (obj.number <= arr[i].number) {
backi = i;
break;
}
}
if (backi == -1) {
backi = len;
}
return backi;
}
}
Show();
};
Show();
};
};
想要学习前端开发的同学,可以加:543#6273@93
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论