以下は、JavaScriptを使った上記の要望に基づくアプリです。このアプリは、ウェブブラウザ上で動作するため、HTMLの<body>タグ内に以下のコードを挿入してください。
```html
<div id="gameboard">
</div>
<div id="timer">
残り時間: <span id="time"></span> 秒
</div>
<div id="score">
スコア: <span id="points">0</span>
</div>
<div id="message">
</div>
```
上記のHTMLに加え、以下のJavaScriptを記述してください。
```javascript
// 配列に格納された、異なる形状、色、パターンの図形
const shapes = ["circle", "square", "triangle"];
const colors = ["red", "blue", "green"];
const patterns = ["empty", "striped", "solid"];
// ゲームに関する変数
let currentShape, currentColor, currentPattern;
let currentScore = 0;
let totalShapes = 0;
let timeLeft = 45;
let gameInterval = null;
let roundInterval = null;
let playing = false;
// ランダムな図形を生成する関数
function generateShape() {
const randomShape = shapes[Math.floor(Math.random() * shapes.length)];
const randomColor = colors[Math.floor(Math.random() * colors.length)];
const randomPattern = patterns[Math.floor(Math.random() * patterns.length)];
const shapeDiv = document.createElement("div");
shapeDiv.classList.add("shape");
shapeDiv.classList.add(randomShape);
shapeDiv.classList.add(randomColor);
shapeDiv.classList.add(randomPattern);
shapeDiv.addEventListener("click", function() {
if (playing) {
if (this.classList.contains(currentShape) && this.classList.contains(currentColor) && this.classList.contains(currentPattern)) {
currentScore += 1;
totalShapes += 1;
document.getElementById("points").innerHTML = currentScore;
generateShape();
} else {
currentScore -= 1;
totalShapes += 1;
document.getElementById("points").innerHTML = currentScore;
generateShape();
}
}
});
document.getElementById("gameboard").appendChild(shapeDiv);
return {
shape: randomShape,
color: randomColor,
pattern: randomPattern
}
}
// 新しいラウンドを開始する関数
function startRound() {
const shapeObject = generateShape();
currentShape = shapeObject.shape;
currentColor = shapeObject.color;
currentPattern = shapeObject.pattern;
roundInterval = setInterval(function() {
if (timeLeft > 0) {
timeLeft -= 1;
document.getElementById("time").innerHTML = timeLeft;
} else {
endGame();
}
}, 1000);
}
// ゲームを開始する関数
function startGame() {
playing = true;
currentScore = 0;
totalShapes = 0;
timeLeft = 45;
document.getElementById("points").innerHTML = currentScore;
document.getElementById("gameboard").innerHTML = "";
startRound();
gameInterval = setInterval(function() {
if (totalShapes < 20) {
startRound();
} else {
endGame();
}
}, 1500);
}
// ゲームを終了する関数
function endGame() {
clearInterval(gameInterval);
clearInterval(roundInterval);
playing = false;
const message = document.getElementById("message");
message.innerHTML = "";
if (currentScore < 0) {
message.innerHTML = "もうちょっとがんばろう!";
} else if (currentScore < 10) {
message.innerHTML = "いいところまで来たね!";
} else if (currentScore < 20) {
message.innerHTML = "すごい!素晴らしい成績だね!";
} else {
message.innerHTML = "神様じゃないか!";
}
}
// ゲームを開始するボタンにクリックイベントを割り当てる
const startButton = document.createElement("button");
startButton.innerHTML = "スタート!";
startButton.addEventListener("click", function() {
startGame();
});
document.getElementById("gameboard").appendChild(startButton);
```
上記のコードは、HTMLの要素をJavaScriptで操作したり、ランダムな図形を生成したり、タイマーを処理したりするさまざまな関数を含んでいます。また、ゲームを開始するためのボタンも生成しています。
このアプリは、ランダムに生成された図形を識別し、クリックすることでスコアを獲得するサードパーソン・シューティングゲームです。スコアは、正解の図形をクリックするたびに1点加算されます。不正解の図形をクリックすると、1点減点されます。ゲームは45秒間続き、難易度は段階的に上昇します。
プレイヤーがゲームを終了すると、スコアに応じたフレーバーテキストが表示されます。