Create a game headlined at the top of the page "Forsaken Generator Simulator". the game is a 6x6 grid where the player has to connect two dots with the numbers 1 to 8 on using the mouse to create a line that follows where the mouse would be. there are two dots for each number and the player has to connect each dot with a number to the other numbered dot placed randomly on the 6x6 grid space. lines cant go outside of the grid or grid space or go inside other lines or starting dots. only when all the dots are connected to the other dot of the same number can the player go to the next level. and then the cycle repeats forever. dont forget to use HTML.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Below is the complete HTML code for the game "Forsaken Generator Simulator." This implementation uses HTML, CSS, and JavaScript to create a 6x6 grid on a canvas. The game logic is as follows:
Game Rules:
There are two dots for each number from 1 to 8, placed randomly on the 6x6 grid.
The player must connect each pair of dots with the same number by drawing a line using the mouse.
Lines must follow the grid (only moving horizontally or vertically between adjacent cells) and cannot:
Go outside the grid.
Cross or overlap with other lines.
Pass through starting dots or other occupied cells.
To draw a line, click and drag from one dot to its matching dot.
Only when all 8 pairs are successfully connected will the level complete, and a new level will generate with randomly placed dots.
The game repeats indefinitely.
The game is built using a <canvas> element for rendering the grid, dots, and lines. Mouse events handle the drawing of paths.
Here's the full HTML file:
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Forsaken Generator Simulator</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 20px;
}
canvas {
border: 2px solid black;
background-color: #f0f0f0;
margin: 20px auto;
display: block;
}
#message {
font-size: 18px;
margin-bottom: 10px;
}
</style>
</head>
<body>
<h1>Forsaken Generator Simulator</h1>
<div id="message">Level 1 - Connect all pairs!</div>
<canvas id="gameCanvas" width="600" height="600"></canvas>
<script>
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
const cellSize = 100; // Each cell is 100x100 pixels for a 6x6 grid
let grid = Array(6).fill().map(() => Array(6).fill(null)); // 6x6 grid: null for empty, number for dot, 'path' for occupied
let dots = []; // Array of {row, col, number}
let paths = []; // Array of paths, each path is an array of {row, col}
let currentPath = null; // Current path being drawn
let startCell = null; // Starting cell of the current path
let level = 1; // Track the level
function generateLevel() {
dots = [];
paths = [];
grid = Array(6).fill().map(() => Array(6).fill(null)); // Reset grid
const numbers = [1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8]; // Two of each number
numbers.sort(() => Math.random() - 0.5); // Shuffle numbers
const positions = []; // Ensure unique positions
while (positions.length < 16) {
const row = Math.floor(Math.random() * 6);
const col = Math.floor(Math.random() * 6);
if (!positions.some(p => p.row === row && p.col === col)) {
positions.push({row, col});
dots.push({row, col, number: numbers[positions.length - 1]});
grid[row][col] = dots[dots.length - 1].number; // Mark cell with dot number
}
}
document.getElementById('message').textContent = `Level ${level} - Connect all pairs!`;
drawGrid();
}
function drawGrid() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Draw grid lines
ctx.strokeStyle = 'black';
for (let i = 0; i <= 6; i++) {
ctx.beginPath();
ctx.moveTo(0, i * cellSize);
ctx.lineTo(canvas.width, i * cellSize);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(i * cellSize, 0);
ctx.lineTo(i * cellSize, canvas.height);
ctx.stroke();
}
// Draw dots
dots.forEach(dot => {
if (!paths.some(path => path.some(cell => cell.row === dot.row && cell.col === dot.col))) { // Only draw if not connected
ctx.fillStyle = 'red';
ctx.beginPath();
ctx.arc(dot.col * cellSize + cellSize / 2, dot.row * cellSize + cellSize / 2, 20, 0, 2 * Math.PI);
ctx.fill();
ctx.fillStyle = 'white'; // Number color
ctx.font = '30px Arial';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(dot.number, dot.col * cellSize + cellSize / 2, dot.row * cellSize + cellSize / 2);
}
});
// Draw existing paths
paths.forEach(path => {
ctx.strokeStyle = 'blue';
ctx.lineWidth = 10;
ctx.beginPath();
path.forEach((cell, index) => {
const x = cell.col * cellSize + cellSize / 2;
const y = cell.row * cellSize + cellSize / 2;
if (index === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
});
ctx.stroke();
});
}
canvas.addEventListener('mousedown', (e) => {
const rect = canvas.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
const col = Math.floor(x / cellSize);
const row = Math.floor(y / cellSize);
const dot = dots.find(d => d.row === row && d.col === col && !paths.some(p => p.some(cell => cell.row === row && cell.col === col)));
if (dot && grid[row][col] !== 'path') { // Start only on an unconnected dot
startCell = {row, col};
currentPath = [{row, col}];
grid[row][col] = 'path'; // Mark as occupied (though it's a dot, we're starting a path)
}
});
canvas.addEventListener('mousemove', (e) => {
if (currentPath) {
const rect = canvas.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
const col = Math.floor(x / cellSize);
const row = Math.floor(y / cellSize);
const lastCell = currentPath[currentPath.length - 1];
if (isAdjacent(lastCell, {row, col}) && grid[row][col] === null) { // Only add to adjacent empty cell
currentPath.push({row, col});
grid[row][col] = 'path'; // Mark as occupied
drawGrid(); // Redraw to show the path
}
}
});
canvas.addEventListener('mouseup', (e) => {
if (currentPath) {
const rect = canvas.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
const col = Math.floor(x / cellSize);
const row = Math.floor(y / cellSize);
const startDot = dots.find(d => d.row === startCell.row && d.col === startCell.col);
const targetDot = dots.find(d => d.row === row && d.col === col && d.number === startDot.number && !(d.row === startDot.row && d.col === startDot.col));
if (targetDot && row === targetDot.row && col === targetDot.col) {
paths.push(currentPath); // Add successful path
currentPath = null;
startCell = null;
drawGrid();
checkWin();
} else {
// Undo the path
currentPath.forEach(cell => {
if (grid[cell.row][cell.col] === 'path') {
grid[cell.row][cell.col] = null; // Clear occupied cells
}
});
currentPath = null;
startCell = null;
drawGrid();
}
}
});
function isAdjacent(cell1, cell2) {
const rowDiff = Math.abs(cell1.row - cell2.row);
const colDiff = Math.abs(cell1.col - cell2.col);
return (rowDiff === 1 && colDiff === 0) || (rowDiff === 0 && colDiff === 1); // Only horizontal or vertical
}
function checkWin() {
if (paths.length === 8) { // All 8 pairs connected
level++;
alert('Level complete! Generating next level...');
generateLevel(); // Generate new level
}
}
// Start the game
generateLevel();
</script>
</body>
</html>
How to Play:
Open this HTML file in a web browser.
Click and drag from a dot to its matching dot (e.g., from one "1" to the other "1").
The line will only follow adjacent grid cells (up, down, left, right) and will not allow overlaps or invalid moves.
Once all pairs are connected, the level will reset with new random dot placements.
The game continues indefinitely.
This implementation ensures that lines stay within the grid, do not overlap, and only connect valid pairs. If you encounter any issues or want enhancements, let me know!