MultiplayerMinesweeper/www/scripts/interface/game/picker.js

53 lines
902 B
JavaScript

import {tileArray} from "/scripts/display/tileRenderer.js"
import {buttonBar} from "/scripts/interface/game/html.js"
var button = 0;
function clickSelector(e) {
document.querySelectorAll('.button').forEach(item => {
item.style ="";
})
event.target.style = "background: lightslategray;"
button = event.target.no
}
export function create() {
for(let i=0;i < 5;i++) {
let span = document.createElement('span')
span.className = "button"
let n;
switch (i) {
case (1):
n = 1
break;
case (2):
n = 2
break;
case (3):
n = 3
break;
case (4):
n = 4
break;
default:
n = 5
};
span.appendChild(tileArray[n]);
buttonBar.appendChild(span);
span.no = i;
span.addEventListener('click', e => {
clickSelector(e);
});
};
};
export function getButton() {
return button;
}
export function destroy() {
while (buttonBar.lastChild) {
buttonBar.removeChild(buttonBar.lastChild)
}
}