/* 「テーブルカード」 2004/05/12版 THU madpoet@thu.sakura.ne.jp http://thu.sakura.ne.jp/ */ // テーブルカードクラス function TableCard() { this.size = 4; // サイズ基本値 this.frameColor = 'black'; // 枠線の色 this.bgColor = 'white'; // カードの色 this.bgBackColor = 'royalblue'; // カードの裏面の色 this.spAndClColor = 'black'; // スペードとクラブの色 this.heAndDiColor = 'red'; // ハートとダイヤの色 var i; for (i = 0; i < arguments.length; i++) { if (i == 0) { this.size = arguments[i]; } else if (i == 1) { this.frameColor = arguments[i]; } else if (i == 2) { this.bgColor = arguments[i]; } else if (i == 3) { this.bgBackColor = arguments[i]; } else if (i == 4) { this.spAndClColor = arguments[i]; } else if (i == 5) { this.heAndDiColor = arguments[i]; } } if (this.size < 3) { this.size = 3; } this.width = this.size * 8; this.height = this.size * 12; this.fontSize = this.size * 3 - 1; this.lineHeight = this.size * 3 - 1; this.jokerSize = this.size * 2; this.jokerHeight = this.size * 2 - 2; this.spades = String.fromCharCode('9824'); this.clubs = String.fromCharCode('9827'); this.hearts = String.fromCharCode('9829'); this.diams = String.fromCharCode('9830'); } // テーブルカード:表示 TableCard.prototype.view = function(id, num, suit, parts) { var node; if(!(node = document.getElementById(id))) { return false; } this.clear(id); var nTable, nTbody, nTr, nTd; var color = this.spAndClColor; var tmp, tmp2; nTable = document.createElement('table'); nTable.cellPadding = 0, nTable.cellSpacing = 0; nTable.style.border = '1pt solid ' + this.frameColor; if (parts == null) { parts = ''; } if (parts.match(/top/)) { nTable.style.borderBottom = 'none'; } if (parts.match(/bottom/)) { nTable.style.borderTop = 'none'; } if (parts.match(/eft/)) { nTable.style.borderRight = 'none'; } if (parts.match(/ight/)) { nTable.style.borderLeft = 'none'; } nTable.style.backgroundColor = this.bgColor; var width = this.width, height = this.height; if (parts.match(/top/) || parts.match(/bottom/)) { height /= 2; } if (parts.match(/eft/) || parts.match(/ight/)) { width /= 2; } nTable.style.width = width + 'pt'; nTable.style.height = height + 'pt'; nTbody = document.createElement('tbody'); num -= 0; if (num > 0 && num <= 13) { var card = num; if (card == 1) { card = 'A'; } else if (card == 11) { card = 'J'; } else if (card == 12) { card = 'Q'; } else if (card == 13) { card = 'K'; } else { card += ''; } if (suit == 0) { suit = this.spades; } else if (suit == 1) { suit = this.clubs; } else if (suit == 2) { suit = this.hearts; color = this.heAndDiColor; } else if (suit == 3) { suit = this.diams; color = this.heAndDiColor; } else { suit = ''; } if (parts == '' || parts == 'top' || parts == 'topLeft' || parts == 'left') { nTr = document.createElement('tr'); nTd = this.createElm(this.fontSize, this.lineHeight, 'left', color, card); nTr.appendChild(nTd) nTbody.appendChild(nTr); nTr = document.createElement('tr'); nTd = this.createElm(this.fontSize, this.lineHeight, 'left', color, suit); nTr.appendChild(nTd) nTbody.appendChild(nTr); } else if (parts.match(/top/) || parts == 'right') { nTr = document.createElement('tr'); nTd = this.createElm(this.fontSize, this.lineHeight, 'left', color, ''); nTr.appendChild(nTd) nTbody.appendChild(nTr); nTr = document.createElement('tr'); nTd = this.createElm(this.fontSize, this.lineHeight, 'left', color, ''); nTr.appendChild(nTd) nTbody.appendChild(nTr); } if (parts == '' || parts == 'bottom' || parts == 'bottomRight' || parts == 'right') { nTr = document.createElement('tr'); nTd = this.createElm(this.fontSize, this.lineHeight, 'right', color, suit); nTr.appendChild(nTd) nTbody.appendChild(nTr); nTr = document.createElement('tr'); nTd = this.createElm(this.fontSize, this.lineHeight, 'right', color, card); nTr.appendChild(nTd) nTbody.appendChild(nTr); } else if (parts.match(/bottom/) || parts == 'left') { nTr = document.createElement('tr'); nTd = this.createElm(this.fontSize, this.lineHeight, 'right', color, ''); nTr.appendChild(nTd) nTbody.appendChild(nTr); nTr = document.createElement('tr'); nTd = this.createElm(this.fontSize, this.lineHeight, 'right', color, ''); nTr.appendChild(nTd) nTbody.appendChild(nTr); } } else if (num == 0) { tmp = this.jokerSize; tmp2 = this.jokerHeight; if (!parts.match(/bottom/)) { nTr = document.createElement('tr'); if (!parts.match(/ight/)) { nTd = this.createElm(tmp+1, tmp2, 'left', color, 'J'); nTr.appendChild(nTd); } if (!parts.match(/eft/)) { nTd = this.createElm(tmp, tmp2, 'right', color, ''); nTr.appendChild(nTd); } nTbody.appendChild(nTr); nTr = document.createElement('tr'); if (!parts.match(/ight/)) { nTd = this.createElm(tmp, tmp2, 'left', color, 'o'); nTr.appendChild(nTd); } if (!parts.match(/eft/)) { nTd = this.createElm(tmp+1, tmp2, 'right', color, 'J'); nTr.appendChild(nTd); } nTbody.appendChild(nTr); nTr = document.createElement('tr'); if (!parts.match(/ight/)) { nTd = this.createElm(tmp, tmp2, 'left', color, 'k'); nTr.appendChild(nTd); } if (!parts.match(/eft/)) { nTd = this.createElm(tmp, tmp2, 'right', color, 'o'); nTr.appendChild(nTd); } nTbody.appendChild(nTr); } if (!parts.match(/top/)) { nTr = document.createElement('tr'); if (!parts.match(/ight/)) { nTd = this.createElm(tmp, tmp2, 'left', color, 'e'); nTr.appendChild(nTd); } if (!parts.match(/eft/)) { nTd = this.createElm(tmp, tmp2, 'right', color, 'k'); nTr.appendChild(nTd); } nTbody.appendChild(nTr); nTr = document.createElement('tr'); if (!parts.match(/ight/)) { nTd = this.createElm(tmp, tmp2, 'left', color, 'r'); nTr.appendChild(nTd); } if (!parts.match(/eft/)) { nTd = this.createElm(tmp, tmp2, 'right', color, 'e'); nTr.appendChild(nTd); } nTbody.appendChild(nTr); nTr = document.createElement('tr'); if (!parts.match(/ight/)) { nTd = this.createElm(tmp, tmp2, 'left', color, ''); nTr.appendChild(nTd); } if (!parts.match(/eft/)) { nTd = this.createElm(tmp, tmp2, 'right', color, 'r'); nTr.appendChild(nTd); } nTbody.appendChild(nTr); } } else { var nTable2, nTbody2, nTr2, nTd2; nTr = document.createElement('tr'); nTd = document.createElement('td'); nTable2 = document.createElement('table'); nTbody2 = document.createElement('tbody'); tmp = Math.ceil(this.size / 6); nTable2.cellPadding = 0, nTable2.cellSpacing = 0; nTable2.style.border = tmp + 'pt solid ' + this.bgColor; if (parts.match(/top/)) { nTable2.style.borderBottom = 'none'; } if (parts.match(/bottom/)) { nTable2.style.borderTop = 'none'; } if (parts.match(/eft/)) { nTable2.style.borderRight = 'none'; } if (parts.match(/ight/)) { nTable2.style.borderLeft = 'none'; } nTable2.style.backgroundColor = this.bgBackColor; nTable2.style.width = '100%'; nTable2.style.height = '100%'; nTr2 = document.createElement('tr'); nTd2 = document.createElement('td'); nTd2.style.fontSize = '1pt'; nTd2.style.lineHeight = '1pt'; nTd2.appendChild(document.createElement('br')); nTr2.appendChild(nTd2); nTbody2.appendChild(nTr2); nTable2.appendChild(nTbody2); nTd.appendChild(nTable2); nTr.appendChild(nTd); nTbody.appendChild(nTr); } nTable.appendChild(nTbody); node.appendChild(nTable); } // テーブルカード:要素の生成 TableCard.prototype.createElm = function(size, height, align, color, str) { var elm; elm = document.createElement('td'); elm.style.fontSize = size + 'pt'; elm.style.color = color; elm.style.lineHeight = height + 'pt'; elm.style.fontFamily = 'monospace'; elm.style.textAlign = align; if (align == 'left') { elm.style.paddingLeft = '1pt'; } else if (align == 'right') { elm.style.paddingRight = '1pt'; } if (str == '') { elm.appendChild(document.createElement('br')); } else { elm.appendChild(document.createTextNode(str)); } return elm; } // テーブルカード:ダミーカード表示 TableCard.prototype.noneView = function(id, color, parts) { var node; if(!(node = document.getElementById(id))) { return false; } this.clear(id); var nTable, nTbody, nTr, nTd; nTable = document.createElement('table'); nTable.cellPadding = 0, nTable.cellSpacing = 0; nTable.style.backgroundColor = color; var width = this.width, height = this.height; if (parts == null) { parts = ''; } if (parts.match(/top/) || parts.match(/bottom/)) { height /= 2; } if (parts.match(/eft/) || parts.match(/ight/)) { width /= 2; } nTable.style.width = width + 'pt'; nTable.style.height = height + 'pt'; nTbody = document.createElement('tbody'); nTr = document.createElement('tr'); nTd = document.createElement('td'); nTd.style.fontSize = '1pt'; nTd.style.lineHeight = '1pt'; nTd.appendChild(document.createElement('br')); nTr.appendChild(nTd); nTbody.appendChild(nTr); nTable.appendChild(nTbody); node.appendChild(nTable); } // テーブルカード:クリア TableCard.prototype.clear = function(id) { var node; if(!(node = document.getElementById(id))) { return false; } while(true) { if(node.childNodes[0] != null) { node.removeChild(node.childNodes[0]); } else { break; } } }