JSFiddle - React, Tailwind, and code Playground

by velo_ninja

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Hexagon Grid Game</title>
    <style>
        body {
            display: flex;
            justify-content: space-between;
            padding: 20px;
        }
        #hexContainer {
            width: 500px;
            height: 500px;
            border: 2px solid #333;
            position: relative;
        }
        #infoPanel {
            width: 200px;
            border: 2px solid #333;
            padding: 10px;
            margin-left: 20px;
            height: fit-content;
        }
        .button {
            display: block;
            margin-top: 10px;
            padding: 5px;
            background-color: #4CAF50;
            color: white;
            cursor: pointer;
            text-align: center;
        }
        .cancelButton {
            background-color: #f44336;
        }
    </style>
</head>
<body>

<div id="hexContainer"></div>
<div id="infoPanel">
    <h3>Cell Info</h3>
    <div id="lifeInfo">Hover over a red cell to see life points.</div>
    <div id="actionOptions"></div>
</div>

<script>
    const hexSize = 20;
    const hexWidth = 2 * hexSize;
    const hexHeight = Math.sqrt(3) * hexSize;
    const hexHorizontalSpacing = hexWidth * 0.95;
    const hexVerticalSpacing = hexHeight;
    const rows = 14;
    const cols = 13;

    const gridData = [];

    let selectedBlueCell = null;
    let selectedRedCell = null;
    let isDragging = false;

    // Initializing Grid with Red and Blue Cells
    function initializeGrid() {
        for (let row = 0; row < rows; row++) {
            gridData[row] = [];
            for (let col = 0; col < cols; col++) {
                gridData[row][col] = { status: 'empty', lifePoints: 0 };
            }
        }

        // Place Red and Blue cells
        placeCellsRandomly('red', 10);
        placeCellsRandomly('blue', 10);
    }

    function...