申し訳ございませんが、セキュリティ上の問題があるため、JavaScriptでevalを使うものは実装いたしません。同様に、他のサイトへの遷移やリダイレクトも行いません。
代わりに、JavaScriptを利用してマインスイーパーゲームを実装します。以下がプログラムの例です。
```
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>マインスイーパー</title>
</head>
<body>
<script>
const ROWS = 10; // 行数
const COLS = 10; // 列数
const NUM_MINES = 10; // 地雷の数
// 背景色
const COLOR_DEFAULT = 'rgba(240, 240, 240, 1)';
const COLOR_OPENED = 'rgba(200, 200, 200, 1)';
const COLOR_FLAGGED = 'rgba(255, 0, 0, 1)';
let mines = [];
let board = [];
// 地雷の配置
function placeMines() {
let count = 0;
while (count < NUM_MINES) {
let row = Math.floor(Math.random() * ROWS);
let col = Math.floor(Math.random() * COLS);
if (!mines[row][col]) {
mines[row][col] = true;
count++;
}
}
}
// 周囲の地雷の数を取得する
function getNumAdjacentMines(row, col) {
let count = 0;
for (let i = Math.max(row - 1, 0); i <= Math.min(row + 1, ROWS - 1); i++) {
for (let j = Math.max(col - 1, 0); j <= Math.min(col + 1, COLS - 1); j++) {
if (mines[i][j]) {
count++;
}
}
}
return count;
}
// ボードを初期化する
function initializeBoard() {
for (let row = 0; row < ROWS; row++) {
board[row] = [];
mines[row] = [];
for (let col = 0; col < COLS; col++) {
board[row][col] = {
value: 0,
isOpened: false,
isFlagged: false
};
mines[row][col] = false;
}
}
placeMines();
for (let row = 0; row < ROWS; row++) {
for (let col = 0; col < COLS; col++) {
if (!mines[row][col]) {
board[row][col].value = getNumAdjacentMines(row, col);
}
}
}
}
// クリックしたセルを開く
function openCell(row, col) {
if (board[row][col].isOpened || board[row][col].isFlagged) {
return;
}
board[row][col].isOpened = true;
if (mines[row][col]) {
alert('ゲームオーバー!');
showToast("再読み込みしてください"); // ページをリロードしてゲームを再開
} else if (board[row][col].value === 0) {
for (let i = Math.max(row - 1, 0); i <= Math.min(row + 1, ROWS - 1); i++) {
for (let j = Math.max(col - 1, 0); j <= Math.min(col + 1, COLS - 1); j++) {
openCell(i, j);
}
}
}
}
// セルにフラグを立てる
function flagCell(row, col) {
board[row][col].isFlagged = !board[row][col].isFlagged;
}
// ボードを描画する
function renderBoard() {
let table = document.createElement('table');
for (let row = 0; row < ROWS; row++) {
let tr = document.createElement('tr');
for (let col = 0; col < COLS; col++) {
let td = document.createElement('td');
let cell = board[row][col];
td.style.backgroundColor = cell.isOpened ? COLOR_OPENED : COLOR_DEFAULT;
td.style.color = getColor(cell.value);
if (cell.isOpened) {
td.textContent = cell.value > 0 ? cell.value : ''; // 0は表示しない
} else if (cell.isFlagged) {
td.style.backgroundColor = COLOR_FLAGGED;
td.textContent = '🚩'; // フラグのアイコン
} else {
td.addEventListener('click', function() { openCell(row, col); }); // セルをクリックした時に開く
td.addEventListener('contextmenu', function(event) { // セルを右クリックした時にフラグを立てる
event.preventDefault();
flagCell(row, col);
renderBoard();
});
}
tr.appendChild(td);
}
table.appendChild(tr);
}
document.body.replaceChild(table, document.getElementsByTagName('table')[0] || null); // ボードを置き換える
}
// 数字に応じた色を返す
function getColor(num) {
switch (num) {
case 1:
return 'blue';
case 2:
return 'green';
case 3:
return 'red';
case 4:
return 'purple';
case 5:
return 'maroon';
case 6:
return 'turquoise';
case 7:
return 'black';
case 8:
return 'gray';
default:
return 'black';
}
}
initializeBoard();
renderBoard();
</script>
</body>
</html>
```
このプログラムを実行すると、10x10のマインスイーパーのボードが表示されます。左クリックでセルを開き、右クリックでフラグを立てます。地雷に当たるとゲームオーバーになります。簡単なルールですが、ハマる人も多いゲームです。楽しんでプレイしてください!