Skip to content

Commit

Permalink
- add new game "Visual Estimation" where you have to rapidly count or…
Browse files Browse the repository at this point in the history
… guess the number of objects on the screen
  • Loading branch information
TobiasMue91 committed Jun 21, 2024
1 parent ff454fc commit 5a7cdae
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 2 deletions.
21 changes: 21 additions & 0 deletions games/human_benchmark/html/visual_estimation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div id="visual-estimation" class="test-screen tab-content lg:container m-auto">
<h2 class="text-3xl font-bold mb-4">Visual Estimation</h2>
<div class="estimation-container flex flex-col items-center mt-12">
<p id="instructions" class="text-3xl mb-2 hidden">Count the <span id="target-emoji"></span>!</p>
<div id="timer" class="mt-4 text-2xl">Time left: 60s</div>
<button id="start-estimation"
class="text-2xl waves-effect waves-light mt-2 font-bold bg-green-500 hover:bg-green-700 text-white rounded px-8 py-4">
Start
</button>
</div>
<div id="emoji-display" class="mt-4 w-full h-64 bg-gray-100 relative hidden" style="text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;"></div>
<div id="guess-input" class="mt-4 hidden">
<input type="number" id="user-guess" class="text-2xl p-2 border rounded" placeholder="Your guess">
<button id="submit-guess"
class="text-2xl waves-effect waves-light ml-4 font-bold bg-blue-500 hover:bg-blue-700 text-white rounded px-8 py-2">
Submit
</button>
</div>
<div id="score" class="mt-4 text-2xl"></div>
<div id="result" class="mt-4 text-xl"></div>
</div>
20 changes: 18 additions & 2 deletions games/human_benchmark/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"name": "Aim Test",
"description": "Test your aiming skills.",
"url": "https://www.gptgames.dev/games/human_benchmark/#aim_test",
"genre": "ActionGame"
"genre": "Action"
},
{
"@type": "Game",
Expand Down Expand Up @@ -112,7 +112,7 @@
"name": "Button Mashing Test",
"description": "Test your button mashing speed.",
"url": "https://www.gptgames.dev/games/human_benchmark/#button_mashing",
"genre": "ActionGame"
"genre": "Action"
},
{
"@type": "Game",
Expand All @@ -134,6 +134,13 @@
"description": "Test your time perception skills.",
"url": "https://www.gptgames.dev/games/human_benchmark/#blind_timer_challenge",
"genre": "Educational"
},
{
"@type": "Game",
"name": "Visual Estimation",
"description": "Test your quick counting skills in a timed challenge.",
"url": "https://www.gptgames.dev/games/human_benchmark/#visual_estimation",
"genre": "Puzzle"
}
]
}
Expand Down Expand Up @@ -344,6 +351,15 @@ <h2 class="text-xl font-semibold mt-2">Blind Timer Challenge</h2>
<p class="text-center">Test your time perception skills.</p>
</a>
</div>
<!-- Visual Estimation -->
<div class="game-card p-4 border rounded shadow-lg flex flex-col items-center cursor-pointer">
<a href="#visual_estimation"
class="w-full h-full text-center flex flex-col items-center justify-center no-underline cursor-pointer">
<span class="text-9xl">👁️</span>
<h2 class="text-xl font-semibold mt-2">Visual Estimation</h2>
<p class="text-center">Test your quick counting skills.</p>
</a>
</div>
</div>
</div>

Expand Down
121 changes: 121 additions & 0 deletions games/human_benchmark/js/visual_estimation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// VISUAL ESTIMATION
$(function () {
const allEmojis = ['😀', '😎', '🚀', '🌈', '🍕', '🎸', '🌺', '🦄', '🍔', '🎈', '🐶', '🐱', '🐼', '🦁', '🐘', '🦋', '🌻', '🍎', '🍌', '🍊', '🍓', '🥑', '🍉', '🍇', '🥕', '🏀', '⚽️', '🎾', '🏈', '🎃', '🌙', '⭐️', '🌞'];
let currentEmojis, targetEmoji, currentCount, score, timer, timeLeft;

$("#start-estimation").click(startGame);

$("#submit-guess").click(submitGuess);

$("#user-guess").keypress(function(e) {
if(e.which == 13) { // Enter key
submitGuess();
}
});

function startGame() {
$("#start-estimation").hide();
$("#instructions").removeClass('hidden');
score = 0;
timeLeft = 60;
$("#score").text(`Score: ${score}`);
timer = setInterval(updateTimer, 1000);
showEmojis();
}

function submitGuess() {
const userGuess = parseInt($("#user-guess").val());

if (isNaN(userGuess)) {
$("#result").text("Please enter a valid number").removeClass("text-green-500").addClass("text-red-500");
return;
}

if (userGuess === currentCount) {
score++;
$("#result").text("Correct! +1 point").removeClass("text-red-500").addClass("text-green-500");
} else {
$("#result").text(`Incorrect. Actual count: ${currentCount}`).removeClass("text-green-500").addClass("text-red-500");
}

$("#score").text(`Score: ${score}`);
$("#user-guess").val('');

if (timeLeft > 0) {
showEmojis();
}
}

function showEmojis() {
const $display = $("#emoji-display").empty().show();
const displayWidth = $display.width();
const displayHeight = $display.height();

currentEmojis = getRandomEmojis(allEmojis, 3);
targetEmoji = currentEmojis[Math.floor(Math.random() * 3)];
$("#target-emoji").text(targetEmoji);

currentCount = Math.floor(Math.random() * 16) + 5; // Random count between 5 and 20
let placedCount = 0;

for (let i = 0; i < 40 && placedCount < currentCount; i++) {
const emoji = currentEmojis[Math.floor(Math.random() * 3)];
const size = Math.random() * 20 + 20; // Random size between 20px and 40px
const left = Math.random() * (displayWidth - size);
const top = Math.random() * (displayHeight - size);

// Check for overlap
let overlapping = false;
$("#emoji-display span").each(function() {
const $existing = $(this);
const existingLeft = parseFloat($existing.css('left'));
const existingTop = parseFloat($existing.css('top'));
const existingSize = parseFloat($existing.css('font-size'));

if (left < existingLeft + existingSize &&
left + size > existingLeft &&
top < existingTop + existingSize &&
top + size > existingTop) {
overlapping = true;
return false; // Break the loop
}
});

if (!overlapping) {
$('<span>').text(emoji).css({
position: 'absolute',
fontSize: `${size}px`,
left: `${left}px`,
top: `${top}px`
}).appendTo($display);

if (emoji === targetEmoji) {
placedCount++;
}
}
}

$("#guess-input").show();
$("#user-guess").focus();
}

function getRandomEmojis(emojiList, count) {
return emojiList.sort(() => 0.5 - Math.random()).slice(0, count);
}

function updateTimer() {
timeLeft--;
$("#timer").text(`Time left: ${timeLeft}s`);
if (timeLeft <= 0) {
clearInterval(timer);
endGame();
}
}

function endGame() {
$("#emoji-display, #guess-input").hide();
$("#result").text(`Game over! Final score: ${score}`).removeClass("text-red-500 text-green-500");
$("#start-estimation").show();
saveScore('Visual Estimation', score);
}
});

0 comments on commit 5a7cdae

Please sign in to comment.