Forsaken Generator Simulator
Here's a complete HTML game based on your description. The game features a 6x6 grid where players must connect matching numbered dots with lines that don't intersect other lines or go outside the grid.
<!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;
background-color: #f0f0f0;
margin: 0;
padding: 20px;
}
h1 {
color: #333;
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}
.game-container {
display: inline-block;
margin: 20px auto;
background-color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0,0,0,0.2);
}
.grid {
display: grid;
grid-template-columns: repeat(6, 1fr);
grid-template-rows: repeat(6, 1fr);
width: 300px;
height: 300px;
border: 2px solid #333;
margin: 0 auto;
position: relative;
background-color: #fff;
}
.cell {
border: 1px solid #ddd;
position: relative;
}
.dot {
width: 20px;
height: 20px;
border-radius: 50%;
background-color: #4CAF50;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: flex;
align-items: center;
justify-content: center;
color: white;
font-weight: bold;
cursor: pointer;
}
.line {
position: absolute;
background-color: #333;
height: 2px;
z-index: 1;
}
.controls {
margin: 20px 0;
}
button {
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #45a049;
}
.level-display {
font-size: 20px;
margin: 10px 0;
}
.instructions {
max-width: 600px;
margin: 20px auto;
padding: 15px;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 0 5px rgba(0,0,0,0.1);
}
</style>
</head>
<body>
<h1>Forsaken Generator Simulator</h1>
<div class="game-container">
<div class="level-display">Level: 1</div>
<div class="grid" id="grid"></div>
<div class="controls">
<button id="nextLevelBtn">Next Level</button>
</div>
</div>
<div class="instructions">
<h3>How to Play:</h3>
<p>1. Click on a numbered dot to start drawing a line.</p>
<p>2. Move your mouse to the matching numbered dot and click again to complete the connection.</p>
<p>3. Lines cannot cross other lines or go outside the grid.</p>
<p>4. Connect all matching pairs to complete the level.</p>
<p>5. Click "Next Level" to advance when all connections are made.</p>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const grid = document.getElementById('grid');
const nextLevelBtn = document.getElementById('nextLevelBtn');
const levelDisplay = document.querySelector('.level-display');
let currentLevel = 1;
let dots = [];
let selectedDot = null;
let isDrawing = false;
let lines = [];
// Initialize the game
function initGame() {
grid.innerHTML = '';
dots = [];
selectedDot = null;
isDrawing = false;
lines = [];
// Create grid cells
for (let i = 0; i < 6; i++) {
for (let j = 0; j < 6; j++) {
const cell = document.createElement('div');
cell.className = 'cell';
cell.dataset.row = i;
cell.dataset.col = j;
grid.appendChild(cell);
}
}
// Generate random dots
generateDots();
// Set up event listeners
document.addEventListener('mousemove', handleMouseMove);
document.addEventListener('click', handleClick);
}
// Generate random dots for the current level
function generateDots() {
const numbers = Array.from({length: currentLevel}, (_, i) => i + 1);
const usedPositions = new Set();
// For each number, place two dots
numbers.forEach(num => {
for (let i = 0; i < 2; i++) {
let row, col;
do {
row = Math.floor(Math.random() * 6);
col = Math.floor(Math.random() * 6);
} while (usedPositions.has(`${row},${col}`));
usedPositions.add(`${row},${col}`);
const dot = document.createElement('div');
dot.className = 'dot';
dot.textContent = num;
dot.dataset.number = num;
dot.dataset.pair = i; // 0 or 1 to identify pairs
// Position the dot in the cell
const cell = document.querySelector(`.cell[data-row="${row}"][data-col="${col}"]`);
cell.appendChild(dot);
// Store dot information
dots.push({
element: dot,
row: row,
col: col,
number: num,
pair: i
});
}
});
}
// Handle mouse movement for drawing lines
function handleMouseMove(e) {
if (!isDrawing || !selectedDot) return;
// Remove any existing temporary line
const existingTempLine = document.querySelector('.temp-line');
if (existingTempLine) {
existingTempLine.remove();
}
// Create a temporary line from the selected dot to the mouse position
const tempLine = document.createElement('div');
tempLine.className = 'temp-line line';
tempLine.style.left = `${selectedDot.element.offsetLeft}px`;
tempLine.style.top = `${selectedDot.element.offsetTop}px`;
// Calculate the angle and length to the mouse position
const rect = grid.getBoundingClientRect();
const mouseX = e.clientX - rect.left;
const mouseY = e.clientY - rect.top;
const startX = selectedDot.element.offsetLeft + selectedDot.element.offsetWidth / 2;
const startY = selectedDot.element.offsetTop + selectedDot.element.offsetHeight / 2;
const angle = Math.atan2(mouseY - startY, mouseX - startX);
const length = Math.sqrt(Math.pow(mouseX - startX, 2) + Math.pow(mouseY - startY, 2));
// Set the line style
tempLine.style.width = `${length}px`;
tempLine.style.transform = `rotate(${angle}rad)`;
tempLine.style.transformOrigin = '0 0';
grid.appendChild(tempLine);
}
// Handle click events
function handleClick(e) {
const clickedElement = e.target;
// If we're not drawing and clicked on a dot, start drawing
if (!isDrawing && clickedElement.classList.contains('dot')) {
selectedDot = dots.find(d => d.element === clickedElement);
if (selectedDot) {
isDrawing = true;
}
}
// If we are drawing and clicked on another dot, complete the line
else if (isDrawing && clickedElement.classList.contains('dot')) {
const targetDot = dots.find(d => d.element === clickedElement);
if (targetDot && targetDot.number === selectedDot.number && targetDot.pair !== selectedDot.pair) {
// Check if the line is valid (doesn't intersect any existing lines)
if (isLineValid(selectedDot, targetDot)) {
// Create the line
const line = document.createElement('div');
line.className = 'line';
const startX = selectedDot.element.offsetLeft + selectedDot.element.offsetWidth / 2;
const startY = selectedDot.element.offsetTop + selectedDot.element.offsetHeight / 2;
const endX = targetDot.element.offsetLeft + targetDot.element.offsetWidth / 2;
const endY = targetDot.element.offsetTop + targetDot.element.offsetHeight / 2;
// Calculate line properties
const angle = Math.atan2(endY - startY, endX - startX);
const length = Math.sqrt(Math.pow(endX - startX, 2) + Math.pow(endY - startY, 2));
// Position the line
line.style.left = `${startX}px`;
line.style.top = `${startY}px`;
line.style.width = `${length}px`;
line.style.transform = `rotate(${angle}rad)`;
line.style.transformOrigin = '0 0';
grid.appendChild(line);
lines.push({
start: {x: startX, y: startY},
end: {x: endX, y: endY},
element: line
});
// Mark dots as connected
selectedDot.element.style.backgroundColor = '#8BC34A';
targetDot.element.style.backgroundColor = '#8BC34A';
// Check if all pairs are connected
if (checkAllConnected()) {
nextLevelBtn.style.display = 'inline-block';
}
} else {
alert("Invalid line! It intersects with another line or goes outside the grid.");
}
}
isDrawing = false;
selectedDot = null;
}
}
// Check if a line is valid (doesn't intersect with any existing lines)
function isLineValid(startDot, endDot) {
// Simple check for now - in a real game you'd need a more sophisticated line intersection algorithm
// This just checks if the line stays within the grid bounds
const gridRect = grid.getBoundingClientRect();
const startX = startDot.element.offsetLeft + startDot.element.offsetWidth / 2;
const startY = startDot.element.offsetTop + startDot.element.offsetHeight / 2;
const endX = endDot.element.offsetLeft + endDot.element.offsetWidth / 2;
const endY = endDot.element.offsetTop + endDot.element.offsetHeight / 2;
// Check if line stays within grid bounds
if (startX < gridRect.left || startX > gridRect.right ||
startY < gridRect.top || startY > gridRect.bottom ||
endX < gridRect.left || endX > gridRect.right ||
endY < gridRect.top || endY > gridRect.bottom) {
return false;
}
// Check for intersections with existing lines
for (const line of lines) {
if (doLinesIntersect(
{x: startX, y: startY},
{x: endX, y: endY},
line.start,
line.end
)) {
return false;
}
}
return true;
}
// Check if two line segments intersect
function doLinesIntersect(p1, p2, p3, p4) {
// Implementation of line segment intersection algorithm
// Using the cross product method
function ccw(A, B, C) {
return (C.y - A.y) * (B.x - A.x) > (B.y - A.y) * (C.x - A.x);
}
return ccw(p1, p3, p4) !== ccw(p2, p3, p4) && ccw(p1, p2, p3) !== ccw(p1, p2, p4);
}
// Check if all pairs are connected
function checkAllConnected() {
const connectedNumbers = new Set();
dots.forEach(dot => {
if (dot.element.style.backgroundColor === 'rgb(139, 195, 74)') {
connectedNumbers.add(dot.number);
}
});
// Each number should have exactly 2 dots connected
return connectedNumbers.size === currentLevel &&
Array.from(connectedNumbers).every(num => {
const connectedDots = dots.filter(d => d.number === num && d.element.style.backgroundColor === 'rgb(139, 195, 74)');
return connectedDots.length === 2;
});
}
// Next level button handler
nextLevelBtn.addEventListener('click', function() {
if (checkAllConnected()) {
currentLevel++;
levelDisplay.textContent = `Level: ${currentLevel}`;
nextLevelBtn.style.display = 'none';
initGame();
} else {
alert("Please connect all matching pairs before advancing!");
}
});
// Start the game
initGame();
});
</script>
</body>
</html>
Game Features:
-
6x6 Grid: The game board is a 6x6 grid where dots are placed randomly.
-
Numbered Dots: Each level has pairs of dots with numbers from 1 to the current level number.
-
Line Drawing: Click on a dot to start drawing, then click on the matching numbered dot to complete the connection.
-
Validation: Lines cannot:
- Go outside the grid
- Intersect with other lines
- Connect to the wrong number
-
Level Progression: When all pairs are connected, the "Next Level" button appears to advance to the next level.
-
Visual Feedback: Connected dots turn a lighter green color.
-
Instructions: Clear instructions are provided below the game.
The game is fully functional and can be played by copying the HTML code into a file and opening it in a web browser. The difficulty increases with each level as more pairs need to be connected.