function setup() { newGame(); } function newGame() { let params = gatherMenuValues(); this.game = new Game(params.TUBESNUMBERS, params.TUBESLEVELS); this.drawer = new Drawer(params.PADDING); this.drawer.setTubesParams(params.TUBESNUMBERS, params.TUBESLEVELS, params.TUBESIZE); this.needUpdate = true; } function mousePressed(e) { let tubeId = this.drawer.getTubeIdAt(mouseX, mouseY); if (tubeId != -1) { this.game.selectTube(tubeId); } this.needUpdate = true; } function gatherMenuValues() { let inputTubesNumbers = parseInt(document.getElementById("tbNumber").value); let inputTubesLevels = parseInt(document.getElementById("tbLevel").value); let inputTubeSize = parseInt(document.getElementById("tbSize").value); let inputPadding = parseInt(document.getElementById("padding").value); return { TUBESNUMBERS: inputTubesNumbers, TUBESLEVELS: inputTubesLevels, TUBESIZE: inputTubeSize, PADDING: inputPadding }; } function draw() { if (!this.needUpdate) return; this.drawer.draw(this.game); this.needUpdate = false; }