Skip to content

Commit

Permalink
Merge pull request #176 from aditya-bhaumik/feature
Browse files Browse the repository at this point in the history
[New Feature]: Add Theme Switcher Button to Change Background Video
  • Loading branch information
ayush-t02 authored May 19, 2024
2 parents 0f2c001 + 24609e2 commit 946beee
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 10 deletions.
1 change: 1 addition & 0 deletions background/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This folder contains all the backgroud video themes used in this project.
Binary file added background/back.mp4
Binary file not shown.
Binary file added background/back2.mp4
Binary file not shown.
Binary file added background/back3.mp4
Binary file not shown.
Binary file added background/back4.mp4
Binary file not shown.
Binary file added background/back5.mp4
Binary file not shown.
35 changes: 26 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

<!-- Stylesheet -->
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="theme.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<!-- JavaScript files -->
<script defer src="./js/edge.js"></script>
<script defer src="./js/box.js"></script>
<script defer src="./js/board.js"></script>
<script defer src="./js/game.js"></script>
<script defer src="./js/theme.js"></script>

<!-- Logo of the game -->
<link rel="shortcut icon" href="./favicon.ico" type="image/x-icon">
Expand All @@ -30,48 +32,52 @@
<source src="./back.mp4" type="video/mp4">
</video>
<div class="form">
<div class="overlay-container">
<h1 class="heading"
style="font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif; color:rgb(52, 76, 100);">
▁ ▂ ▄ ▅ ▆ ▇ █ <span style="color: rgb(87, 166, 161);">MAXIMISE</span> BOXES!! █ ▇ ▆ ▅ ▄ ▂ ▁
</h1>

<h3 class="instructions-heading" style="color: white; background-color: rgb(87, 123, 141);">Instructions</h3>

<p class="instructions" style="color: rgb(52, 76, 100);">
<p class="instructions" style="color: rgb(211, 211, 211);">
<br>
1. Select the number of rows, columns and players. <br>
2. The player who has maximum number of boxes on board is the winner. <br>
3. Players will switch after every turn. But the player who has filled the last box, will get one extra
chance
consecutively. <br>
</p>

</div>
</div>

<div class="overlay-container">
<!-- Form page -->
<div class="form">

<div>
<h2 style="color: rgb(52, 76, 100);">What size of Board do you want? :</h2>
<h2 style="color: rgb(211, 211, 211);">What size of Board do you want? :</h2>
</div>

<div class="form-item">
<label for="rows" style="color: rgb(52, 76, 100);">Rows : <span class="details">(between 5 and 30)</span></label>
<label for="rows" style="color: rgb(211, 211, 211);">Rows : <span class="details">(between 5 and 30)</span></label>
<input type="number" id="rows" min="5" max="30" value="6" />
</div>

<div class="form-item">
<label for="columns" style="color: rgb(52, 76, 100);">Columns : <span class="details">(between 5 and 30)</span></label>
<label for="columns" style="color: rgb(211, 211, 211);">Columns : <span class="details">(between 5 and 30)</span></label>
<input type="number" id="columns" min="5" max="30" value="6" />
</div>

<div class="form-item">
<label for="players-count" style="color: rgb(52, 76, 100);">Players : <span class="details">(between 2 and 6)</span></label>
<label for="players-count" style="color: rgb(211, 211, 211);">Players : <span class="details">(between 2 and 6)</span></label>
<input type="number" id="players-count" min="2" max="6" value="2" />
</div>

<button class="start-btn" style="background-color:rgb(87, 123, 141);">START</button>

</div>

</div>

</div>

Expand All @@ -86,11 +92,22 @@ <h2 style="color: rgb(52, 76, 100);">What size of Board do you want? :</h2>

<!-- Game Page -->
<div class="board" style="margin-top: 154px;"></div>
<div>
<button id="theme-button" class="theme-btn">Change Theme</button>
<div id="theme-options" class="hidden">
<button class="theme-option" data-video="back.mp4">Starry Night</button>
<button class="theme-option" data-video="back2.mp4">Aurora</button>
<button class="theme-option" data-video="back3.mp4">Waterfall</button>
<button class="theme-option" data-video="back4.mp4">Garden</button>
<button class="theme-option" data-video="back5.mp4">Beach</button>
</div>
<!-- Background Videos -->
<video autoplay loop muted plays-inline class="back" id="background-video">
<source src="./background/back4.mp4" type="video/mp4">
</video>

<button class="mute-btn"><i class="fa fa-volume-up fa-2x"></i></button>

</body>

</html>
<!--Video by <a href="https://pixabay.com/users/blendertimer-9538909/?utm_source=link-attribution&utm_medium=referral&utm_campaign=video&utm_content=80645">Daniel Roberts</a> from <a href="https://pixabay.com//?utm_source=link-attribution&utm_medium=referral&utm_campaign=video&utm_content=80645">Pixabay</a>
</a>-->
2 changes: 2 additions & 0 deletions js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ startBtn.addEventListener("click", () => {
game = new Game(rows, columns, playersCount)
settingsUI.style.display = "none"
heading.style.display = "none"
document.getElementById('theme-options').style.display = 'none';
document.getElementById('theme-button').style.display = 'none';
});

function calculate(value, min, max) {
Expand Down
51 changes: 51 additions & 0 deletions js/theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
function setBackgroundVideo(videoSrc) {
const videoElement = document.querySelector('video.back');
videoElement.querySelector('source').setAttribute('src', videoSrc);
videoElement.load();
videoElement.play();
}

document.getElementById('theme-button').addEventListener('click', () => {
const themeOptions = document.getElementById('theme-options');
if (themeOptions.style.visibility === 'hidden' || themeOptions.style.visibility === '') {
themeOptions.style.visibility = 'visible';
} else {
themeOptions.style.visibility = 'hidden';
}
});

document.querySelectorAll('.theme-option').forEach(button => {
button.addEventListener('click', (event) => {
const videoSrc = `./background/${event.target.getAttribute('data-video')}`;
setBackgroundVideo(videoSrc);

// Save selected video in localStorage to persist the theme
localStorage.setItem('selectedTheme', videoSrc);
localStorage.setItem('selectedThemeName', event.target.innerText);

// Remove 'selected' class from all theme options
document.querySelectorAll('.theme-option').forEach(option => {
option.classList.remove('selected');
});

// Add 'selected' class to the clicked option
event.target.classList.add('selected');

// Hide theme options after selection
document.getElementById('theme-options').style.visibility = 'hidden';
});
});

// Check localStorage for saved theme and apply it
document.addEventListener('DOMContentLoaded', () => {
const savedTheme = localStorage.getItem('selectedTheme');
const savedThemeName = localStorage.getItem('selectedThemeName');
if (savedTheme) {
setBackgroundVideo(savedTheme);
document.querySelectorAll('.theme-option').forEach(option => {
if (option.innerText === savedThemeName) {
option.classList.add('selected');
}
});
}
});
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ a {
justify-content: center;
color: rgba(0, 0, 0, 0.864);
padding-top: 10px;
border-top: solid 1px #f9f9f9;

}

.player-turn .bg {
Expand Down
54 changes: 54 additions & 0 deletions theme.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
.theme-btn {
position: fixed;
top: 10px;
right: 10px;
padding: 10px 20px;
cursor: pointer;
background-color: #57667d;
color: white;
border: none;
border-radius: 5px;
z-index: 1000;
}

#theme-options {
position: fixed;
top: 50px;
right: 10px;
display: flex;
flex-direction: column;
background: rgba(0, 0, 0, 0.8);
padding: 10px;
border-radius: 5px;
z-index: 1000;
visibility: hidden;
}

.theme-option {
margin: 5px 0;
padding: 10px;
cursor: pointer;
background-color: #444;
color: white;
border: none;
border-radius: 5px;
}

.hidden {
display: none;
}


.overlay-container {
position: relative;
z-index: 1;
background: rgba(0, 0, 0, 0.5); /* Semi-transparent background */
padding: 20px;
border-radius: 10px;
color: white;
}

.theme-option.selected {
border: 2px solid #00f;
background-color: rgba(0, 0, 255, 0.1);
}

0 comments on commit 946beee

Please sign in to comment.