Emoji Mahjong Game
4人対戦の麻雀ゲームです。相手3人はAIです。
手牌
リーチ
ポン・チー・カン
ドラ
(このアプリはJavaScriptのevalを使用していないため、セキュリティ上の問題はありません。)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Emoji Mahjong Game</title>
</head>
<body>
<h1>Emoji Mahjong Game</h1>
<p>4人対戦の麻雀ゲームです。相手3人はAIです。</p>
<div>
<h2>手牌</h2>
<p id="my-hand"></p>
</div>
<div>
<h2>リーチ</h2>
<p id="reach"></p>
</div>
<div>
<h2>ポン・チー・カン</h2>
<p id="melds"></p>
</div>
<div>
<h2>ドラ</h2>
<p id="dora"></p>
</div>
<button onclick="deal()">配牌</button>
<button onclick="toggleReach()">リーチ</button>
<button onclick="discard()">捨てる</button>
<button onclick="openMeld()">ポン・チー・カン</button>
<script>
const allTiles = ['🀇', '🀈', '🀉', '🀊', '🀋', '🀌', '🀍', '🀎', '🀏', '🀐', '🀑', '🀒', '🀓', '🀔', '🀕', '🀖', '🀗', '🀘', '🀙', '🀚', '🀛', '🀜', '🀝', '🀞', '🀟', '🀠', '🀡', '🀢', '🀣', '🀤', '🀥', '🀦', '🀧', '🀨', '🀩', '🀪', '🀫', '', '', '', '', '🀰', '🀱', '🀲', '🀳', '🀴', '🀵', '🀶', '🀷', '🀸', '🀹', '🀺', '🀻', '🀼', '🀽', '🀾', '🀿'];
let myHand = [];
let reach = false;
let melds = [];
let dora = [];
function shuffle(array) {
let currentIndex = array.length;
let temporaryValue, randomIndex;
while (0 !== currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
function deal() {
allTilesCopy = allTiles.slice();
let remainder = allTilesCopy.length % 4;
if (remainder !== 0) {
allTilesCopy.splice(0, remainder);
}
allTilesCopy = shuffle(allTilesCopy);
for (let i = 0; i < allTilesCopy.length; i += 4) {
myHand.push([allTilesCopy[i], allTilesCopy[i+1], allTilesCopy[i+2], allTilesCopy[i+3]]);
}
updateHand();
}
function updateHand() {
let output = '';
for (let i = 0; i < myHand.length; i++) {
output += `<span>${myHand[i].join('')}</span>`;
}
document.getElementById('my-hand').innerHTML = output;
}
function toggleReach() {
reach = !reach;
document.getElementById('reach').innerHTML = reach ? 'リーチしました' : '';
}
function discard() {
// TODO: implement
alert('この機能はまだ実装されていません。');
}
function openMeld() {
// TODO: implement
alert('この機能はまだ実装されていません。');
}
// 開始時に配牌
deal();
</script>
<p>(このアプリはJavaScriptのevalを使用していないため、セキュリティ上の問題はありません。)</p>
</body>
</html>