-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameone.html
155 lines (140 loc) · 4.45 KB
/
gameone.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
<html>
<head>
<title>got me on the decline</title>
<style>
#game {
text-align: center;
font-family: Arial, sans-serif;
}
#drag-zone {
display: flex;
justify-content: center;
margin-bottom: 20px;
}
.draggable {
margin: 0 10px;
cursor: grab;
text-align: center;
transition: transform 0.2s ease;
background-color: rgb(186, 186, 186);
padding: 4px;
border-radius: 10px;
}
.draggable > img {
width: 75px;
}
.draggable.shake {
animation: shake 0.5s;
}
@keyframes shake {
0%,
100% {
transform: translateX(0);
}
25% {
transform: translateX(-5px);
}
50% {
transform: translateX(5px);
}
75% {
transform: translateX(-5px);
}
}
.drop-zone {
border: 2px dashed #ccc;
border-radius: 10px;
padding: 20px;
margin: 10px;
width: 200px;
min-height: 150px;
display: inline-block;
vertical-align: top;
}
.drop-zone h2 {
margin: 0 0 10px 0;
}
.drop-zone.hover {
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="game">
<h1>Image Matching Game</h1>
<p>Determine which images are safe to train on.</p>
<div id="drag-zone">
<div class="draggable" draggable="true" data-category="copyrighted">
<img src="images/image1.webp" alt="Image 1" />
<p>Image 1 - Published on a personal blog.</p>
</div>
<div class="draggable" draggable="true" data-category="non-copyrighted">
<img src="images/image2.webp" alt="Image 2" />
<p>Image 2 - Released into the public domain.</p>
</div>
<div class="draggable" draggable="true" data-category="copyrighted">
<img src="images/image3.webp" alt="Image 3" />
<p>Image 3 - Released on a photographer's blog.</p>
</div>
<div class="draggable" draggable="true" data-category="non-copyrighted">
<img src="images/image4.webp" alt="Image 4" />
<p>Image 4 - Published under Creative Commons w/o BY.</p>
</div>
</div>
<div id="drop-zones">
<div class="drop-zone" data-category="copyrighted">
<h2>Copyrighted</h2>
</div>
<div class="drop-zone" data-category="non-copyrighted">
<h2>Non-Copyrighted</h2>
</div>
</div>
</div>
<script>
(function () {
const draggables = document.querySelectorAll(".draggable");
const dropZones = document.querySelectorAll(".drop-zone");
draggables.forEach((draggable) => {
draggable.addEventListener("dragstart", (e) => {
e.dataTransfer.setData("text/plain", draggable.dataset.category);
e.target.classList.add("dragging");
});
draggable.addEventListener("dragend", (e) => {
e.target.classList.remove("dragging");
});
});
function checkCompletion() {
const remainingItems = document.querySelectorAll(".draggable").length;
if (remainingItems === 0) {
// Add completion logic here if needed
}
}
dropZones.forEach((zone) => {
zone.addEventListener("dragover", (e) => {
e.preventDefault();
zone.classList.add("hover");
});
zone.addEventListener("dragleave", () => {
zone.classList.remove("hover");
});
zone.addEventListener("drop", (e) => {
e.preventDefault();
zone.classList.remove("hover");
const category = e.dataTransfer.getData("text/plain");
const dropCategory = zone.dataset.category;
const draggingElement = document.querySelector(".dragging");
if (category === dropCategory) {
zone.appendChild(draggingElement);
checkCompletion();
} else {
draggingElement.classList.add("shake");
setTimeout(() => {
draggingElement.classList.remove("shake");
}, 500);
}
});
});
})();
</script>
</body>
</html>