-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2151 from Aditi22Bansal/master
Solved #2090- Hoplite
- Loading branch information
Showing
4 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |