/* 「七並べ」 2004/06/19版 THU madpoet@thu.sakura.ne.jp http://thu.sakura.ne.jp/ */ // 七並べクラス function FantanDomino() { this.id = arguments[0]; var node; if(!(node = document.getElementById(this.id))) { return false; } this.size = 4; // サイズ基本値 this.bgColor = 'limegreen'; // 背景色 this.activeColor = 'white'; // アクティブ時の色 this.waitTime = 1000; // 待ち時間 this.playerModel = new Array(); this.playerModel[0] = new PlayerModel(this, '_pl0', 'トンヌラ', 1); this.playerModel[1] = new PlayerModel(this, '_pl1', 'ナマグサ', 2); this.playerModel[2] = new PlayerModel(this, '_pl2', 'シメサバ', 3); this.playerModel[3] = new PlayerModel(this, '_pl3', 'あなた ', 0); this.pl = this.playerModel[3]; var i; for (i = 1; i < arguments.length; i++) { if (i == 1) { this.size = arguments[i]; } else if (i == 2) { this.bgColor = arguments[i]; } else if (i == 3) { this.waitTime = arguments[i]; } else if (i == 4) { this.playerModel[0].name = arguments[i]; } else if (i == 5) { this.playerModel[1].name = arguments[i]; } else if (i == 6) { this.playerModel[2].name = arguments[i]; } else if (i == 7) { this.playerModel[3].name = arguments[i]; } } if (this.size < 3) { this.size = 3; } this.debug = false; this.ie = false; var agt = navigator.appName; if (agt.match(/Internet Explorer/)){ this.ie = true; } this.fontSize = Math.floor(this.size * 2.5); this.miniFontSize = this.size * 2; this.lineHeight = this.size * 3 - 1; this.mode = 'start'; this.lastStage = 3; this.stage = 0; this.level = 0; this.beforeTurn = 0; this.joker = true; this.redeal = true; this.pointList = new Array(); this.pointList[0] = 50; // 配り直し時にマイナスされる点数 this.pointList[1] = 200; // 一位で勝利 this.pointList[2] = 100; // 二位で勝利 this.pointList[3] = 50; // 三位で勝利 this.pointList[4] = 25; // 四位で勝利 this.pointList[5] = -100; // 一番目に負け this.pointList[6] = -50; // 二番目に負け this.pointList[7] = -25; // 三番目に負け this.pointList[8] = -20; // 四番目に負け this.card = new TableCard(this.size); this.cardSelect = new Array(); this.cardSelect[0] = new TableCard(this.size, 'black', 'yellow'); this.cardSelect[1] = new TableCard(this.size, 'black', 'lemonchiffon'); this.fieldSet(); this.init(); this.stageView(); this.buttonSet('start'); } // 七並べ:初期化 FantanDomino.prototype.init = function() { this.win = 0; this.lose = 0; this.setInit(); for (i = 0; i < 4; i++) { this.playerModel[i].init(); } } // 七並べ:初期セット FantanDomino.prototype.setInit = function() { var i, j; var id, parts; for (j = 0; j < 4; j++) { for (i = 1; i <= 13; i++) { id = this.id + '_card' + j + '_' + i; if (i == 7) { parts = ''; } else { parts = 'left'; } this.card.noneView(id, this.bgColor, parts); } } id = this.id + '_hand0'; this.card.noneView(id, this.bgColor, 'left'); } // 七並べ:フィールドのセット FantanDomino.prototype.fieldSet = function() { this.card.clear(this.id); var node; node = document.getElementById(this.id); var i, j, k, id, str; var nTable, nTbody, nTr, nTd, nTable2, nTbody2, nTr2, nTd2; var nTable3, nTbody3, nTr3, nTd3, nP, nDiv, nSpan, nForm; nTable = document.createElement('table'); nTable.cellPadding = this.size * 2; nTable.style.backgroundColor = this.bgColor; nTable.style.width = this.size * 103 + 'pt'; nTbody = document.createElement('tbody'); nTr = document.createElement('tr'); nTd = document.createElement('td'); nTd.rowSpan = 2; nTable2 = document.createElement('table'); nTable2.cellPadding = 1; nTbody2 = document.createElement('tbody'); for (i = 0; i < 4; i++) { id = this.id + '_pl' + i; nTr2 = document.createElement('tr'); nTd2 = document.createElement('td'); nTd2.id = id; nTd2.vAlign = 'top'; nTd2.style.border = '1pt solid black'; nTable3 = document.createElement('table'); nTable3.cellPadding = 0, nTable3.cellSpacing = 0; nTbody3 = document.createElement('tbody'); nTr3 = document.createElement('tr'); nTd3 = document.createElement('td'); nTd3.align = 'center'; nTd3.style.width = this.size * 16 + 'pt'; nTd3.style.color = 'black'; nTd3.style.fontSize = this.fontSize + 'pt'; nTd3.style.lineHeight = this.lineHeight + 'pt'; nSpan = document.createElement('span'); nSpan.id = id + '_name'; nSpan.style.fontWeight = 'bold'; str = this.playerModel[i].name; nSpan.appendChild(document.createTextNode(str)); nTd3.appendChild(nSpan); nTd3.appendChild(document.createElement('br')); nSpan = document.createElement('span'); nSpan.id = id + '_point'; nSpan.style.fontSize = this.miniFontSize + 'pt'; nSpan.appendChild(document.createTextNode('0')); nTd3.appendChild(nSpan); nTd3.appendChild(document.createTextNode(' 点')); nTd3.appendChild(document.createElement('br')); nTd3.appendChild(document.createTextNode('残り ')); nSpan = document.createElement('span'); nSpan.id = id + '_rest'; nSpan.appendChild(document.createTextNode('0')); nTd3.appendChild(nSpan); nTd3.appendChild(document.createTextNode('枚')); nTd3.appendChild(document.createElement('br')); nSpan = document.createElement('span'); nSpan.id = id + '_pass'; nSpan.appendChild(document.createTextNode('パス 0回')); nTd3.appendChild(nSpan); nTr3.appendChild(nTd3); nTbody3.appendChild(nTr3); nTable3.appendChild(nTbody3); nTd2.appendChild(nTable3); nTr2.appendChild(nTd2); nTd2 = document.createElement('td'); nTable3 = document.createElement('table'); nTable3.cellPadding = 0, nTable3.cellSpacing = 0; nTbody3 = document.createElement('tbody'); nTr3 = document.createElement('tr'); if (i == 1) { k = 2; } else if (i == 2) { k = 1; } else { k = i; } for (j = 1; j <= 13; j++) { nTd3 = document.createElement('td'); nTd3.id = this.id + '_card' + k + '_' + j; nTr3.appendChild(nTd3); } nTbody3.appendChild(nTr3); nTable3.appendChild(nTbody3); nTd2.appendChild(nTable3); nTr2.appendChild(nTd2); nTbody2.appendChild(nTr2); } nTr2 = document.createElement('tr'); nTd2 = document.createElement('td'); nTd2.colSpan = 2, nTd2.align = 'right'; nTd2.style.border = '1pt solid black'; nTable3 = document.createElement('table'); nTable3.cellPadding = 0, nTable3.cellSpacing = 0; nTbody3 = document.createElement('tbody'); nTr3 = document.createElement('tr'); for (i = 0; i < 14; i++) { nTd3 = document.createElement('td'); nTd3.id = this.id + '_hand' + i; nTd3.onclick = this.click; nTd3.onmouseover = this.mOver; nTd3.onmouseout = this.mOut; nTr3.appendChild(nTd3); } nTbody3.appendChild(nTr3); nTable3.appendChild(nTbody3); nTd2.appendChild(nTable3); nTr2.appendChild(nTd2); nTbody2.appendChild(nTr2); nTable2.appendChild(nTbody2); nTd.appendChild(nTable2); nTr.appendChild(nTd); nTd = document.createElement('td'); nTd.vAlign = 'top'; nTd.style.width = this.size * 20 + 'pt'; nTd.style.color = 'black'; nTd.style.fontSize = this.fontSize + 'pt'; nTd.style.lineHeight = this.lineHeight + 'pt'; nDiv = document.createElement('div'); nDiv.align = 'center'; nDiv.style.fontWeight = 'bold'; nDiv.appendChild(document.createTextNode('第 ')); nSpan = document.createElement('span'); nSpan.id = this.id + '_stage'; nSpan.appendChild(document.createTextNode('0/0')); nDiv.appendChild(nSpan); nDiv.appendChild(document.createTextNode(' 回戦')); nTd.appendChild(nDiv); nP = document.createElement('p'); nDiv = document.createElement('div'); nDiv.id = this.id + '_joker'; nDiv.style.cursor = 'default'; nDiv.onclick = this.click; nDiv.appendChild(document.createTextNode('ジョーカー:有り')); nP.appendChild(nDiv); nTd.appendChild(nP); nP = document.createElement('p'); nDiv = document.createElement('div'); nDiv.id = this.id + '_redeal'; nDiv.style.cursor = 'default'; nDiv.onclick = this.click; nDiv.appendChild(document.createTextNode('配り直し :有り')); nP.appendChild(nDiv); nTd.appendChild(nP); nForm = document.createElement('form'); nP = document.createElement('p'); nP.id = this.id + '_round'; nForm.appendChild(nP); nP = document.createElement('p'); nP.id = this.id + '_level'; nForm.appendChild(nP); nTd.appendChild(nForm); nTr.appendChild(nTd); nTbody.appendChild(nTr); nTr = document.createElement('tr'); nTd = document.createElement('td'); nTd.align = 'center', nTd.vAlign = 'bottom'; nDiv = document.createElement('div'); nDiv.id = this.id + '_button'; nDiv.align = 'center'; nDiv.style.marginBottom = this.size * 5 + 'pt'; nTd.style.color = 'black'; nTd.style.fontSize = this.fontSize + 'pt'; nTd.style.lineHeight = this.lineHeight + 'pt'; nTd.appendChild(nDiv); nTr.appendChild(nTd); nTr.appendChild(nTd); nTbody.appendChild(nTr); nTable.appendChild(nTbody); node.appendChild(nTable); } // 七並べ:ボタンのセット FantanDomino.prototype.buttonSet = function(command) { this.card.clear(this.id + '_button'); var node, tmp; node = document.getElementById(this.id + '_button'); if (command == 'start') { node.appendChild(this.buttonSet2('start')); node = document.getElementById(this.id + '_joker'); if (this.ie) { node.style.cursor = 'hand'; } else { node.style.cursor = 'pointer'; } node = document.getElementById(this.id + '_redeal'); if (this.ie) { node.style.cursor = 'hand'; } else { node.style.cursor = 'pointer'; } var nSelect, nOption; node = document.getElementById(this.id + '_round'); node.appendChild(document.createTextNode('試合回数:')); node.appendChild(document.createElement('br')); nSelect = document.createElement('select'); nSelect.id = this.id + '_sRound'; nSelect.style.fontSize = this.fontSize + 'pt'; nSelect.style.fontFamily = 'monospace'; nSelect.style.backgroundColor = this.bgColor; nSelect.onchange = this.click; nOption = document.createElement('option'); nOption.appendChild(document.createTextNode('  1回')); nSelect.appendChild(nOption); nOption = document.createElement('option'); nOption.appendChild(document.createTextNode('  3回')); nSelect.appendChild(nOption); nOption = document.createElement('option'); nOption.appendChild(document.createTextNode('  6回')); nSelect.appendChild(nOption); nOption = document.createElement('option'); nOption.appendChild(document.createTextNode(' 12回')); nSelect.appendChild(nOption); node.appendChild(nSelect); node = document.getElementById(this.id + '_sRound'); if (this.lastStage == 1) { tmp = 0; } else if (this.lastStage == 3) { tmp = 1; } else if (this.lastStage == 6) { tmp = 2; } else if (this.lastStage == 12) { tmp = 3; } node.selectedIndex = tmp; node = document.getElementById(this.id + '_level'); node.appendChild(document.createTextNode('難易度:')); node.appendChild(document.createElement('br')); nSelect = document.createElement('select'); nSelect.id = this.id + '_sLevel'; nSelect.style.fontSize = this.fontSize + 'pt'; nSelect.style.fontFamily = 'monospace'; nSelect.style.backgroundColor = this.bgColor; nSelect.onchange = this.click; nOption = document.createElement('option'); nOption.appendChild(document.createTextNode('Level 1')); nSelect.appendChild(nOption); nOption = document.createElement('option'); nOption.appendChild(document.createTextNode('Level 2')); nSelect.appendChild(nOption); nOption = document.createElement('option'); nOption.appendChild(document.createTextNode('Level 3')); nSelect.appendChild(nOption); nOption = document.createElement('option'); nOption.appendChild(document.createTextNode('Lv 1〜3')); nSelect.appendChild(nOption); node.appendChild(nSelect); node = document.getElementById(this.id + '_sLevel'); if (this.level == 0) { tmp = 3; } else { tmp = this.level - 1; } node.selectedIndex = tmp; } else if (command == 'select') { if (this.pl.turnCount == 1 && this.redeal) { if (this.pl.point >= this.pointList[0]) { node.appendChild(this.buttonSet2('redeal')); } } node.appendChild(this.buttonSet2('pass')); } } // 七並べ:ボタンのセット2 FantanDomino.prototype.buttonSet2 = function(button) { var elm; elm = document.createElement('div'); elm.id = this.id + '_button_' + button; elm.style.marginTop = this.size * 2 + 'pt'; elm.style.border = '2pt double black'; elm.style.width = '90%'; if (this.ie) { elm.style.cursor = 'hand'; } else { elm.style.cursor = 'pointer'; } elm.onclick = this.click; var str; if (button == 'start') { str = '勝負開始'; } else if (button == 'pass') { str = 'パス'; } else if (button == 'redeal') { str = '配り直し'; } elm.appendChild(document.createTextNode(str)); return elm; } // 七並べ:ステージ表示 FantanDomino.prototype.stageView = function() { var node = document.getElementById(this.id + '_stage'); node.firstChild.nodeValue = this.stage + '/' + this.lastStage; } // 七並べ:場にカードを表示 FantanDomino.prototype.cardView = function(suit, num, type) { var id = this.id + '_card' + suit + '_' + num; var leftId = this.id + '_card' + suit + '_' + (num - 1); var left = true, right = true; if (num == 1) { left = false; } else if (this.fieldCard[(num - 2) + suit * 13] == 0) { left = false; } if (num == 13) { right = false; } else if (this.fieldCard[num + suit * 13] == 0) { right = false; } var parts = ''; if (left && right) { parts = 'left'; if (type == 'none') { parts = 'none'; this.card.view(leftId, num - 1, suit); } else { this.card.view(leftId, num - 1, suit, 'left'); } } else if (left) { if (type == 'none') { this.card.view(leftId, num - 1, suit); } else { this.card.view(leftId, num - 1, suit, 'left'); } } else if (right) { parts = 'left'; } if (type == 'none') { if (parts == 'none') { this.card.clear(id); } else { this.card.noneView(id, this.bgColor, 'left'); } } else if (type == null || type == 'normal') { this.card.view(id, num, suit, parts); } else { this.cardSelect[type].view(id, num, suit, parts); } } // 七並べ:場にカード(ジョーカー含む)を表示 FantanDomino.prototype.cardViewJoker = function(suit, num, type) { var id = this.id + '_card' + suit + '_' + num; var card, linkId, jokerId, nextId, next = 0, link = 0, parts = ''; if (num < 7) { jokerId = this.id + '_card' + suit + '_' + (num + 1); if (num > 1) { nextId = this.id + '_card' + suit + '_' + (num - 1); if (this.fieldCard[(num - 2) + suit * 13]) { next = num - 1; } } if (type == 'none') { this.card.noneView(jokerId, this.bgColor, 'left'); if (next) { this.card.view(nextId, next, suit); this.card.clear(id); } else { this.card.noneView(id, this.bgColor, 'left'); } } else { if (next) { this.card.view(nextId, next, suit, 'left'); } if (type == 'normal') { this.card.view(jokerId, 0, 0, 'left'); } else { this.cardSelect[type].view(jokerId, 0, 0, 'left'); } if (type == 'normal') { this.card.view(id, num, suit, 'left'); } else { this.cardSelect[type].view(id, num, suit, 'left'); } } } else { link = num - 2; linkId = this.id + '_card' + suit + '_' + (num - 2); jokerId = this.id + '_card' + suit + '_' + (num - 1); if (num < 13) { if (this.fieldCard[num + suit * 13]) { next = true; parts = 'left'; } } if (type == 'none') { this.card.view(linkId, link, suit); this.card.noneView(jokerId, this.bgColor, 'left'); if (next) { this.card.clear(id); } else { this.card.noneView(id, this.bgColor, 'left'); } this.card.noneView(jokerId, this.bgColor, 'left'); } else { this.card.view(linkId, link, suit, 'left'); if (type == 'normal') { this.card.view(id, num, suit, parts); } else { this.cardSelect[type].view(id, num, suit, parts); } if (type == 'normal') { this.card.view(jokerId, 0, 0, 'left'); } else { this.cardSelect[type].view(jokerId, 0, 0, 'left'); } } } } // 七並べ:全ての手札の表示 FantanDomino.prototype.handCardAllView = function() { var i, id, card, parts = 'left', node; for (i = 0; i < 14; i++) { id = this.id + '_hand' + i; node = document.getElementById(id); node.style.cursor = 'default'; if (this.pl.hand.length <= i) { if (i == 0) { this.card.noneView(id, this.bgColor); } else { this.card.clear(id); } } else { card = cardNumAndSuit(this.pl.hand[i]); if (i == this.pl.hand.length - 1) { parts = ''; } this.card.view(id, card[0], card[1], parts); } } } // 七並べ:手札の表示 FantanDomino.prototype.handCardView = function(num, type) { var id = this.id + '_hand' + num; var parts = 'left'; if (num == this.pl.hand.length - 1) { parts = ''; } var card = cardNumAndSuit(this.pl.hand[num]); var node = document.getElementById(id); if (type == 'normal') { this.card.view(id, card[0], card[1], parts); node.style.cursor = 'default'; } else { this.cardSelect[type].view(id, card[0], card[1], parts); if (card[0] != 0) { if (this.ie) { node.style.cursor = 'hand'; } else { node.style.cursor = 'pointer'; } } } } // 七並べ:最初のカード配り FantanDomino.prototype.firstDeal = function() { this.oneCards = new Array(); var i, j, k = 0, tmp; for (j = 0; j < 4; j++) { for (i = 1; i <= 13; i++) { this.oneCards[k] = (j * 100) + i; k++; } } this.oneCards = shuffle(this.oneCards); this.fieldCard = new Array(4 * 13); for (i = 0; i < this.fieldCard.length; i++) { this.fieldCard[i] = 0; } var len, card, id; i = 0; while(this.oneCards.length > 0) { card = cardNumAndSuit(this.oneCards[0]); if (card[0] == 7) { if (card[1] == 3) { this.turn = i; } this.fieldCard[(card[0] - 1) + card[1] * 13] = 1; this.cardView(card[1], card[0]); } else { len = this.playerModel[i].hand.length; this.playerModel[i].hand[len] = this.oneCards[0]; } this.oneCards = this.oneCards.slice(1); if (i == 3) { i = 0; } else { i++; } } if (this.joker) { tmp = dice(1, 4) - 1; len = this.playerModel[tmp].hand.length; this.playerModel[tmp].hand[len] = 400; } for (i = 0; i < 4; i++) { this.playerModel[i].hand.sort(sort); this.playerModel[i].stateView(); } this.handCardAllView(); } // 七並べ:次のターンへ FantanDomino.prototype.nextTurn = function() { this.beforeTurn = this.turn; var endCheck = 0; while (true) { if (this.turn == 3) { this.turn = 0; } else { this.turn++; } if (this.playerModel[this.turn].gameState == 'play') { break; } else { endCheck++; if (endCheck > 3) { break; } } } var i; endCheck = 0; for (i = 0; i < 4; i++) { if (this.playerModel[i].gameState != 'play') { endCheck++; } } if (endCheck >= 3) { this.gameEnd(); } else { this.turnExe(); } } // 七並べ:ターン実行 FantanDomino.prototype.turnExe = function() { var func; if (this.beforeTurn != 3 && this.playerModel[3].hand.length == 0) { func = "turnTimeAction()"; this.turnId = setTimeout(func, 10); } else { func = "turnTimeAction()"; this.turnId = setTimeout(func, this.waitTime); } } // 七並べ:ジョーカーターン FantanDomino.prototype.jokerTurn = function(suit, num) { var id = this.playerModel[this.turn].id; var node = document.getElementById(id); node.style.backgroundColor = this.bgColor; var i, pl, card, check = -1; var errorCount = 0; while (true) { errorCount++; if (errorCount > 3) { alert('エラー!'); break; } if (this.turn == 3) { this.turn = 0; } else { this.turn++; } if (this.playerModel[this.turn].gameState != 'play') { continue; } pl = this.playerModel[this.turn]; for (i = 0; i < pl.hand.length; i++) { card = cardNumAndSuit(pl.hand[i]); if (card[0] == num && card[1] == suit) { check = i; break; } } if (check >= 0) { break; } } id = this.playerModel[this.turn].id; this.cardView(suit, num, 'normal'); var ary, ary2; ary = pl.hand.slice(0, check); ary2 = pl.hand.slice(check + 1); pl.hand = ary.concat(ary2); if (this.turn == 3) { this.handCardAllView(); } pl.stateView(); node = document.getElementById(id); node.style.backgroundColor = this.activeColor; if (pl.hand.length == 0) { if (this.turn == 3) { pl.cardOut('win', 'pl'); } else { pl.cardOut('win'); } } if (this.turn == 3) { this.handCardAllView(); } this.nextTurn(); } // 七並べ:プレイヤターン FantanDomino.prototype.playerTurn = function() { this.playerModel[this.beforeTurn].stateView(); var node = document.getElementById(this.pl.id); node.style.backgroundColor = this.activeColor; this.mode = 'select'; this.pl.turnCount++; this.buttonSet('select'); this.pl.handCheck(); var i; for (i = 0; i < this.pl.handTakeOut.length; i++) { if (this.pl.handTakeOut[i] == 1) { this.handCardView(i, 0); } else if (this.pl.handTakeOut[i] == 2) { this.handCardView(i, 1); } } } // 七並べ:プレイヤターンの終了 FantanDomino.prototype.playerTurnEnd = function(mode) { this.mode = 'turn'; this.pl.stateView(); this.buttonSet(); var i; if (mode == 'pass') { for (i = 0; i < this.pl.handTakeOut.length; i++) { if (this.pl.handTakeOut[i] != 0) { this.handCardView(i, 'noramal'); } } } else { this.handCardAllView(); } } // 七並べ:ゲーム終了 FantanDomino.prototype.gameEnd = function() { this.mode = 'getPoint'; var i, node, card; for (i = 0; i < 4; i++) { node = document.getElementById(this.id + '_pl' + i); node.style.backgroundColor = this.bgColor; } var pl = this.playerModel[this.turn]; var winOrLose = 'win'; if (pl.gameState == 'play') { if (pl.hand.length > 0) { card = cardNumAndSuit(pl.hand[pl.hand.length - 1]); if (card[0] == 0) { winOrLose = 'lose'; } } if (this.turn == 3) { pl.cardOut(winOrLose, 'pl'); } else { pl.cardOut(winOrLose); } } var order = new Array(); for (i = 0; i < 4; i++) { pl = this.playerModel[i]; if (pl.gameState == 'win') { order[i] = pl.order + '_' + i; } else { order[i] = (10 - pl.order) + '_' + i; } } order.sort(); var tmp, str = '', point; for (i = 0; i < order.length; i++) { tmp = order[i].split('_'); tmp[1] -= 0; pl = this.playerModel[tmp[1]]; if (pl.gameState == 'win') { point = pl.order; } else { point = pl.order + 4; } pl.point += this.pointList[point]; if (pl.point < 0) { pl.point = 0; } str += (i + 1) + '位 ' + pl.name + ':'; if (this.pointList[point] >= 0) { str += '+'; } str += this.pointList[point] + '点'; if (i < order.length - 1) { str += '\n'; } } alert(str); if (this.stage == this.lastStage) { str = '《最終成績》\n'; for (i = 0; i < 4; i++) { this.playerModel[i].stateView(); order[i] = (100000 - this.playerModel[i].point) * 10 + i; } order.sort(sort); for (i = 0; i < 4; i++) { order[i] %= 10; } pl = this.playerModel[order[0]]; str += '1位 ' + pl.name + ':' + pl.point + '点\n'; var j = 1, k = pl.point; for (i = 1; i < 4; i++) { pl = this.playerModel[order[i]]; if (pl.point < k) { j = i + 1; } k = pl.point; str += j + '位 ' + pl.name + ':' + pl.point + '点'; if (i < 3) { str += '\n'; } } alert(str); this.mode = 'start'; this.stage = 0; this.beforeTurn = 0; for (i = 0; i < 4; i++) { this.playerModel[i].point = 200; } this.init(); this.stageView(); this.buttonSet('start'); } else { this.init(); this.stage++; this.mode = 'deal'; this.stageView(); this.firstDeal(); this.mode = 'turn'; this.turnExe(); } } // 七並べ:クリック時のアクション FantanDomino.prototype.clickAction = function(action) { var i, id, node; if (action == 'button_start') { if (this.mode != 'start') { return false; } this.mode = 'deal'; node = document.getElementById(this.id + '_joker'); node.style.cursor = 'default'; node = document.getElementById(this.id + '_redeal'); node.style.cursor = 'default'; this.buttonSet(); id = this.id + '_round'; this.card.clear(id); id = this.id + '_level'; this.card.clear(id); this.stage = 1; this.stageView(); this.firstDeal(); this.mode = 'turn'; this.turnExe(); } else if (action == 'button_pass') { this.mode = 'turn'; this.buttonSet(); this.pl.pass++; if (this.pl.pass > 3) { this.pl.cardOut('lose', 'pl'); this.nextTurn(); } else { this.playerTurnEnd(); this.nextTurn(); } } else if (action == 'button_redeal') { this.pl.point -= this.pointList[0]; this.buttonSet(); this.init(); this.firstDeal(); this.mode = 'turn'; this.turnExe(); } else if (action == 'joker') { if (this.mode != 'start') { return false; } node = document.getElementById(this.id + '_joker'); if (this.joker) { this.joker = false; node.firstChild.nodeValue = 'ジョーカー:無し'; } else { this.joker = true; node.firstChild.nodeValue = 'ジョーカー:有り'; } } else if (action == 'redeal') { if (this.mode != 'start') { return false; } node = document.getElementById(this.id + '_redeal'); if (this.redeal) { this.redeal = false; node.firstChild.nodeValue = '配り直し :無し'; } else { this.redeal = true; node.firstChild.nodeValue = '配り直し :有り'; } } else if (action == 'sRound') { if (this.mode != 'start') { return false; } node = document.getElementById(this.id + '_sRound'); if (node.selectedIndex == 0) { this.lastStage = 1; } else if (node.selectedIndex == 1) { this.lastStage = 3; } else if (node.selectedIndex == 2) { this.lastStage = 6; } else if (node.selectedIndex == 3) { this.lastStage = 12; } this.stageView(); } else if (action == 'sLevel') { if (this.mode != 'start') { return false; } node = document.getElementById(this.id + '_sLevel'); if (node.selectedIndex == 3) { this.level = 0; } else { this.level = node.selectedIndex + 1; } for (i = 0; i < 3; i++) { if (this.level == 0) { this.playerModel[i].level = this.playerModel[i].levelBak; } else { this.playerModel[i].level = this.level; } } } else if (action.match(/hand/)) { action = action.replace('hand', ''); action -= 0; if (this.mode != 'select') { return false; } else if (this.pl.handTakeOut[action] == 0) { return false; } this.mode = 'turn'; var card = cardNumAndSuit(this.pl.hand[action]); if (card[0] == 0) { return false; } var handCheck = this.pl.handTakeOut[action]; this.pl.handTakeOut = new Array(); this.fieldCard[(card[0] - 1) + card[1] * 13] = 1; var ary, ary2; ary = this.pl.hand.slice(0, action); ary2 = this.pl.hand.slice(action + 1); this.pl.hand = ary.concat(ary2); if (handCheck == 1) { this.cardView(card[1], card[0], 'normal'); var endCheck = false; if (this.pl.hand.length == 0) { this.pl.cardOut('win', 'pl'); endCheck = true; } else if (this.pl.hand.length == 1) { card = cardNumAndSuit(this.pl.hand[0]); if (card[0] == 0) { this.pl.cardOut('lose', 'pl'); endCheck = true; } } if (!endCheck) { this.playerTurnEnd(); } this.nextTurn(); } else if (handCheck == 2) { var len = this.pl.hand.length - 1; this.pl.hand = this.pl.hand.slice(0, len); var c1; if (card[0] < 7) { c1 = card[0] + 1; } else { c1 = card[0] - 1; } this.fieldCard[(c1 - 1) + card[1] * 13] = 1; this.cardViewJoker(card[1], card[0], 'normal'); if (this.pl.hand.length == 0) { this.pl.cardOut('win', 'pl'); } else { this.playerTurnEnd(); } var func = 'turnTimeAction(' + card[1] + ',' + c1 + ')'; this.turnId = setTimeout(func, this.waitTime); } } } // 七並べ:クリック FantanDomino.prototype.click = function() { var cFD = cardFantanDomino; var action = this.id; action = action.replace(cFD.id + '_', ''); cFD.clickAction(action); } // 七並べ:マウスオーバー時のアクション FantanDomino.prototype.mOverAction = function(action) { if (this.mode != 'select') { return false; } else if (this.pl.handTakeOut[action] == 0) { return false; } var card = cardNumAndSuit(this.pl.hand[action]); if (this.pl.handTakeOut[action] == 1) { this.cardView(card[1], card[0], 0); } else if (this.pl.handTakeOut[action] == 2) { this.cardViewJoker(card[1], card[0], 1); } } // 七並べ:マウスオーバー FantanDomino.prototype.mOver = function() { var cFD = cardFantanDomino; var action = this.id; action = action.replace(cFD.id + '_hand', ''); action -= 0; cFD.mOverAction(action); } // 七並べ:マウスアウト時のアクション FantanDomino.prototype.mOutAction = function(action) { if (this.mode != 'select') { return false; } else if (this.pl.handTakeOut[action] == 0) { return false; } var card = cardNumAndSuit(this.pl.hand[action]); if (this.pl.handTakeOut[action] == 1) { this.cardView(card[1], card[0], 'none'); } else if (this.pl.handTakeOut[action] == 2) { this.cardViewJoker(card[1], card[0], 'none'); } } // 七並べ:マウスアウト FantanDomino.prototype.mOut = function() { var cFD = cardFantanDomino; var action = this.id; action = action.replace(cFD.id + '_hand', ''); action -= 0; cFD.mOutAction(action); } // プレイヤモデルクラス function PlayerModel(parent, id, name, level) { this.parent = parent; this.id = this.parent.id + id; this.name = name; this.level = level; this.levelBak = level; this.point = 200; } // プレイヤモデル:初期化 PlayerModel.prototype.init = function() { this.hand = new Array(); this.handTakeOut = new Array(); this.pass = 0; this.turnCount = 0; this.gameState = 'play'; this.order = 0; this.stateView(); } // プレイヤモデル:状態表示 PlayerModel.prototype.stateView = function(bg) { var node; if (bg != 'none') { node = document.getElementById(this.id); node.style.backgroundColor = this.parent.bgColor; } node = document.getElementById(this.id + '_point'); node.firstChild.nodeValue = this.point; node = document.getElementById(this.id + '_rest'); node.firstChild.nodeValue = this.hand.length; if (this.gameState == 'play') { node = document.getElementById(this.id + '_pass'); node.style.fontWeight = 'normal'; node.style.color = 'black'; node.firstChild.nodeValue = 'パス ' + this.pass + '回'; } } // プレイヤモデル:出せるカードのチェック PlayerModel.prototype.handCheck = function() { var joker = false; var card = cardNumAndSuit(this.hand[this.hand.length - 1]); if (card[0] == 0) { joker = true; } var i, j, c1, c2, nextCard, joker2, jokerCheck = false, cardOk; var fieldCard = this.parent.fieldCard; var fieldCheck = new Array(); for (i = 0; i < 4; i++) { fieldCheck[i] = new Array(); for (j = 6; j > 0; j--) { if (fieldCard[(j - 1) + i * 13] == 0) { fieldCheck[i][0] = j + 1; break; } else if (j == 1) { fieldCheck[i][0] = 1; } } for (j = 8; j <= 13; j++) { if (fieldCard[(j - 1) + i * 13] == 0) { fieldCheck[i][1] = j - 1; break; } else if (j == 13) { fieldCheck[i][1] = 13; } } } this.handTakeOut = new Array(); for (i = 0; i < this.hand.length; i++) { cardOk = false; card = cardNumAndSuit(this.hand[i]); if (joker) { joker2 = true; } if (card[0] == 0) { if (jokerCheck) { this.handTakeOut[i] = 2; } else { this.handTakeOut[i] = 0; } break; } if (card[0] < 7) { if (card[0] == fieldCheck[card[1]][0] - 1) { cardOk = true; joker2 = false; } else if (joker2 && card[0] == fieldCheck[card[1]][0] - 2) { cardOk = true; } if (joker2 && cardOk && i < this.hand.length - 1) { nextCard = cardNumAndSuit(this.hand[i + 1]); if (nextCard[1] == card[1]) { if (nextCard[0] == card[0] + 1) { cardOk = false; joker2 = false; } } } } else { if (card[0] == fieldCheck[card[1]][1] + 1) { cardOk = true; joker2 = false; } else if (joker2 && card[0] == fieldCheck[card[1]][1] + 2) { cardOk = true; } if (joker2 && cardOk && i > 0) { nextCard = cardNumAndSuit(this.hand[i - 1]); if (nextCard[1] == card[1]) { if (nextCard[0] == card[0] - 1) { cardOk = false; joker2 = false; } } } } if (cardOk) { if (joker2) { jokerCheck = true; this.handTakeOut[i] = 2; } else { this.handTakeOut[i] = 1; } } else { this.handTakeOut[i] = 0; } } } // プレイヤモデル:ターン PlayerModel.prototype.turn = function() { this.parent.playerModel[this.parent.beforeTurn].stateView(); var node = document.getElementById(this.id); node.style.backgroundColor = this.parent.activeColor; this.turnCount++; this.handCheck(); var i, j, card, nextCard; var fCard = this.parent.fieldCard; var count = 0; var handNum = new Array(); var handJoker = new Array(); var hand1 = new Array(), hand2 = new Array(), hand3 = new Array(); var k, l, cardTmp, fCardCheck; for (i = 0; i < this.handTakeOut.length; i++) { if (this.handTakeOut[i] == 0) { continue; } card = cardNumAndSuit(this.hand[i]); if (card[0] == 0) { break; } handNum[count] = i; if (this.handTakeOut[i] == 1) { handJoker[count] = false; } else { handJoker[count] = true; } if (card[0] < 7) { j = i, k = 0; cardTmp = card; while (true) { j--; if (j < 0) { break; } nextCard = cardNumAndSuit(this.hand[j]); if (cardTmp[1] != nextCard[1]) { break; } else if (cardTmp[0] != nextCard[0] + 1) { break; } else { cardTmp = nextCard; k++; } } hand1[count] = k; k = card[0] - k; hand2[count] = 0; if (j >= 0) { if (card[1] == nextCard[1]) { hand2[count] = k - nextCard[0] - 1; } } if (hand2[count] > 0) { k = card[0] - hand1[count] - 1; fCardCheck = true; for (l = k; l > k - hand2[count]; l--) { if (!fCard[(l - 1) + card[1] * 13]) { fCardCheck = false; break; } } if (fCardCheck) { hand1[count]++; k = 0; card = nextCard; cardTmp = card; while (true) { j--; if (j < 0) { break; } nextCard = cardNumAndSuit(this.hand[j]); if (cardTmp[1] != nextCard[1]) { break; } else if (cardTmp[0] != nextCard[0] + 1) { break; } else { cardTmp = nextCard; k++; } } hand1[count] += k; k = card[0] - k; hand2[count] = 0; if (j >= 0) { if (card[1] == nextCard[1]) { hand2[count] = k - nextCard[0] - 1; } } } } if (hand2[count] > 0) { card[0]++; k = card[0] - hand1[count] - 1; fCardCheck = true; for (l = k; l > k - hand2[count]; l--) { if (!fCard[(l - 1) + card[1] * 13]) { fCardCheck = false; break; } } if (fCardCheck) { hand1[count]++; k = 0; card = nextCard; cardTmp = card; while (true) { j--; if (j < 0) { break; } nextCard = cardNumAndSuit(this.hand[j]); if (cardTmp[1] != nextCard[1]) { break; } else if (cardTmp[0] != nextCard[0] + 1) { break; } else { cardTmp = nextCard; k++; } } hand1[count] += k; k = card[0] - k; hand2[count] = 0; if (j >= 0) { if (card[1] == nextCard[1]) { hand2[count] = k - nextCard[0] - 1; } } } } hand3[count] = 0; if (hand1[count] == 0 && hand2[count] == 0) { j = card[0] - 1; for (k = j; k > 0; k--) { if (!fCard[(k - 1) + card[1] * 13]) { hand3[count]++; } } } } else { j = i, k = 0; cardTmp = card; while (true) { j++; if (j >= this.hand.length) { break; } nextCard = cardNumAndSuit(this.hand[j]); if (cardTmp[1] != nextCard[1]) { break; } else if (cardTmp[0] != nextCard[0] - 1) { break; } else { cardTmp = nextCard; k++; } } hand1[count] = k; k = card[0] + k; hand2[count] = 0; if (j <= this.hand.length - 1) { if (card[1] == nextCard[1]) { hand2[count] = nextCard[0] - k - 1; } } if (hand2[count] > 0) { k = card[0] + hand1[count] + 1; fCardCheck = true; for (l = k; l < k + hand2[count]; l++) { if (!fCard[(l - 1) + card[1] * 13]) { fCardCheck = false; break; } } if (fCardCheck) { hand1[count]++; k = 0; card = nextCard; cardTmp = card; while (true) { j++; if (j >= this.hand.length) { break; } nextCard = cardNumAndSuit(this.hand[j]); if (cardTmp[1] != nextCard[1]) { break; } else if (cardTmp[0] != nextCard[0] - 1) { break; } else { cardTmp = nextCard; k++; } } hand1[count] += k; k = card[0] + k; hand2[count] = 0; if (j <= this.hand.length - 1) { if (card[1] == nextCard[1]) { hand2[count] = nextCard[0] - k - 1; } } } } if (hand2[count] > 0) { card[0]--; k = card[0] + hand1[count] + 1; fCardCheck = true; for (l = k; l < k + hand2[count]; l++) { if (!fCard[(l - 1) + card[1] * 13]) { fCardCheck = false; break; } } if (fCardCheck) { hand1[count]++; k = 0; card = nextCard; cardTmp = card; while (true) { j++; if (j >= this.hand.length) { break; } nextCard = cardNumAndSuit(this.hand[j]); if (cardTmp[1] != nextCard[1]) { break; } else if (cardTmp[0] != nextCard[0] - 1) { break; } else { cardTmp = nextCard; k++; } } hand1[count] += k; k = card[0] + k; hand2[count] = 0; if (j <= this.hand.length - 1) { if (card[1] == nextCard[1]) { hand2[count] = nextCard[0] - k - 1; } } } } hand3[count] = 0; if (hand1[count] == 0 && hand2[count] == 0) { j = card[0] + 1; for (k = j; k <= 13; k++) { if (!fCard[(k - 1) + card[1] * 13]) { hand3[count]++; } } } } count++; } var handCheck = new Array('', '', '', '', ''); for (i = 0; i < handNum.length; i++) { if (hand1[i] == 0 && hand2[i] > 0 && !handJoker[i]) { handCheck[0] += i + ','; } else if (hand1[i] > 0 && hand2[i] > 0 && !handJoker[i]) { handCheck[1] += i + ','; } else if (hand1[i] > 0 && hand2[i] == 0 && !handJoker[i]) { handCheck[3] += i + ','; } else if (hand3[i] == 0 && !handJoker[i]) { handCheck[2] += i + ','; } else if (!handJoker[i]){ handCheck[4] += i + ','; } } var handCheckJ = new Array('', '', '', '', ''); for (i = 0; i < handNum.length; i++) { if (hand1[i] == 0 && hand2[i] > 0 && handJoker[i]) { handCheckJ[0] += i + ','; } else if (hand1[i] > 0 && hand2[i] > 0 && handJoker[i]) { handCheckJ[1] += i + ','; } else if (hand1[i] > 0 && hand2[i] == 0 && handJoker[i]) { handCheckJ[3] += i + ','; } else if (hand3[i] == 0 && handJoker[i]) { handCheckJ[2] += i + ','; } else if (handJoker[i]){ handCheckJ[4] += i + ','; } } var handResult = -2; if (handNum.length == 0) { handResult = -2; } else if (this.level == 1) { // level 1 if (handNum.length == 1 && this.hand.length == 1) { handResult = -1; } else if (handNum.length == 1 && handJoker[handNum[0]] && this.hand.length == 2) { handResult = -1; } else if (handCheck[2] != '') { handResult = 2; } else if (handCheck[3] != '') { handResult = 3; } else if (handCheck[1] != '') { handResult = 1; } else if (handCheck[0] != '') { handResult = 0; } else if (handCheck[4] != '') { handResult = 4; } else if (handCheckJ[3] != '') { handResult = 13; } else if (handCheckJ[1] != '') { handResult = 11; } else if (this.pass < 3) { handResult = -2; } else if (handCheckJ[0] != '') { handResult = 10; } else if (handCheckJ[2] != '') { handResult = 12; } else if (handCheckJ[4] != '') { handResult = 14; } } else if (this.level == 2) { // level 2 if (handNum.length == 1 && this.hand.length == 1) { handResult = -1; } else if (handNum.length == 1 && handJoker[handNum[0]] && this.hand.length == 2) { handResult = -1; } else if (handCheck[2] != '') { handResult = 2; } else if (handCheck[3] != '') { handResult = 3; } else if (handCheck[1] != '') { handResult = 1; } else if (handCheck[0] != '') { handResult = 0; } else if (handCheckJ[3] != '') { handResult = 13; } else if (handCheckJ[1] != '') { handResult = 11; } else if (this.pass < 3) { handResult = -2; } else if (handCheckJ[0] != '') { handResult = 10; } else if (handCheckJ[2] != '') { handResult = 12; } else if (handCheckJ[4] != '') { handResult = 14; } else if (handCheck[4] != '') { handResult = 4; } } else if (this.level == 3) { // level 3 if (handCheck[0] != '') { handResult = 0; } else if (handCheck[1] != '') { handResult = 1; } else if (handCheck[2] != '') { handResult = 2; } else if (handCheck[3] != '') { handResult = 3; } else if (handCheckJ[1] != '') { handResult = 11; } else if (handCheckJ[0] != '') { handResult = 10; } else if (handCheckJ[3] != '') { handResult = 13; } else if (this.pass < 3) { handResult = -2; } else if (handCheckJ[2] != '') { handResult = 12; } else if (handCheckJ[4] != '') { handResult = 14; } else if (handCheck[4] != '') { handResult = 4; } } var jokerTurn = false, c1; if (handResult == -2) { this.pass++; } else { var action; if (handResult == -1) { action = 0; } else if (handResult == 0) { if (this.level == 3) { j = this.aryTopNum(handCheck[0], hand2, 'max'); } else { j = this.aryTopNum(handCheck[0], hand2, 'min'); } action = handNum[j]; } else if (handResult == 1) { j = this.aryTopNum(handCheck[1], hand1, 'max'); action = handNum[j]; } else if (handResult == 2) { handCheck[2] = handCheck[2].replace(/,$/, ''); k = handCheck[2].split(','); j = dice(1, k.length) - 1; action = handNum[k[j]]; } else if (handResult == 3) { j = this.aryTopNum(handCheck[3], hand1, 'max'); action = handNum[j]; } else if (handResult == 4) { j = this.aryTopNum(handCheck[4], hand3, 'min'); action = handNum[j]; } else if (handResult == 10) { if (this.level == 3) { j = this.aryTopNum(handCheckJ[0], hand2, 'max'); } else { j = this.aryTopNum(handCheckJ[0], hand2, 'min'); } action = handNum[j]; } else if (handResult == 11) { j = this.aryTopNum(handCheckJ[1], hand1, 'max'); action = handNum[j]; } else if (handResult == 12) { handCheckJ[2] = handCheckJ[2].replace(/,$/, ''); k = handCheckJ[2].split(','); j = dice(1, k.length) - 1; action = handNum[k[j]]; } else if (handResult == 13) { j = this.aryTopNum(handCheckJ[3], hand1, 'max'); action = handNum[j]; } else if (handResult == 14) { j = this.aryTopNum(handCheckJ[4], hand3, 'min'); action = handNum[j]; } if (this.parent.debug) { var str = this.name + ' が持っているカードは'; var i2, j2 = -1, card2; for (i2 = 0; i2 < this.hand.length; i2++) { card2 = cardNumAndSuit(this.hand[i2]); if (card2[0] == 0) { break; } if (card2[1] != j2) { str = str.replace(/,$/, ''); j2 = card2[1]; str += '\n'; if (card2[1] == 0) { str += 'S'; } else if (card2[1] == 1) { str += 'C'; } else if (card2[1] == 2) { str += 'H'; } else if (card2[1] == 3) { str += 'D'; } str += ':'; } if (card2[0] == 1) { card2[0] = 'A'; } else if (card2[0] == 11) { card2[0] = 'J'; } else if (card2[0] == 12) { card2[0] = 'Q'; } else if (card2[0] == 13) { card2[0] = 'K'; } str += card2[0] + ','; } str = str.replace(/,$/, ''); str += '\n\n出せるカードは'; j2 = -1; for (i2 = 0; i2 < handNum.length; i2++) { card2 = cardNumAndSuit(this.hand[handNum[i2]]); if (card2[0] == 0) { break; } if (card2[1] != j2) { str = str.replace(/,$/, ''); j2 = card2[1]; str += '\n'; if (card2[1] == 0) { str += 'S'; } else if (card2[1] == 1) { str += 'C'; } else if (card2[1] == 2) { str += 'H'; } else if (card2[1] == 3) { str += 'D'; } str += ':'; } if (card2[0] == 1) { card2[0] = 'A'; } else if (card2[0] == 11) { card2[0] = 'J'; } else if (card2[0] == 12) { card2[0] = 'Q'; } else if (card2[0] == 13) { card2[0] = 'K'; } str += card2[0] + ','; } str = str.replace(/,$/, ''); str += '\n\n'; str += '出すカードは\n'; card2 = cardNumAndSuit(this.hand[action]); if (card2[1] == 0) { str += 'S'; } else if (card2[1] == 1) { str += 'C'; } else if (card2[1] == 2) { str += 'H'; } else if (card2[1] == 3) { str += 'D'; } if (card2[0] == 1) { card2[0] = 'A'; } else if (card2[0] == 11) { card2[0] = 'J'; } else if (card2[0] == 12) { card2[0] = 'Q'; } else if (card2[0] == 13) { card2[0] = 'K'; } str += 'の' + card2[0]; alert(str); } var handTakeOut = this.handTakeOut[action]; this.handTakeOut = new Array(); card = cardNumAndSuit(this.hand[action]); fCard[(card[0] - 1) + card[1] * 13] = 1; var ary, ary2; ary = this.hand.slice(0, action); ary2 = this.hand.slice(action + 1); this.hand = ary.concat(ary2); if (handTakeOut == 1) { this.parent.cardView(card[1], card[0], 'normal'); } else if (handTakeOut == 2) { var len = this.hand.length - 1; this.hand = this.hand.slice(0, len); if (card[0] < 7) { c1 = card[0] + 1; } else { c1 = card[0] - 1; } fCard[(c1 - 1) + card[1] * 13] = 1; this.parent.cardViewJoker(card[1], card[0], 'normal'); jokerTurn = true; } } this.stateView('none'); if (this.pass > 3) { this.cardOut('lose'); } else if (this.hand.length == 0) { this.cardOut('win'); } else if (this.hand.length == 1) { cardTmp = cardNumAndSuit(this.hand[0]); if (cardTmp[0] == 0) { this.cardOut('lose'); } } else if (handResult == -2) { node = document.getElementById(this.id + '_pass'); node.style.fontWeight = 'bold'; node.style.color = 'red'; node.firstChild.nodeValue = 'パス'; } if (jokerTurn) { var func = 'turnTimeAction(' + card[1] + ',' + c1 + ')'; this.parent.turnId = setTimeout(func, this.parent.waitTime); } else { this.parent.nextTurn(); } } // プレイヤモデル:最大(or最小)値の格納された配列の添え字を返す PlayerModel.prototype.aryTopNum = function(aryStr, ary, MaxOrMin) { aryStr = aryStr.replace(/,$/, ''); var ary1 = aryStr.split(','); var i, result; if (dice(1,2) == 1) { result = ary1[0]; for (i = 1; i < ary1.length; i++) { if (MaxOrMin == 'max') { if (ary[ary1[i]] > ary[result]) { result = ary1[i]; } } else if (MaxOrMin == 'min') { if (ary[ary1[i]] < ary[result]) { result = ary1[i]; } } } } else { result = ary1[ary1.length - 1]; for (i = ary1.length - 2; i >= 0; i--) { if (MaxOrMin == 'max') { if (ary[ary1[i]] > ary[result]) { result = ary1[i]; } } else if (MaxOrMin == 'min') { if (ary[ary1[i]] < ary[result]) { result = ary1[i]; } } } } return result; } // プレイヤモデル:カードの放出 PlayerModel.prototype.cardOut = function(mode, target) { this.mode = 'turn'; var fCard = this.parent.fieldCard; var card, i = 0, id, c1; while (true) { if (this.hand.length == 0) { break; } card = cardNumAndSuit(this.hand[0]); if (card[0] != 0) { this.parent.cardView(card[1], card[0], 'normal'); c1 = (card[0] - 1) + card[1] * 13; this.parent.fieldCard[c1] = 1; if (card[0] < 7) { c1 = card[0] + 1; } else { c1 = card[0] - 1; } if (fCard[(c1 - 1) + card[1] * 13] == 0) { id = this.parent.id + '_card'; id += card[1] + '_' + c1; this.parent.card.clear(id); } } this.hand = this.hand.slice(1); } if (target == 'pl') { this.parent.handCardAllView(); this.parent.buttonSet(); } this.stateView('none'); var node = document.getElementById(this.id + '_pass'); node.style.fontWeight = 'bold'; node.style.color = 'blue'; if (mode == 'lose') { this.gameState = 'lose'; this.parent.lose++; this.order = this.parent.lose; node.firstChild.nodeValue = '負け'; } else if (mode == 'win') { this.gameState = 'win'; this.parent.win++; this.order = this.parent.win; node.firstChild.nodeValue = this.order + '位'; } } // ターン用タイマ関数 function turnTimeAction(option, option2) { var cFD = cardFantanDomino; if (option2 > 0) { cFD.jokerTurn(option, option2); } else if (cFD.turn == 3) { cFD.playerTurn(); } else { cFD.playerModel[cFD.turn].turn(); } } // シャッフル(配列のランダムソート) function shuffle(ary) { var i, cut, len = ary.length, ary1, ary2, resultAry = new Array(); for (i = 0; i < len; i++) { cut = dice(1, ary.length); if (ary.length == 1) { resultAry[i] = ary[0]; } else { resultAry[i] = ary[cut-1]; ary1 = ary.slice(0, cut-1); ary2 = ary.slice(cut); ary = ary1.concat(ary2); } } return resultAry; } // カードの数字とスートを返す(スートの順:SHCD) function cardNumAndSuit(cardNum) { var ary = new Array(); ary[0] = cardNum % 100; ary[1] = Math.floor(cardNum / 100); if (ary[1] == 1) { ary[1] = 2; } else if (ary[1] == 2) { ary[1] = 1; } return ary; } // ソート用比較関数 function sort(a, b) { return(a - b); } // ダイスロール function dice(num, dice) { num = naturalNumCheck(num); dice = naturalNumCheck(dice, 6); var i, result = 0; for (i = 0; i < num; i++) { result += Math.ceil(Math.random() * dice); } return result; } // 自然数チェック function naturalNumCheck(checkNum, returnNum) { checkNum -= 0, returnNum -= 0; if (returnNum < 1 || returnNum == null || isNaN(returnNum)) { returnNum = 1; } if (checkNum < 1 || checkNum == null || isNaN(checkNum)) { return returnNum; } else { return checkNum; } }