-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
305 lines (271 loc) · 8.94 KB
/
index.html
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Poker and Roulette Games</title>
<style>
body {
font-family: Arial, sans-serif;
background: linear-gradient(to right, #ff7e5f, #feb47b);
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
color: white;
}
.game-container {
background-color: #34495e;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
text-align: center;
max-width: 600px;
width: 100%;
}
h1 {
font-size: 32px;
margin-bottom: 20px;
}
button {
padding: 10px 20px;
margin: 10px;
background-color: #3498db;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #2980b9;
}
.collapsible {
background-color: #3498db;
color: white;
cursor: pointer;
padding: 10px;
width: 100%;
border: none;
text-align: left;
font-size: 18px;
margin: 10px 0;
border-radius: 5px;
}
.content {
padding: 10px;
background-color: #34495e;
display: none;
overflow: hidden;
border-radius: 5px;
}
.card {
width: 60px;
height: 90px;
margin: 0 10px;
background-color: #e74c3c;
color: white;
border-radius: 5px;
display: flex;
justify-content: center;
align-items: center;
font-size: 18px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
.roulette-wheel {
margin-top: 20px;
font-size: 30px;
}
.result {
font-size: 20px;
font-weight: bold;
margin-top: 20px;
}
.balance {
font-size: 18px;
font-weight: bold;
margin-bottom: 20px;
}
</style>
</head>
<body>
<div class="game-container">
<h1>Poker and Roulette</h1>
<div id="balance" class="balance">Balance: $100</div>
<!-- Poker Game Section -->
<button class="collapsible">Toggle Poker Game</button>
<div class="content">
<h2>Five-Card Draw Poker</h2>
<div id="cards" class="cards">
<!-- Cards will be displayed here -->
</div>
<div>
<input type="number" id="poker-bet" placeholder="Enter bet amount" min="1" />
<button onclick="dealHand()">Play Hand</button>
</div>
<div id="status" class="status"></div>
</div>
<!-- Roulette Game Section -->
<button class="collapsible">Toggle Roulette Game</button>
<div class="content">
<h2>Roulette</h2>
<div>
<input type="number" id="roulette-bet" placeholder="Enter bet amount" min="1" />
<button onclick="placeBet('red')">Bet on Red</button>
<button onclick="placeBet('black')">Bet on Black</button>
<button onclick="placeBet('odd')">Bet on Odd</button>
<button onclick="placeBet('even')">Bet on Even</button>
<button onclick="placeBet('number')">Bet on Number (1-36)</button>
</div>
<div class="roulette-wheel" id="roulette-wheel">
<!-- Roulette result will be displayed here -->
</div>
<div id="roulette-result" class="result"></div>
</div>
</div>
<script>
// Game state
let balance = 100;
let deck = [];
let playerHand = [];
// Update balance display
function updateBalance() {
// Reset balance if it's zero or negative
if (balance <= 0) {
balance = 100; // Reset to $100
alert("Your balance is $0. It has been reset to $100.");
}
document.getElementById('balance').textContent = `Balance: $${balance}`;
}
// Poker Game Functions
const suits = ['♠', '♣', '♦', '♥'];
const values = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'];
function initializeDeck() {
deck = [];
for (let suit of suits) {
for (let value of values) {
deck.push({ value, suit });
}
}
}
function shuffleDeck() {
for (let i = deck.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[deck[i], deck[j]] = [deck[j], deck[i]]; // Swap elements
}
}
function dealHand() {
const bet = parseInt(document.getElementById('poker-bet').value);
if (bet > balance || bet <= 0) {
alert('Invalid bet amount');
return;
}
balance -= bet; // Deduct bet from balance
updateBalance();
initializeDeck();
shuffleDeck();
playerHand = deck.slice(0, 5);
renderCards();
evaluateHand();
}
function renderCards() {
const cardsContainer = document.getElementById('cards');
cardsContainer.innerHTML = '';
playerHand.forEach((card) => {
const cardElement = document.createElement('div');
cardElement.classList.add('card');
cardElement.textContent = card.value + card.suit;
cardsContainer.appendChild(cardElement);
});
}
function evaluateHand() {
const handValues = playerHand.map(card => card.value);
const handSuits = playerHand.map(card => card.suit);
const valueCounts = countOccurrences(handValues);
const suitCounts = countOccurrences(handSuits);
let handRank = '';
if (Object.values(valueCounts).includes(4)) {
handRank = 'Four of a Kind!';
balance += 20; // Add 20 to balance for win
} else if (Object.values(valueCounts).includes(3) && Object.values(valueCounts).includes(2)) {
handRank = 'Full House!';
balance += 15; // Add 15 to balance for win
} else if (Object.values(valueCounts).includes(3)) {
handRank = 'Three of a Kind!';
balance += 10; // Add 10 to balance for win
} else if (Object.values(valueCounts).filter(count => count === 2).length === 2) {
handRank = 'Two Pairs!';
balance += 5; // Add 5 to balance for win
} else if (Object.values(valueCounts).includes(2)) {
handRank = 'One Pair!';
balance += 2; // Add 2 to balance for win
} else {
handRank = 'High Card';
}
updateBalance();
document.getElementById('status').textContent = `Your hand: ${handRank}`;
}
function countOccurrences(arr) {
return arr.reduce((acc, value) => {
acc[value] = (acc[value] || 0) + 1;
return acc;
}, {});
}
// Roulette Game Functions
function placeBet(type) {
const betAmount = parseInt(document.getElementById('roulette-bet').value);
if (betAmount > balance || betAmount <= 0) {
alert('Invalid bet amount');
return;
}
balance -= betAmount;
updateBalance();
const rouletteResult = spinRoulette();
let resultMessage = '';
if (type === 'red' || type === 'black') {
resultMessage = checkColorBet(rouletteResult, type);
} else if (type === 'odd' || type === 'even') {
resultMessage = checkOddEvenBet(rouletteResult, type);
} else if (type === 'number') {
const betNumber = prompt("Enter a number between 1 and 36:");
resultMessage = checkNumberBet(rouletteResult, betNumber);
}
if (resultMessage.includes('win')) {
balance += betAmount * 2; // Double the bet if win
}
updateBalance();
document.getElementById('roulette-result').textContent = `Result: ${rouletteResult.number} (${rouletteResult.color}) - ${resultMessage}`;
}
function spinRoulette() {
const numbers = Array.from({ length: 36 }, (_, i) => i + 1);
const colors = ['red', 'black', 'green']; // 0 is green
const number = Math.floor(Math.random() * numbers.length);
const color = (numbers[number] % 2 === 0) ? 'black' : 'red'; // Simplified rule for black/red colors
return {
number: numbers[number],
color: color
};
}
function checkColorBet(result, color) {
return result.color === color ? 'You win!' : 'You lose!';
}
function checkOddEvenBet(result, type) {
const isOdd = result.number % 2 !== 0;
return (type === 'odd' && isOdd) || (type === 'even' && !isOdd) ? 'You win!' : 'You lose!';
}
function checkNumberBet(result, betNumber) {
return result.number === parseInt(betNumber) ? 'You win!' : 'You lose!';
}
// Collapsible functionality
const collapsibles = document.querySelectorAll(".collapsible");
collapsibles.forEach(button => {
button.addEventListener("click", () => {
const content = button.nextElementSibling;
content.style.display = content.style.display === "block" ? "none" : "block";
});
});
// Initial setup
updateBalance();
</script>
</body>
</html>