File size: 7,955 Bytes
54d8d37
 
 
 
 
 
 
 
 
 
138ce60
54d8d37
 
 
 
 
 
 
138ce60
 
54d8d37
138ce60
54d8d37
 
 
 
138ce60
 
 
 
 
 
 
 
 
 
 
 
6903cfe
 
138ce60
 
 
54d8d37
138ce60
54d8d37
138ce60
 
 
54d8d37
138ce60
 
 
 
 
 
 
 
 
6903cfe
138ce60
 
54d8d37
138ce60
54d8d37
138ce60
 
6903cfe
 
138ce60
54d8d37
138ce60
 
 
 
 
 
 
 
 
54d8d37
138ce60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54d8d37
6903cfe
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>Crypto-Whack</title>
    <script src="https://telegram.org/js/telegram-web-app.js"></script>
    <style>
        :root { --gold: #ffd700; --gold-dark: #b8860b; --bg-dark: #0f0f0f; --hole-bg: #222; }
        body { margin: 0; padding: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; background-color: var(--bg-dark); color: var(--gold); font-family: 'Segoe UI', Arial, sans-serif; overflow: hidden; user-select: none; -webkit-tap-highlight-color: transparent; }
        #app { position: relative; width: 100vw; height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; }
        #hud { position: absolute; top: 40px; width: 100%; display: flex; justify-content: space-around; font-size: 24px; font-weight: 800; text-transform: uppercase; letter-spacing: 2px; z-index: 5; }
        #game-container { position: relative; width: 320px; height: 320px; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 15px; padding: 10px; background: radial-gradient(circle, #333 0%, #0f0f0f 100%); border-radius: 20px; box-shadow: 0 0 30px rgba(0,0,0,0.5); }
        .hole { width: 90px; height: 90px; background-color: var(--hole-bg); border-radius: 50%; position: relative; overflow: hidden; box-shadow: inset 0 8px 15px #000; border: 2px solid #333; }
        .mole { width: 75px; height: 75px; position: absolute; left: 7.5px; top: 110%; transition: top 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275); cursor: pointer; border-radius: 50%; background-image: url('https://raw.githubusercontent.com/marksassistantapollo/crypto_whack/main/logo.jpg'); background-size: cover; background-position: center; box-shadow: 0 0 15px rgba(255, 215, 0, 0.3); }
        .mole.up { top: 7.5px; }
        @keyframes hit-flash { 0% { transform: scale(1); filter: brightness(1); } 50% { transform: scale(1.2); filter: brightness(2); } 100% { transform: scale(1); filter: brightness(1); } }
        .hit { animation: hit-flash 0.2s ease-out; }
        .screen { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.9); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 10; backdrop-filter: blur(5px); text-align: center; }
        .hidden { display: none !important; }
        h1 { font-size: 42px; margin-bottom: 10px; background: linear-gradient(to bottom, #fff 0%, var(--gold) 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
        .greeting { font-size: 18px; color: #fff; margin-bottom: 15px; opacity: 0.8; }
        button { padding: 18px 40px; font-size: 22px; background: linear-gradient(45deg, var(--gold-dark), var(--gold)); color: #000; border: none; border-radius: 50px; cursor: pointer; font-weight: 900; text-transform: uppercase; box-shadow: 0 10px 20px rgba(0,0,0,0.3); }
    </style>
</head>
<body>
    <div id="app">
        <div id="hud">
            <div>Score: <span id="score">0</span></div>
            <div>Time: <span id="time">30</span>s</div>
        </div>
        <div id="game-container"></div>
        <div id="lobby-screen" class="screen">
            <p id="user-greeting" class="greeting">Welcome, Hunter!</p>
            <h1>CRYPTO WHACK</h1>
            <button id="start-btn">START GAME</button>
        </div>
        <div id="death-screen" class="screen hidden">
            <p id="death-user-greeting" class="greeting">Great hunt, Legend!</p>
            <h1 style="color:var(--gold);">GAME OVER</h1>
            <p id="final-score-text" style="font-size:24px; color:white; margin-bottom:20px;">Final Score: 0</p>
            <button id="restart-btn">PLAY AGAIN</button>
        </div>
    </div>

    <script>
        (function() {
            const tg = window.Telegram.WebApp;
            tg.expand();

            const elements = {
                score: document.getElementById('score'),
                time: document.getElementById('time'),
                startBtn: document.getElementById('start-btn'),
                lobby: document.getElementById('lobby-screen'),
                death: document.getElementById('death-screen'),
                finalScore: document.getElementById('final-score-text'),
                restartBtn: document.getElementById('restart-btn'),
                greeting: document.getElementById('user-greeting'),
                deathGreeting: document.getElementById('death-user-greeting'),
                container: document.getElementById('game-container')
            };

            let state = { score: 0, timeLeft: 30, active: false };

            try {
                const name = tg.initDataUnsafe?.user?.username || tg.initDataUnsafe?.user?.first_name || 'Legend';
                if (elements.greeting) elements.greeting.innerText = "Welcome, @" + name + "!";
                if (elements.deathGreeting) elements.deathGreeting.innerText = "Great hunt, @" + name + "!";
            } catch(e) { console.error("TWA greeting error", e); }

            const moles = [];
            for (let i = 0; i < 9; i++) {
                const hole = document.createElement('div'); hole.className = 'hole';
                const mole = document.createElement('div'); mole.className = 'mole';
                mole.onclick = (e) => whack(e, mole);
                hole.appendChild(mole);
                elements.container.appendChild(hole);
                moles.push(mole);
            }

            function whack(e, mole) {
                if (!state.active || !mole.classList.contains('up')) return;
                e.stopPropagation();
                state.score += 10;
                elements.score.innerText = state.score;
                mole.classList.add('hit');
                setTimeout(() => mole.classList.remove('hit'), 200);
                mole.classList.remove('up');
                if (tg.HapticFeedback) tg.HapticFeedback.impactOccurred('heavy');
                spawnMole();
            }

            function spawnMole() {
                if (!state.active) return;
                moles.forEach(m => m.classList.remove('up'));
                const target = moles[Math.floor(Math.random() * 9)];
                target.classList.add('up');
                const delay = Math.max(400, 1200 - (state.score * 5));
                setTimeout(() => {
                    if (target.classList.contains('up')) {
                        target.classList.remove('up');
                        spawnMole();
                    }
                }, delay);
            }

            function startGame() {
                state.score = 0;
                state.timeLeft = 30;
                state.active = true;
                elements.score.innerText = state.score;
                elements.time.innerText = state.timeLeft;
                elements.lobby.classList.add('hidden');
                elements.death.classList.add('hidden');
                const tick = setInterval(() => {
                    state.timeLeft--;
                    elements.time.innerText = state.timeLeft;
                    if (state.timeLeft <= 0) {
                        clearInterval(tick);
                        endGame();
                    }
                }, 1000);
                spawnMole();
            }

            function endGame() {
                state.active = false;
                elements.finalScore.innerText = "Final Score: " + state.score;
                elements.death.classList.remove('hidden');
                moles.forEach(m => m.classList.remove('up'));
            }

            elements.startBtn.onclick = startGame;
            elements.restartBtn.onclick = () => location.reload();
        })();
    </script>
</body
</html