-
Notifications
You must be signed in to change notification settings - Fork 0
/
diamant.html
91 lines (83 loc) · 2.37 KB
/
diamant.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
<!DOCTYPE html>
<html>
<head>
<title>Incan Gold (Diamant) Card Viewer</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
font-family: Arial, sans-serif;
max-width: 400px;
margin: 0 auto;
padding: 20px;
text-align: center;
}
.card {
border: 1px solid black;
border-radius: 5px;
width: 200px;
height: 300px;
margin: 20px auto;
display: flex;
justify-content: center;
align-items: center;
font-size: 24px;
cursor: pointer;
}
.danger {
background-color: #f8d7da;
color: #721c24;
}
.treasure {
background-color: #d4edda;
color: #155724;
}
.previous-cards {
margin-top: 20px;
text-align: left;
}
</style>
</head>
<body>
<h1>Diamant</h1>
<h2>Current Card</h2>
<div id="card" class="card" onclick="drawCard()"></div>
<div class="previous-cards">
<h3>Previous Cards:</h3>
<ul id="previous-cards-list"></ul>
</div>
<script>
const cardDiv = document.getElementById('card');
const previousCardslist = document.getElementById('previous-cards-list');
const deck = [
...Array(15).fill().map((_, i) => ({ type: 'treasure', value: [1, 2, 3, 4, 5, 5, 7, 7, 9, 11, 11, 13, 14, 15, 17][i] })),
...Array(3).fill({ type: 'danger', value: 'Serpent' }),
...Array(3).fill({ type: 'danger', value: 'Scorpion' }),
...Array(3).fill({ type: 'danger', value: 'Rockfall' }),
...Array(3).fill({ type: 'danger', value: 'Gas cloud' }),
...Array(3).fill({ type: 'danger', value: 'Explosion' })
];
const shuffle = (array) => {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
};
const drawCard = () => {
if (deck.length === 0) {
cardDiv.textContent = 'No more cards!';
cardDiv.classList.remove('treasure', 'danger');
return;
}
const card = deck.pop();
cardDiv.textContent = card.value;
cardDiv.classList.remove('treasure', 'danger');
cardDiv.classList.add(card.type);
const listItem = document.createElement('li');
listItem.textContent = card.value;
previousCardslist.appendChild(listItem);
};
shuffle(deck);
drawCard();
</script>
</body>
</html>