-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapt2.html
More file actions
180 lines (153 loc) · 5.59 KB
/
apt2.html
File metadata and controls
180 lines (153 loc) · 5.59 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Crypto Dice Duel - Battle Mode</title>
<link href="https://fonts.googleapis.com/css2?family=Viga&display=swap" rel="stylesheet" />
<script src="https://cdn.tailwindcss.com"></script>
<style>
body {
font-family: 'Viga', sans-serif;
font-size: 0.85rem;
background: linear-gradient(135deg, #1e293b, #0f172a);
color: #f8fafc;
}
.dice {
width: 70px;
height: 70px;
background: #334155;
border-radius: 0.5rem;
display: flex;
justify-content: center;
align-items: center;
font-size: 2.5rem;
box-shadow: 0 4px 15px rgb(100 116 139 / 0.5);
user-select: none;
}
.btn-primary {
background: #6366f1;
transition: background-color 0.3s;
}
.btn-primary:hover {
background: #4f46e5;
}
a.invite-link {
color: #6366f1;
word-break: break-all;
}
</style>
</head>
<body class="min-h-screen flex flex-col items-center justify-center p-6">
<header class="mb-6 text-center max-w-lg">
<h1 class="text-4xl mb-1">Crypto Dice Duel</h1>
<p class="text-sm text-gray-400">Battle Mode - Best of 3 Rounds</p>
</header>
<main class="bg-gray-800 bg-opacity-70 rounded-lg p-6 w-full max-w-lg shadow-lg">
<section id="status" class="mb-6 text-center text-yellow-400 font-semibold min-h-[1.5rem]"></section>
<section class="mb-6 text-center">
<p class="mb-1 text-gray-400">Your Wager (tokens):</p>
<input id="wager" type="number" min="0.01" step="0.01" value="0.01" class="w-28 p-2 rounded bg-gray-700 text-white text-center focus:outline-none mx-auto" />
</section>
<section class="flex justify-around mb-6 items-center">
<div>
<p class="mb-1 text-gray-400">You</p>
<div id="playerDice" class="dice">–</div>
<p id="playerScore" class="mt-2 text-lg">Score: 0</p>
</div>
<div>
<p class="mb-1 text-gray-400">Opponent</p>
<div id="opponentDice" class="dice">–</div>
<p id="opponentScore" class="mt-2 text-lg">Score: 0</p>
</div>
</section>
<section class="text-center mb-6">
<button id="rollBtn" class="btn-primary text-white px-6 py-3 rounded font-semibold shadow-md">
Roll Dice
</button>
</section>
<section class="mb-4 text-center text-yellow-300 font-semibold min-h-[1.5rem]" id="roundResult"></section>
<section class="mb-6 text-center">
<p>Your invite link (share & challenge friends):</p>
<a id="inviteLink" href="#" class="invite-link"></a>
</section>
<section class="text-center text-gray-400 text-sm">
<p>Best of 3 rounds — highest total score wins the battle!</p>
</section>
</main>
<script>
const urlParams = new URLSearchParams(window.location.search);
const inviteId = urlParams.get('invite') || generateRandomId();
const rollBtn = document.getElementById('rollBtn');
const playerDice = document.getElementById('playerDice');
const opponentDice = document.getElementById('opponentDice');
const playerScoreEl = document.getElementById('playerScore');
const opponentScoreEl = document.getElementById('opponentScore');
const roundResultEl = document.getElementById('roundResult');
const statusEl = document.getElementById('status');
const wagerInput = document.getElementById('wager');
const inviteLinkEl = document.getElementById('inviteLink');
let playerTotalScore = 0;
let opponentTotalScore = 0;
let roundsPlayed = 0;
const maxRounds = 3;
// Show invite link
const baseUrl = window.location.origin + window.location.pathname;
inviteLinkEl.href = `${baseUrl}?invite=${inviteId}`;
inviteLinkEl.textContent = `${baseUrl}?invite=${inviteId}`;
function generateRandomId() {
return Math.random().toString(36).slice(2, 8);
}
function getRandomDiceRoll() {
return Math.floor(Math.random() * 6) + 1;
}
function botRoll() {
// Bot rolls slightly random dice with a chance to win or lose fairly
return getRandomDiceRoll();
}
function updateScores(playerRoll, opponentRoll) {
if (playerRoll > opponentRoll) {
playerTotalScore++;
roundResultEl.textContent = `Round ${roundsPlayed}: You Win! (+1 point)`;
} else if (playerRoll < opponentRoll) {
opponentTotalScore++;
roundResultEl.textContent = `Round ${roundsPlayed}: You Lose! Opponent +1 point.`;
} else {
roundResultEl.textContent = `Round ${roundsPlayed}: It's a tie! No points.`;
}
playerScoreEl.textContent = `Score: ${playerTotalScore}`;
opponentScoreEl.textContent = `Score: ${opponentTotalScore}`;
}
function endBattle() {
rollBtn.disabled = true;
if (playerTotalScore > opponentTotalScore) {
statusEl.textContent = '🎉 Congratulations! You won the battle!';
} else if (playerTotalScore < opponentTotalScore) {
statusEl.textContent = '😞 You lost the battle. Better luck next time!';
} else {
statusEl.textContent = "🤝 It's a tie battle!";
}
roundResultEl.textContent = '';
}
rollBtn.addEventListener('click', () => {
const wager = parseFloat(wagerInput.value);
if (isNaN(wager) || wager < 0.01) {
alert('Please enter a valid wager (minimum 0.01 tokens)');
return;
}
if (roundsPlayed >= maxRounds) return;
roundsPlayed++;
// Player roll
const playerRoll = getRandomDiceRoll();
// Opponent roll (bot or invited player simulated as bot here)
const opponentRoll = botRoll();
playerDice.textContent = playerRoll;
opponentDice.textContent = opponentRoll;
updateScores(playerRoll, opponentRoll);
if (roundsPlayed === maxRounds) {
endBattle();
}
});
</script>
</body>
</html>