10.24点.rar

  • `chengyu
    了解作者
  • JavaScript
    开发工具
  • 13KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 0
    下载次数
  • 2021-03-09 20:41
    上传日期
玩家与三个计算机玩家对战,头一轮玩家先出,从第二轮开始上一轮第二个出牌的先出,当某一轮中4张牌点数之和恰为24时玩家胜,若所有牌全部出完每一轮4张牌点数之和都不是24则计算机胜
10.24点.rar
  • 10.24点
  • 24Points
  • .idea
  • 24Points.iml
    469B
  • modules.xml
    275B
  • workspace.xml
    7.5KB
  • poker.js
    28.5KB
  • index.html
    24.6KB
内容介绍
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>24点</title> </head> <body bgcolor="green"> <div id="container"> &nbsp; </div> </body> <script src="./poker.js"></script> <script> if (window.Poker) { init(); function init() { var container = document.getElementById('container'); var domCanvas = document.createElement('canvas'); var canvas = domCanvas.getContext('2d'); container.appendChild(domCanvas); domCanvas.height = 600; domCanvas.width = 1300; var cardWidth = 90; var cardHeight = 120; var suits = ['spades', 'hearts', 'diamonds', 'clubs']; var points = ['a', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'j', 'q', 'k']; var cards = []; for (var i = 0; i < 4; i++) { for (var j = 0; j < 13; j++) { cards.push([suits[i], points[j]]); } } // 模拟洗牌,打乱52张牌的顺序 for (var i = 0; i < 10; i++) { cards.sort(function () { return Math.random() - 0.5; }); } var playerCards = [[], [], [], []]; var deskCards = []; // 玩家和东家、北家、西家轮流抓牌 for (var i = 0; i < 13; i++) { playerCards[0].push([cards[4 * i][0], cards[4 * i][1]]); playerCards[1].push([cards[4 * i + 1][0], cards[4 * i + 1][1]]); playerCards[2].push([cards[4 * i + 2][0], cards[4 * i + 2][1]]); playerCards[3].push([cards[4 * i + 3][0], cards[4 * i + 3][1]]); } for (var i = 0; i < 4; i++) { playerCards[i].sort(sortCards); } var hMidPos = 625; var hInterval = 24; var vMidPos = 240; var vInterval = 5; var nowPlaying = 0; var sumPoints = 0; var playerPlayed; var playerHasnotPoints; var compPreparePlay; drawPlayerCards(); canvas.font = '20px "微软雅黑"'; canvas.fillStyle = '#FFF'; canvas.fillText('当某一轮中4张牌点数之和为24时玩家胜,若所有牌全部出完每一轮4张牌点数之和都不是24则计算机胜', 200, 590); var allowOperate = true; domCanvas.addEventListener('click', function (e) { if (allowOperate) { allowOperate = false; if (e.y >= 460 && e.y < 460 + cardHeight && e.x < hMidPos + (playerCards[0].length - 1) * hInterval / 2 + cardWidth + 16) { var selectedIndex; for (var i = playerCards[0].length - 1; i >= 0; i--) { if (e.x >= hMidPos - (playerCards[0].length - 1) * hInterval / 2 + i * hInterval + 16) { selectedIndex = i; break; } } play(0, selectedIndex); if (deskCards.length === 4) { if (sumPoints === 24) { redraw(); alert('恭喜,您赢了!'); return; } nowPlaying = 2; // 该轮中第2个出牌的玩家下一轮先出 redraw(); deskCards = []; sumPoints = 0; playerPlayed = false; setTimeout(userOrCompsPlay, 1000); return; } nowPlaying = getNextPlayer(nowPlaying); redraw(); setTimeout(userOrCompsPlay, 500); } else allowOperate = true; } }); function redraw() { domCanvas.width = domCanvas.width; // 清除canvas内容 drawPlayerCards(); drawDeskCards(); } // 绘制玩家和东家、北家、西家手中的牌 function drawPlayerCards() { for (var i = 0; i < playerCards[0].length; i++) canvas.drawPokerCard(hMidPos - (playerCards[0].length - 1) * hInterval / 2 + i * hInterval, 450, cardHeight, playerCards[0][i][0], playerCards[0][i][1]); for (var i = 0; i < playerCards[1].length; i++) canvas.drawPokerBack(1150, vMidPos - (playerCards[1].length - 1) * vInterval / 2 + i * vInterval, cardHeight, '#5C72C2', '#2B4299'); for (var i = 0; i < playerCards[2].length; i++) canvas.drawPokerBack(hMidPos - (playerCards[2].length - 1) * hInterval / 2 + i * hInterval, 30, cardHeight, '#5C72C2', '#2B4299'); for (var i = 0; i < playerCards[3].length; i++) canvas.drawPokerBack(100, vMidPos - (playerCards[3].length - 1) * vInterval / 2 + i * vInterval, cardHeight, '#5C72C2', '#2B4299'); } // 绘制桌面上已经出过的牌 function drawDeskCards() { for (var i = 0; i < deskCards.length; i++) { switch (deskCards[i][1]) { case 0: canvas.drawPokerCard(hMidPos, vMidPos + 2 * cardHeight / 3, cardHeight, deskCards[i][0][0], deskCards[i][0][1]); break; case 1: canvas.drawPokerCard(hMidPos + 2 * cardWidth / 3, vMidPos, cardHeight, deskCards[i][0][0], deskCards[i][0][1]); break; case 2: canvas.drawPokerCard(hMidPos, vMidPos - 2 * cardHeight / 3, cardHeight, deskCards[i][0][0], deskCards[i][0][1]); break; case 3: canvas.drawPokerCard(hMidPos - 2 * cardWidth / 3, vMidPos, cardHeight, deskCards[i][0][0], deskCards[i][0][1]); } } } function getPoint(card) { return points.indexOf(card[1]) + 1; } function play(i, pos) { var card = playerCards[i].splice(pos, 1)[0]; deskCards.push([card, i]); if (i === 0) { playerPlayed = true; playerHasnotPoints = getPlayerHasnotPoints(); compPreparePlay = [null, null, null]; } sumPoints += getPoint(card); } function userOrCompsPlay() { if (playerCards[0].length === 0 && playerCards[1].length === 0 && playerCards[2].length === 0 && playerCards[3].length === 0) { alert('很遗憾,您输了!'); return; } if (nowPlaying === 0) { redraw(); allowOperate = true; return; } play(nowPlaying, compPlay(nowPlaying)); if (deskCards.length === 4) { if (sumPoints === 24) { redraw(); alert('恭喜,您赢了!'); return; } nowPlaying = deskCards[1][1]; // 该轮中第2个出牌的玩家下一轮先出 redraw(); deskCards = [
评论
    相关推荐
    • 24points.rar
      一个24点计算游戏。输入4个数,计算结果.
    • 24Points.rar
      四 张 牌 算 24 点 、4 个 数 字 算 出 24
    • 24points.rar
      纸牌游戏,24点,非常简单的实现,没有做界面在DOS上实现的,基本功能可以完成
    • 24points.rar
      实现24点小游戏,要求四个数字运算结果等于二十四,用C实现
    • 24points.rar
      用C语言编的 计算 24点的程序.中文操作界面
    • 24points.rar
      用C语言编的 计算 24点的程序.中文操作界面
    • Calculate24Points.rar
      个1~9之间的自然数作为操作数,而您的任务是对这4个操作数进行适当的算术运算,要求运算结果等于24。可以使用的运算只有:+,
    • 24points.rar
      能够产生随机数 然后运行24点程序也可以系统自动生成
    • 24points.rar
      24点问题~ 就是计算四个相同的数通过加减乘除和括号得到24
    • 24points.rar
      用C语言编的 计算 24点的程序.中文操作界面