8.憋王八.rar

  • `chengyu
    了解作者
  • JavaScript
    开发工具
  • 15KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 0
    下载次数
  • 2021-03-09 20:32
    上传日期
玩家与两个计算机玩家对战,黑桃7先出,以4个花色的7为基准逐个接牌,两个王(八)永远是死牌不能出,无牌可接时则必须向下家要一张,最先出完的玩家是赢家,最后两个王八憋在谁手里了谁就输
8.憋王八.rar
  • 8.憋王八
  • SuffocateTurtles
  • .idea
  • misc.xml
    179B
  • workspace.xml
    8.7KB
  • modules.xml
    291B
  • SuffocateTurtles.iml
    469B
  • index.html
    40.1KB
  • poker.js
    28.5KB
内容介绍
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>憋王八</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]]); } } cards.push(['spades', 'joker']); // 小王 cards.push(['hearts', 'joker']); // 大王 // 模拟洗牌,打乱54张牌的顺序 for (var i = 0; i < 10; i++) { cards.sort(function () { return Math.random() - 0.5; }); } var playerCards = [[], [], []]; var deskCards = [[], [], [], []]; // 玩家和东家、西家轮流抓牌,随机决定谁先抓 var random = getRandom(0, 3); for (var i = 0; i < 18; i++) { playerCards[random].push([cards[3 * i][0], cards[3 * i][1]]); playerCards[(random + 1) % 3].push([cards[3 * i + 1][0], cards[3 * i + 1][1]]); playerCards[(random + 2) % 3].push([cards[3 * i + 2][0], cards[3 * i + 2][1]]); } for (var i = 0; i < 3; i++) { playerCards[i].sort(sortCards); } var hMidPos = 625; var hInterval = 24; var vMidPos = 150; var vInterval = 5; var nowPlaying; var compCanPlayCards; var winsIndex = -1; var borrowIndex = -1; var allowOperate = false; drawPlayerCards(); setTimeout(function () { // 黑桃7先出 for (var i = 0; i < 3; i++) { var pos = getIndexIn2dArray(playerCards[i], ['spades', '7']); if (pos !== -1) { play(i, pos); redraw(); nowPlaying = getNextPlayer(i); break; } } // 黑桃7出完之后从出黑桃7玩家的下家开始轮流出牌,若没牌可出则向该玩家的下家要一张牌,直到3个玩家中有2个玩家都出完了为止,此时两个王八肯定憋在了未出完的一个玩家手里,游戏结果为该玩家输了第一个出完的玩家赢了 setTimeout(userOrCompsPlay, 500); }, 500); 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; } } if (borrowIndex === -1) { if (!canPlay(playerCards[0][selectedIndex])) { alert('这张牌能出吗?看错了吧!'); allowOperate = true; return; } play(0, selectedIndex); if (playerCards[0].length === 0) { if (winsIndex === -1) winsIndex = 0; } nowPlaying = getNextPlayer(0); redraw(); setTimeout(userOrCompsPlay, 500); } else { lend(0, selectedIndex, borrowIndex); borrowIndex = -1; if (playerCards[0].length === 0) { if (winsIndex === -1) winsIndex = 0; nowPlaying = getNextPlayer(0); redraw(); setTimeout(userOrCompsPlay, 500); } else { nowPlaying = 0; redraw(); if (getCanPlayCards(0).length === 0) setTimeout(userOrCompsPlay, 500); else allowOperate = true; } } } else allowOperate = true; } }); function redraw() { domCanvas.width = domCanvas.width; // 清除canvas内容 drawPlayerCards(); drawDeskCards(); if (winsIndex !== -1) drawWinMsg(winsIndex); if (borrowIndex !== -1) drawBorrowMsg(borrowIndex); } // 绘制玩家和东家、西家手中的牌 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(100, vMidPos - (playerCards[2].length - 1) * vInterval / 2 + i * vInterval, cardHeight, '#5C72C2', '#2B4299'); } // 绘制桌面上已经出过的牌 function drawDeskCards() { for (var i = 0; i < 4; i++) { for (var j = 0; j < deskCards[i].length; j++) { var index = points.indexOf(deskCards[i][j][1]); canvas.drawPokerCard(469 + 100 * i, 2 + 22 * index, cardHeight, deskCards[i][j][0], deskCards[i][j][1]); } } } function drawWinMsg(i) { canvas.font = '75px "微软雅黑"'; canvas.fillStyle = '#F00'; if (i === 0) canvas.fillText('Win', 592, 538); else if (i === 1) canvas.fillText('Win', 1120, 200); else canvas.fillText('Win', 70, 200); } function drawBorrowMsg(i) { canvas.font = '20px "微软雅黑"'; canvas.fillStyle = '#FFF'; if (i === 0) canvas.fillText('出不去,要一张', 592, 425); el
评论
    相关推荐
    • 24-games.rar
      24点游戏,用C编写,可以运行。 输入四个数字,程序自动得出其于算法构成24的结果。
    • cards.rar
      小型老虎机实验,利用卡片随机呈现结果,功能简小,适合参考实验
    • javagames.zip
      java games template for deverloper
    • Games.rar
      Each suit has thirteen cards: an Ace, which is regarded as number 1 for this game cards numbered 2 to 10 inclusive. Each suit also four “face cards”: a Jack, number 11 for this game a Queen, number...
    • dofus-temporis-v-cards
      中华网 这个仓库是用于主机数据从DOFUS网站上的时间上的5事件网站。 解释说明 40x40精灵 /items/40/ 精灵200x200 /items/200/ 所有游戏项目 /items.json 格式范例: ... " name " : " Hache Ériphe " , ...
    • javascript_games:Javascript游戏
      Java脚本游戏 使用html5和javascript制作的游戏 记忆卡游戏 蛙人 马里奥 由制成,一个javascript html5引擎。 恩里克·德尔加多(Enrique Delgado)。
    • fend-project-memory-games
      记忆游戏项目 目录 指示 ... 您需要将该项目从静态项目转换为交互式项目。... 首先,打开js/app.js并开始构建应用程序的功能 有关特定的详细说明,请参见中的项目说明。 ...该存储库是所有Udacity学生的入门代码。...
    • ruby-playing-cards:一副实用的扑克牌
      从背后的人带给你 看看这些很棒的! 每周发布 1 个 15 分钟的演员表以及 2 分钟的 Ruby 或 2 分钟的 Rails 截屏视频! 纸牌 该库可让您访问一副实用的纸牌和一副 21 点纸牌...# many decks for games that require mu
    • card-games
      基本上是一堆乱七八糟的纸牌,以创建一些游戏并提高每个游戏中的技能。 首先在python中执行此操作,然后在javascript中执行此操作,然后在android中执行此操作 首先基本上很简单,然后再复杂一些,添加功能等。...
    • snowglobe-src-viewer-2.0.0-r0.tar.gz
      国外的开源游戏引擎,能够承载上千人,属于社交类的游戏