Skip to content

Commit

Permalink
Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
PawanSirsat committed Apr 15, 2024
1 parent 67bb125 commit 7293e89
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 152 deletions.
5 changes: 5 additions & 0 deletions font.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.jersey-10-regular {
font-family: "Jersey 10", sans-serif;
font-weight: 400;
font-style: normal;
}
80 changes: 17 additions & 63 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,79 +6,33 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>2000s Gaming Collection</title>
<link rel="stylesheet" href="style.css">
<style>
.game-item {
display: flex;
align-items: center;
}
<link rel="stylesheet" href="font.css">

.game-arrow {
cursor: pointer;
width: 20px;
/* Adjust size as needed */
height: auto;
margin-right: 10px;
/* Adjust spacing between image and text */
}

.selected .game-arrow {
display: inline;
/* Show arrow image for selected game */
}
</style>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Jersey+10&display=swap" rel="stylesheet">
</head>

<body>

<main>
<section id="collection">
<h2>Video Game Collection</h2>
<ul id="gameList">
<li class="game-item selected" onclick="toggleSelection(this)">
<img src="arrow.png" alt="Down" class="game-arrow">
<a href="game1.html">Game Title 1</a>
</li>
<li class="game-item" onclick="toggleSelection(this)">
<img src="arrow.png" alt="Down" class="game-arrow">
<a href="game2.html">Game Title 2</a>
</li>
<!-- Add more game links as needed -->
<h1 class="jersey-10-regular">Video Game Collection</h1>
<ul id="gameList" class="jersey-10-regular">
<!-- JavaScript will generate list items here -->
</ul>
</section>
</main>

<script>
function toggleSelection(item) {
const selected = document.querySelector('.selected');
if (selected !== item) {
selected.classList.remove('selected');
selected.querySelector('.game-arrow').style.display = 'none';
item.classList.add('selected');
item.querySelector('.game-arrow').style.display = 'inline';
}
}

document.addEventListener('keydown', function (event) {
const selected = document.querySelector('.selected');
if (event.key === 'Enter') {
const selectedGame = selected.querySelector('a');
if (selectedGame) {
window.location.href = selectedGame.href;
}
} else if (event.key === 'ArrowUp') {
const prev = selected.previousElementSibling;
if (prev) {
toggleSelection(prev);
}
} else if (event.key === 'ArrowDown') {
const next = selected.nextElementSibling;
if (next) {
toggleSelection(next);
}
}
});
</script>

<audio id="selectSound">
<source src="select.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<audio id="startSound">
<source src="start.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>

<script src="script.js"></script>
</body>

</html>
112 changes: 68 additions & 44 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,80 @@
document.addEventListener('DOMContentLoaded', function () {
const games = [
{ href: 'https://www.google.com', name: 'Game Title 1' },
{ href: 'https://www.google.com', name: 'Game Title 2' },
// Add more games as needed
]

// Function to generate game list dynamically
// Function to generate game list dynamically
function generateGameList() {
const gameList = document.getElementById('gameList')
const games = gameList.querySelectorAll('li')
let selectedGameIndex = 0
games.forEach((game, index) => {
const listItem = document.createElement('li')
listItem.className = 'game-item'
if (index === 0) {
listItem.classList.add('selected')
}
listItem.onclick = function () {
toggleSelection(this)
}

function selectGame(index) {
console.log('index', index)
// Create the div for overlapping with the arrow
const overlapDiv = document.createElement('div')
overlapDiv.className = 'overlap'

// Remove the selected class from all games
games.forEach((game) => game.classList.remove('selected'))
const arrowImg = document.createElement('img')
arrowImg.src = 'arrow.png'
arrowImg.alt = 'Down'
arrowImg.className = 'arrow'

// Add the selected class to the specified game
games[index].classList.add('selected')
const gameLink = document.createElement('a')
gameLink.href = game.href
gameLink.textContent = game.name

// Focus on the selected game link for keyboard accessibility
games[index].querySelector('a').focus()
listItem.appendChild(overlapDiv) // Append the overlap div
listItem.appendChild(arrowImg)
listItem.appendChild(gameLink)
gameList.appendChild(listItem)
})
}

// Update the selected game index
selectedGameIndex = index
}
// Call the function to generate the game list
generateGameList()

// Select the first game by default
selectGame(selectedGameIndex)
// Function to toggle selection
function toggleSelection(item) {
const selected = document.querySelector('.selected')
if (selected !== item) {
selected.classList.remove('selected')
selected.querySelector('.arrow').style.display = 'none'
item.classList.add('selected')
item.querySelector('.arrow').style.display = 'inline'

// Function to handle navigation to the selected game link
function navigateToSelectedGame() {
const selectedGameLink = games[selectedGameIndex].querySelector('a')
if (selectedGameLink) {
window.location.href = selectedGameLink.href
}
const selectSound = document.getElementById('selectSound')
selectSound.play()
}
}

document.addEventListener('keydown', function (event) {
if (event.key === 'ArrowUp') {
if (selectedGameIndex > 0) {
console.log('-')
selectGame(selectedGameIndex - 1)
}
} else if (event.key === 'ArrowDown') {
if (selectedGameIndex < games.length - 1) {
console.log('+')
selectGame(selectedGameIndex + 1)
}
} else if (event.key === 'Enter') {
navigateToSelectedGame()
// Add event listener for keyboard navigation
document.addEventListener('keydown', function (event) {
const selected = document.querySelector('.selected')
if (event.key === 'Enter') {
const selectedGame = selected.querySelector('a')
if (selectedGame) {
const startSound = document.getElementById('startSound')
startSound.play()
window.location.href = selectedGame.href
// Play the start sound
}
})

// Add click event listeners to the game list items
games.forEach((game, index) => {
game.addEventListener('click', function () {
selectGame(index)
navigateToSelectedGame()
})
})
} else if (event.key === 'ArrowUp') {
const prev = selected.previousElementSibling
if (prev) {
toggleSelection(prev)
}
} else if (event.key === 'ArrowDown') {
const next = selected.nextElementSibling
if (next) {
toggleSelection(next)
}
}
})
Binary file added select.mp3
Binary file not shown.
Binary file added start.mp3
Binary file not shown.
101 changes: 56 additions & 45 deletions style.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
body {
font-family: monospace;
/* Use Arial Rounded MT Bold as the primary font */
background-color: #000;
color: #fff;
margin: 0;
Expand All @@ -15,78 +14,90 @@ main {
margin-top: 20px;
}

#collection h2 {
font-size: 24px;
#collection h1 {
font-size: 50px;
text-align: center;
}

/* Update the game tile styles */
#collection ul {
margin: 0;
padding: 0;
#gameList {
list-style-type: none;
/* Remove the list item decoration */
}

#collection li {
margin-bottom: 10px;
padding: 0;
}

#collection li a {

#gameList li a {
display: block;
padding: 10px;
/* Old-style green color */
color: #009900;
/* Darker green on hover */
text-decoration: none;
font-size: 25px;
font-weight: bold;
/* Make the title bigger */
/* Use a vintage font style */
font-size: 40px;
border-radius: 5px;
text-align: center;
transition: background-color 0.3s, transform 0.3s;
width: calc(100% - 20px);
/* Subtract arrow width from total width */
}

#collection li a:hover {
text-decoration: none;
transform: scale(1.01);
/* Scale up slightly on hover for an old-school effect */
}

#gameList {
list-style-type: none;
padding: 0;
}

#gameList li {
#collection li {
margin-bottom: 10px;
cursor: pointer;
position: relative;
}

.arrow {
position: absolute;
left: -40px;
/* Adjust the left position to position the arrow */
left: 50px;
top: 50%;
/* Center the arrow vertically */
transform: translateY(-50%);
/* Offset the arrow vertically */
width: 20px;
/* Set the width of the arrow */
height: 20px;
/* Set the height of the arrow */
width: 10px;
/* Adjust the width of the arrow */
height: auto;
/* Automatically adjust the height */
background-image: url('arrow.png');
/* Set the background image of the arrow */
background-size: cover;
/* Ensure the arrow image covers the element */
display: none;
/* Hide the arrow by default */
}

#gameList li {
margin-bottom: 10px;
position: relative;
}

#gameList li.selected .arrow {
display: inline-block;
/* Show the arrow for the selected game */
}

/* CSS for the overlap div */
/* CSS for the overlap div */
/* CSS for the overlap div */


/* CSS for the game item */
.game-item {
position: relative;
display: flex;
align-items: center;
/* Adjust the left padding for the game name */
}

/* CSS for the arrow */
.arrow {
width: 10%;
/* Adjust the size of the arrow */
}

/* CSS for the game link */
.game-item a {
width: 75%;
/* Adjust the width of the game name */
margin-left: 5px;
/* Add margin to separate arrow from game name */
}

/* CSS for the game list */
#gameList {
list-style-type: none;
padding: 0;
margin: 0 auto;
/* Center the game list horizontally */
max-width: 600px;
/* Adjust the maximum width as needed */
}

0 comments on commit 7293e89

Please sign in to comment.