-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameon.html
152 lines (139 loc) · 3.54 KB
/
gameon.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
<!DOCTYPE html>
<html>
<head>
<style>
.container {
width: 350px;
height: 150px;
margin: 0 auto;
display: flex;
align-items: center;
justify-content: center;
}
.card-game{
width:128px;
height:128px;
text-align: center;
vertical-align: middle;
line-height: 90px;
color: white;
margin-left: 5px;
margin-right: 5px;
}
.headline{
font-family:verdana;
text-align:center;
font-size:100px;
}
.flip-card {
background-color: transparent;
width: 300px;
height: 200px;
border: 1px solid #f1f1f1;
perspective: 1000px; /* Remove this if you don't want the 3D effect */
}
/* This container is needed to position the front and back side */
.flip-card-inner {
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 0.8s;
transform-style: preserve-3d;
}
/* Do an horizontal flip when you move the mouse over the flip box container */
.flip-card:hover .flip-card-inner {
transform: rotateY(180deg);
}
/* Position the front and back side */
.flip-card-front, .flip-card-back {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
}
/* Style the front side (fallback if image is missing) */
.flip-card-front {
background-color: #bbb;
color: black;
}
/* Style the back side */
.flip-card-back {
background-color: dodgerblue;
color: white;
transform: rotateY(180deg);
}
</style>
</head>
<body>
<h1 class="headline">THE</h1>
<h1 class="headline">CARDS GAME</h1>
</body>
<script language="javascript" type="text/javascript">
const cardsDir = "./cards/";
const cards = [cardsDir + 'bb8.png', cardsDir + 'cat.png', cardsDir + 'groot.png', cardsDir + 'mario.png' , cardsDir + 'psyduck.png' , cardsDir + 'superman.png', cardsDir + 'transformer.png'];
const geekCard = cardsDir + 'geek.png';
(function () {
var images = chooseCards(3);
var scramOrd = scrabmledOrder(images.length);
var image = document.createElement("img");
var cardId = "card";
var imgdiv = document.createElement('div');
var counter = 0;
for (q = 0; q < 2; q++) {
var con = document.createElement('div');
con.className = 'container';
for (i = 0; i < images.length; i++) {
counter++;
cardId = "card" + counter;
imgdiv = document.createElement('div');
imgdiv.className = 'card-game';
con.appendChild(imgdiv);
image = document.createElement("img");
image.setAttribute("alt", "");
image.setAttribute("src", geekCard);
image.setAttribute("id", cardId);
image.setAttribute("onclick", "changeImage(" + cardId + ".id, '" + images[scramOrd[counter-1]] + "')");
imgdiv.appendChild(image);
}
document.body.appendChild(con);
}
})();
function changeImage(cardNum, image) {
var img = document.getElementById(cardNum).src;
geekCardFileName = geekCard.split("/").pop();
if ( img.indexOf(geekCardFileName) != -1)
document.getElementById(cardNum).src = image;
else
document.getElementById(cardNum).src = geekCard;
}
function chooseCards(howManyCards)
{
var selected = []
var blacklist = []
while (selected.length < howManyCards){
rand = Math.floor(Math.random() * cards.length);
if (! blacklist.includes(rand)){
blacklist.push(rand);
selected.push(cards[rand])
}
}
return selected;
}
function scrabmledOrder(numOfCards){
var order = []
var blacklist = []
while (order.length < (numOfCards * 2))
{
rand = Math.floor(Math.random() * numOfCards);
if (! blacklist.includes(rand)){
if (order.includes(rand)){
blacklist.push(rand);
}
order.push(rand);
}
}
return order;
}
</script>
</html>