diff --git a/main.js b/main.js index 6d328bc74559df9a6b65a6c80e177860c5250c68..f44b820851077ea3da8c51a13dcb45d1d2b4108d 100644 --- a/main.js +++ b/main.js @@ -1,29 +1,24 @@ import { solveSudoku } from "./public/solver.js"; import http from 'node:http'; import { generateSudoku } from "./public/generateSudoku.js"; -import express, { raw } from "express"; +import express, { Router, raw } from "express"; import path from 'path'; // Add this line to import the path module -// const sudokuBoard = generateSudoku(50); -// const rawString = sudokuBoard.map(row => row.map(num => `<td>${num}</td>`).join('')).map(row => `<tr>${row}</tr>`).join(''); -// console.log(rawString) - - -// const sol = solveSudoku(sudokuBoard); -// Format the solved Sudoku board vertically -// const solString = sol.map(row => row.map(num => `<td>${num}</td>`).join('')).map(row => `<tr>${row}</tr>`).join(''); - const router = express.Router(); const port = 8080; let app = express(); + app.use(express.static('public')); app.get('/', (req, res) => { res.statusCode(200) res.sendFile(path.join(__dirname, 'public', 'index.html')); }); +app.get('/Sudoku', (req, res) => { + res.status(200).sendFile(path.join(__dirname, 'public', 'index.html')); +}); app.listen(port, () => { console.log(`Server running at http://localhost:${port}`); diff --git a/public/index.html b/public/index.html index 812bf578f6ce880072576aa1ea92c3ab8861d73a..5b8095d76fc509cf3ec2d6a08e3795ae0884c591 100644 --- a/public/index.html +++ b/public/index.html @@ -22,7 +22,7 @@ <table id="noSolutionBoard"></table> - <button id="Auswerten">Auswerten</button> + <button id="Auswerten">Evaluate</button> <br> <button id="toggleButton" onclick="solveTable('noSolutionBoard')">Generate Solution</button> @@ -41,35 +41,39 @@ let sudokuBoard; function collectUserInputs() { - let userInputArray = sudokuBoard.map((row, rowIndex) => { - return row.map((num, colIndex) => { - let inputField = document.getElementById(`cell_${rowIndex}_${colIndex}`); - return inputField ? (inputField.value !== '' ? parseInt(inputField.value, 10) : num) : num; - }); + let userInputArray = sudokuBoard.map((row, rowIndex) => { + return row.map((num, colIndex) => { + let inputField = document.getElementById(`cell_${rowIndex}_${colIndex}`); + return inputField ? (inputField.value !== '' ? parseInt(inputField.value, 10) : num) : num; }); + }); - console.log("User Input Array:", userInputArray); - const table = document.querySelector('table'); - const element = document.querySelector('input'); - if(isValid(userInputArray)){ - table.style.backgroundColor = 'green'; - element.style.backgroundColor = "green"; - } else { - table.style.backgroundColor = "red"; - element.style.backgroundColor = "red"; - } - setTimeout(() => { - table.style.backgroundColor = "white"; // Set to original or your desired color - try { - const element = document.getElementsByName('input'); - element.style.backgroundColor = "white"; - } catch (TypeError) { - console.log("caught not able to read input Error") - } - }, 600); - } - - + updateValidation(userInputArray) +} + + +function updateValidation(userInputArray) { + const table = document.getElementById('noSolutionBoard'); + + if (isValid(userInputArray)) { + setColors('green'); + } else { + setColors('red'); + } + + setTimeout(() => { + resetColors(); + }, 600); + + function setColors(color) { + console.log("setColor called"); + table.style.backgroundColor = color; + } + + function resetColors() { + table.style.backgroundColor = 'white'; + } +} function updateTable(tableId) { let table = document.getElementById(tableId);