Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Chromebook Keyboard Drag and Drop Game</title>
- <style>
- body {
- font-family: Arial, sans-serif;
- text-align: center;
- background-color: #f0f8ff;
- }
- .game-container {
- margin: 20px auto;
- width: 100%;
- }
- .keyboard-row {
- display: flex;
- justify-content: center;
- margin-bottom: 2px;
- width: 100%;
- }
- .key {
- width: 50px; /* Default width */
- height: 50px; /* Default height */
- margin: 5px;
- cursor: pointer;
- border-radius: 5px;
- background-color: white;
- border: 3px solid #000;
- display: flex;
- justify-content: center;
- align-items: center;
- }
- .key img {
- max-width: 100%;
- max-height: 100%;
- }
- .key.correct {
- background-color: #90ee90;
- border-color: #90ee90;
- }
- .keybank {
- display: flex;
- flex-wrap: wrap;
- justify-content: center;
- }
- .hidden {
- display: none;
- }
- .congratulations {
- margin-top: 20px;
- }
- .dragging {
- opacity: 0.5;
- }
- #keyboard-container {
- background-color: grey;
- border: 3px solid #000;
- padding: 5px;
- border-radius: 10px; /* Rounded corners */
- }
- </style>
- </head>
- <body>
- <div class="game-container">
- <h1>Chromebook Keyboard Drag and Drop Game</h1>
- <div id="keyboard-container">
- <div class="keyboard-row" id="row1"></div>
- <div class="keyboard-row" id="row2"></div>
- <div class="keyboard-row" id="row3"></div>
- <div class="keyboard-row" id="row4"></div>
- <div class="keyboard-row" id="row5"></div>
- <div class="keyboard-row" id="row6"></div>
- </div>
- <div id="keybank" class="keybank">
- <!-- Keys to drag will be generated here -->
- </div>
- </div>
- <div id="congratulations" class="congratulations hidden">
- <h2>Congratulations! You've completed the keyboard!</h2>
- <button onclick="restartGame()">Play Again</button>
- </div>
- <script>
- const keys = [
- { symbol: 'Esc', image: 'https://drive.google.com/thumbnail?id=1b7mScbRhzw5S5qznbdyrD3f_m67Zhi6N&sz=w100', position: '1', width: 40, height: 50, row: 1 },
- { symbol: 'larrow', image: 'images/larrow-key.png', position: '2', width: 40, height: 50, row: 1 },
- { symbol: 'rarrow', image: 'images/rarrow-key.png', position: '3', width: 40, height: 50, row: 1 },
- { symbol: 'F3', image: 'images/f3-key.png', position: '4', width: 40, height: 50, row: 1 },
- { symbol: 'F4', image: 'images/f4-key.png', position: '5', width: 40, height: 50, row: 1 },
- { symbol: 'F5', image: 'images/f5-key.png', position: '6', width: 40, height: 50, row: 1 },
- { symbol: 'F6', image: 'images/f6-key.png', position: '7', width: 40, height: 50, row: 1 },
- { symbol: 'F7', image: 'images/f7-key.png', position: '8', width: 40, height: 50, row: 1 },
- { symbol: 'F8', image: 'images/f8-key.png', position: '9', width: 40, height: 50, row: 1 },
- { symbol: 'F9', image: 'images/f9-key.png', position: '10', width: 40, height: 50, row: 1 },
- { symbol: 'F10', image: 'images/f10-key.png', position: '11', width: 40, height: 50, row: 1 },
- { symbol: 'F11', image: 'images/f11-key.png', position: '12', width: 40, height: 50, row: 1 },
- { symbol: 'F12', image: 'images/f12-key.png', position: '13', width: 40, height: 50, row: 1 },
- { symbol: '`', image: 'images/tilde-key.png', position: '17', width: 40, height: 50, row: 2 },
- { symbol: '1', image: 'images/1-key.png', position: '18', width: 40, height: 50, row: 2 },
- { symbol: '2', image: 'images/2-key.png', position: '19', width: 40, height: 50, row: 2 },
- { symbol: '3', image: 'images/3-key.png', position: '20', width: 40, height: 50, row: 2 },
- { symbol: '4', image: 'images/4-key.png', position: '21', width: 40, height: 50, row: 2 },
- { symbol: '5', image: 'images/5-key.png', position: '22', width: 40, height: 50, row: 2 },
- { symbol: '6', image: 'images/6-key.png', position: '23', width: 40, height: 50, row: 2 },
- { symbol: '7', image: 'images/7-key.png', position: '24', width: 40, height: 50, row: 2 },
- { symbol: '8', image: 'images/8-key.png', position: '25', width: 40, height: 50, row: 2 },
- { symbol: '9', image: 'images/9-key.png', position: '26', width: 40, height: 50, row: 2 },
- { symbol: '0', image: 'images/0-key.png', position: '27', width: 40, height: 50, row: 2 },
- { symbol: '-', image: 'images/minus-key.png', position: '28', width: 40, height: 50, row: 2 },
- { symbol: '=', image: 'images/equal-key.png', position: '29', width: 40, height: 50, row: 2 },
- { symbol: 'Backspace', image: 'images/backspace-key.png', position: '30', width: 80, height: 50, row: 2 },
- { symbol: 'Tab', image: 'images/tab-key.png', position: '31', width: 60, height: 50, row: 3 },
- { symbol: 'Q', image: 'images/q-key.png', position: '32', width: 40, height: 50, row: 3 },
- { symbol: 'W', image: 'images/w-key.png', position: '33', width: 40, height: 50, row: 3 },
- { symbol: 'E', image: 'images/e-key.png', position: '34', width: 40, height: 50, row: 3 },
- { symbol: 'R', image: 'images/r-key.png', position: '35', width: 40, height: 50, row: 3 },
- { symbol: 'T', image: 'images/t-key.png', position: '36', width: 40, height: 50, row: 3 },
- { symbol: 'Y', image: 'images/y-key.png', position: '37', width: 40, height: 50, row: 3 },
- { symbol: 'U', image: 'images/u-key.png', position: '38', width: 40, height: 50, row: 3 },
- { symbol: 'I', image: 'images/i-key.png', position: '39', width: 40, height: 50, row: 3 },
- { symbol: 'O', image: 'images/o-key.png', position: '40', width: 40, height: 50, row: 3 },
- { symbol: 'P', image: 'images/p-key.png', position: '41', width: 40, height: 50, row: 3 },
- { symbol: '[', image: 'images/open-bracket-key.png', position: '42', width: 40, height: 50, row: 3 },
- { symbol: ']', image: 'images/close-bracket-key.png', position: '43', width: 40, height: 50, row: 3 },
- { symbol: '\\', image: 'images/backslash-key.png', position: '44', width: 60, height: 50, row: 3 },
- { symbol: 'Caps Lock', image: 'images/caps-lock-key.png', position: '45', width: 70, height: 50, row: 4 },
- { symbol: 'A', image: 'images/a-key.png', position: '46', width: 40, height: 50, row: 4 },
- { symbol: 'S', image: 'images/s-key.png', position: '47', width: 40, height: 50, row: 4 },
- { symbol: 'D', image: 'images/d-key.png', position: '48', width: 40, height: 50, row: 4 },
- { symbol: 'F', image: 'images/f-key.png', position: '49', width: 40, height: 50, row: 4 },
- { symbol: 'G', image: 'images/g-key.png', position: '50', width: 40, height: 50, row: 4 },
- { symbol: 'H', image: 'images/h-key.png', position: '51', width: 40, height: 50, row: 4 },
- { symbol: 'J', image: 'images/j-key.png', position: '52', width: 40, height: 50, row: 4 },
- { symbol: 'K', image: 'images/k-key.png', position: '53', width: 40, height: 50, row: 4 },
- { symbol: 'L', image: 'images/l-key.png', position: '54', width: 40, height: 50, row: 4 },
- { symbol: ';', image: 'images/semicolon-key.png', position: '55', width: 40, height: 50, row: 4 },
- { symbol: '\'', image: 'images/quote-key.png', position: '56', width: 40, height: 50, row: 4 },
- { symbol: 'Enter', image: 'images/enter-key.png', position: '57', width: 90, height: 50, row: 4 },
- { symbol: 'Shift', image: 'images/left-shift-key.png', position: '58', width: 90, height: 50, row: 5 },
- { symbol: 'Z', image: 'images/z-key.png', position: '59', width: 40, height: 50, row: 5 },
- { symbol: 'X', image: 'images/x-key.png', position: '60', width: 40, height: 50, row: 5 },
- { symbol: 'C', image: 'images/c-key.png', position: '61', width: 40, height: 50, row: 5 },
- { symbol: 'V', image: 'images/v-key.png', position: '62', width: 40, height: 50, row: 5 },
- { symbol: 'B', image: 'images/b-key.png', position: '63', width: 40, height: 50, row: 5 },
- { symbol: 'N', image: 'images/n-key.png', position: '64', width: 40, height: 50, row: 5 },
- { symbol: 'M', image: 'images/m-key.png', position: '65', width: 40, height: 50, row: 5 },
- { symbol: ',', image: 'images/comma-key.png', position: '66', width: 40, height: 50, row: 5 },
- { symbol: '.', image: 'images/period-key.png', position: '67', width: 40, height: 50, row: 5 },
- { symbol: '/', image: 'images/slash-key.png', position: '68', width: 40, height: 50, row: 5 },
- { symbol: 'Shift', image: 'images/right-shift-key.png', position: '69', width: 120, height: 50, row: 5 },
- { symbol: 'Ctrl', image: 'images/left-ctrl-key.png', position: '70', width: 50, height: 50, row: 6 },
- { symbol: 'Fn', image: 'images/fn-key.png', position: '71', width: 50, height: 50, row: 6 },
- { symbol: 'Alt', image: 'images/left-alt-key.png', position: '72', width: 50, height: 50, row: 6 },
- { symbol: 'Space', image: 'images/space-key.png', position: '73', width: 300, height: 50, row: 6 },
- { symbol: 'Alt', image: 'images/right-alt-key.png', position: '74', width: 50, height: 50, row: 6 },
- { symbol: 'Ctrl', image: 'images/right-ctrl-key.png', position: '75', width: 50, height: 50, row: 6 }
- ];
- document.addEventListener('DOMContentLoaded', () => {
- createKeyboard();
- createKeyBank();
- });
- function createKeyboard() {
- keys.forEach(key => {
- const keyElement = document.createElement('div');
- keyElement.classList.add('key');
- keyElement.style.width = `${key.width}px`;
- keyElement.style.height = `${key.height}px`;
- keyElement.dataset.image = key.image;
- keyElement.dataset.position = key.position;
- keyElement.dataset.row = key.row;
- const imgElement = document.createElement('img');
- imgElement.src = key.image;
- imgElement.alt = key.symbol;
- keyElement.appendChild(imgElement);
- keyElement.addEventListener('dragover', handleDragOver);
- keyElement.addEventListener('drop', handleDrop);
- document.getElementById(`row${key.row}`).appendChild(keyElement);
- });
- }
- function createKeyBank() {
- const shuffledKeys = shuffleArray(keys.slice());
- shuffledKeys.forEach(key => {
- const keyElement = document.createElement('div');
- keyElement.classList.add('key');
- keyElement.dataset.position = key.position;
- keyElement.style.width = `${key.width}px`;
- keyElement.style.height = `${key.height}px`;
- keyElement.draggable = true;
- keyElement.dataset.symbol = key.symbol;
- const imgElement = document.createElement('img');
- imgElement.src = key.image;
- imgElement.alt = key.symbol;
- keyElement.appendChild(imgElement);
- keyElement.addEventListener('dragstart', handleDragStart);
- keyElement.addEventListener('dragend', handleDragEnd);
- document.getElementById('keybank').appendChild(keyElement);
- });
- }
- function shuffleArray(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]];
- }
- return array;
- }
- function handleDragStart(e) {
- e.dataTransfer.setData('text/plain', e.target.dataset.position);
- e.target.classList.add('dragging');
- }
- function handleDragEnd(e) {
- e.target.classList.remove('dragging');
- }
- function handleDragOver(e) {
- e.preventDefault();
- e.currentTarget.classList.add('drag-over');
- }
- function handleDrop(e) {
- e.preventDefault();
- e.currentTarget.classList.remove('drag-over');
- const position = e.dataTransfer.getData('text/plain');
- const draggedKey = document.querySelector(`#keybank .key[data-position='${position}']`);
- if (draggedKey && e.currentTarget.dataset.position === position) {
- e.currentTarget.innerHTML = draggedKey.innerHTML;
- e.currentTarget.classList.add('correct');
- draggedKey.classList.add('hidden');
- checkForCompletion();
- }
- }
- function checkForCompletion() {
- const keys = document.querySelectorAll('#keyboard-container .key');
- const completed = Array.from(keys).every(key => key.classList.contains('correct'));
- if (completed) {
- document.getElementById('congratulations').classList.remove('hidden');
- }
- }
- function restartGame() {
- document.getElementById('congratulations').classList.add('hidden');
- document.getElementById('keyboard-container').innerHTML = '';
- document.getElementById('keybank').innerHTML = '';
- createKeyboard();
- createKeyBank();
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement