自我娱乐斗地主

用VS写发牌的程序,在网页中显示

<!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <meta http-equiv="X-UA-Compatible" content="IE=edge">     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <title>Document</title>     <script>         // 1,创建牌         // 1.1 创捷4个花色         document.write("<hr/>");         var color = ["♠","♥","♣","♦"]         // 1.2 创建A~K         var ranks = ["A","2","3","4","5","6","7","8","9","10","J","Q","K"];         // 1.3 组合1.1和1.2         var cards = new Array(54);         var cardIndex = 0;

        for(var i=0;i<color.length;i++){             for(var j=0;j<ranks.length;j++){                 cards[cardIndex] = color[i] + ranks[j]                 cardIndex++;             }         }
        // 1.4 加大小王         cards[52] = "大王";         cards[53] = "小王";         document.write(cards);         document.write("<hr/>");         // 2,随机取牌         var handCards = new Array(17);         for (var i = 0; i < 17; i++){             var r = Math.random() * cards.length;             var rIndex = Math.floor(r);             var randomCard = cards[rIndex];             handCards[i] = randomCard;             cards.splice(rIndex, 1);         }         document.write("<hr/>");         handCards.sort();         document.write(handCards);     </script> </head> <body>     </body> </html>
上一篇:实现进制转换伪代码


下一篇:JavaScript 10.27