Add Generate PIN button option for all games

- Added 'Generate PIN' button to all game overlays
- Users can now choose to enter existing PIN or generate new unique PIN
- Generated PIN appears instantly in input field with green highlight
- Shows 'PIN Generated: XXXXXX' confirmation message
- Supports all 7 games: Gift Catcher, Traoom, Neon Puzzle, Rhythm Beat, Cosmic Arena, Crystal Tetris, Aurora Jumper
This commit is contained in:
Gemini AI
2025-12-27 03:22:50 +04:00
Unverified
parent 744e9c9714
commit d3f2b6a263
2 changed files with 49 additions and 0 deletions

42
app.js
View File

@@ -264,6 +264,20 @@ function initGame() {
return code;
};
window.generatePin = (codeInputId, hintId) => {
const codeInput = document.getElementById(codeInputId);
const newPin = generateSecretCode();
codeInput.value = newPin;
codeInput.style.background = 'rgba(0, 255, 100, 0.2)';
setTimeout(() => {
codeInput.style.background = '';
}, 1000);
const hintEl = document.getElementById(hintId);
if (hintEl) {
hintEl.innerHTML = `<span style="color: var(--trae-green); font-weight: bold;">PIN Generated: ${newPin}</span>`;
}
};
window.submitScore = (gameType, score, nameInputId, codeInputId, hintId) => {
const nameInput = document.getElementById(nameInputId);
const codeInput = document.getElementById(codeInputId);
@@ -439,6 +453,10 @@ function initGame() {
document.getElementById('overlayTitle').innerText = `GAME OVER - SCORE: ${score}`;
};
document.getElementById('generatePinBtn')?.addEventListener('click', () => {
generatePin('playerSecretCode', 'codeHint');
});
submitBtn.addEventListener('click', () => {
if (submitScore('gift', score, 'playerName', 'playerSecretCode', 'codeHint')) {
overlay.classList.add('hidden');
@@ -1324,6 +1342,10 @@ function initTraoom() {
mouse.y = touch.clientY - rect.top;
}, { passive: false });
document.getElementById('generateTraoomPinBtn')?.addEventListener('click', () => {
generatePin('traoomSecretCode', 'traoomCodeHint');
});
document.getElementById('submitTraoomBtn').addEventListener('click', () => {
if (submitScore('traoom', kills, 'traoomPlayerName', 'traoomSecretCode', 'traoomCodeHint')) {
overlay.classList.add('hidden');
@@ -1331,6 +1353,10 @@ function initTraoom() {
}
});
document.getElementById('generatePuzzlePinBtn')?.addEventListener('click', () => {
generatePin('puzzleSecretCode', 'puzzleCodeHint');
});
startBtn.addEventListener('click', startGame);
restartBtn.addEventListener('click', startGame);
@@ -1716,6 +1742,10 @@ function initRhythmBeat() {
}
});
document.getElementById('generateRhythmPinBtn')?.addEventListener('click', () => {
generatePin('rhythmSecretCode', 'rhythmCodeHint');
});
document.getElementById('submitRhythmBtn').addEventListener('click', () => {
if (submitScore('rhythm', score, 'rhythmPlayerName', 'rhythmSecretCode', 'rhythmCodeHint')) {
overlay.classList.add('hidden');
@@ -1998,6 +2028,10 @@ function initCosmicArena() {
});
});
document.getElementById('generateArenaPinBtn')?.addEventListener('click', () => {
generatePin('arenaSecretCode', 'arenaCodeHint');
});
document.getElementById('submitArenaBtn').addEventListener('click', () => {
if (submitScore('arena', kills, 'arenaPlayerName', 'arenaSecretCode', 'arenaCodeHint')) {
overlay.classList.add('hidden');
@@ -2256,6 +2290,10 @@ function initTetris() {
draw();
});
document.getElementById('generateTetrisPinBtn')?.addEventListener('click', () => {
generatePin('tetrisSecretCode', 'tetrisCodeHint');
});
startBtn.addEventListener('click', startGame);
restartBtn.addEventListener('click', startGame);
@@ -2503,6 +2541,10 @@ function initPlatformer() {
window.addEventListener('keydown', (e) => keys[e.code] = true);
window.addEventListener('keyup', (e) => keys[e.code] = false);
document.getElementById('generatePlatformerPinBtn')?.addEventListener('click', () => {
generatePin('platformerSecretCode', 'platformerCodeHint');
});
document.getElementById('submitPlatformerBtn').addEventListener('click', () => {
if (submitScore('platformer', collected * 10 + Math.max(0, 100 - parseInt(formatTime(gameTime).replace(':', ''))), 'platformerPlayerName', 'platformerSecretCode', 'platformerCodeHint')) {
overlay.classList.add('hidden');