Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved #2090- Hoplite #2151

Merged
merged 4 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Hoplite/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hoplite Game</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Hoplite Game</h1>
<div id="gameBoard"></div>
</div>
<script src="script.js"></script>
</body>
</html>
27 changes: 27 additions & 0 deletions Hoplite/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "Hoplite Game",
"short_name": "Hoplite",
"description": "A simple web-based strategy game inspired by Hoplite.",
"version": "1.0.0",
"manifest_version": 2,
"start_url": "index.html",
"display": "standalone",
"background_color": "#f5f5f5",
"theme_color": "#ffffff",
"orientation": "portrait",
"icons": [
{
"src": "icons/icon-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "icons/icon-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"permissions": [
"storage"
]
}
61 changes: 61 additions & 0 deletions Hoplite/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
document.addEventListener('DOMContentLoaded', () => {
const gameBoard = document.getElementById('gameBoard');
const boardSize = 5;
const heroPosition = { x: 2, y: 2 };
const enemies = [{ x: 1, y: 1 }, { x: 3, y: 3 }];

function createBoard() {
for (let y = 0; y < boardSize; y++) {
for (let x = 0; x < boardSize; x++) {
const cell = document.createElement('div');
cell.classList.add('cell');
cell.dataset.x = x;
cell.dataset.y = y;
gameBoard.appendChild(cell);
}
}
renderBoard();
}

function renderBoard() {
document.querySelectorAll('.cell').forEach(cell => {
cell.classList.remove('hero', 'enemy');
});

const heroCell = document.querySelector(`.cell[data-x='${heroPosition.x}'][data-y='${heroPosition.y}']`);
heroCell.classList.add('hero');

enemies.forEach(enemy => {
const enemyCell = document.querySelector(`.cell[data-x='${enemy.x}'][data-y='${enemy.y}']`);
enemyCell.classList.add('enemy');
});
}

function moveHero(x, y) {
if (x >= 0 && x < boardSize && y >= 0 && y < boardSize) {
heroPosition.x = x;
heroPosition.y = y;
renderBoard();
}
}

document.addEventListener('keydown', (event) => {
const { x, y } = heroPosition;
switch (event.key) {
case 'ArrowUp':
moveHero(x, y - 1);
break;
case 'ArrowDown':
moveHero(x, y + 1);
break;
case 'ArrowLeft':
moveHero(x - 1, y);
break;
case 'ArrowRight':
moveHero(x + 1, y);
break;
}
});

createBoard();
});
43 changes: 43 additions & 0 deletions Hoplite/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f5f5f5;
margin: 0;
}

.container {
text-align: center;
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

#gameBoard {
display: grid;
grid-template-columns: repeat(5, 50px);
gap: 5px;
margin: 20px 0;
}

.cell {
width: 50px;
height: 50px;
background-color: #ddd;
display: flex;
justify-content: center;
align-items: center;
border: 1px solid #ccc;
cursor: pointer;
}

.cell.hero {
background-color: #ffa;
}

.cell.enemy {
background-color: #f88;
}
Loading