-
Notifications
You must be signed in to change notification settings - Fork 839
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 #4501 from AdityaP700/resolve-readme-conflict
Added KeySymphony Game
- Loading branch information
Showing
23 changed files
with
276 additions
and
7 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,46 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>KeySymphony</title> | ||
<link rel="stylesheet" href="style1.css"> | ||
<script src="index1.js" defer></script> | ||
</head> | ||
<body> | ||
<div class="wrapper"> | ||
<header> | ||
<h2> | ||
KeySymphony | ||
</h2> | ||
<div class="column sound"> | ||
<span>Sound</span><input type="range"> | ||
</div> | ||
|
||
<div class="column keys-checkbox"> | ||
<span>Show Keys</span><input type="checkbox" checked> | ||
</div> | ||
</header> | ||
<ul class="Piano"> | ||
<li class="key white" data-key="a"><span>a</span></li> | ||
<li class="key black" data-key="w"><span>w</span></li> | ||
<li class="key white" data-key="s"><span>s</span></li> | ||
<li class="key black" data-key="e"><span>e</span></li> | ||
<li class="key white" data-key="d"><span>d</span></li> | ||
<li class="key white" data-key="f"><span>f</span></li> | ||
<li class="key black" data-key="t"><span>t</span></li> | ||
<li class="key white" data-key="g"><span>g</span></li> | ||
<li class="key black" data-key="y"><span>y</span></li> | ||
<li class="key white" data-key="h"><span>h</span></li> | ||
<li class="key black" data-key="u"><span>u</span></li> | ||
<li class="key white" data-key="j"><span>j</span></li> | ||
<li class="key white" data-key="k"><span>k</span></li> | ||
<li class="key black" data-key="o"><span>o</span></li> | ||
<li class="key white" data-key="l"><span>l</span></li> | ||
<li class="key black" data-key="p"><span>p</span></li> | ||
<li class="key white" data-key=";"><span>;</span></li> | ||
<!-- <li class="key black"data-key="c"><span>c</span></li> --> | ||
</ul> | ||
</div> | ||
</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,43 @@ | ||
document.addEventListener("DOMContentLoaded", () => { | ||
const pianoKeys = document.querySelectorAll(".Piano .key"), | ||
volumeSlider = document.querySelector(".sound input"), | ||
keyCheckbox = document.querySelector(".keys-checkbox input"); | ||
|
||
let allKeys = [], | ||
audio = new Audio(); | ||
|
||
const playTune = (key) => { | ||
audio.src = `tunes/${key}.wav`; | ||
audio.play(); | ||
|
||
const clickedKey = document.querySelector(`[data-key="${key}"]`); | ||
if (clickedKey) { | ||
clickedKey.classList.add("active"); | ||
setTimeout(() => { | ||
clickedKey.classList.remove("active"); | ||
}, 160); | ||
} | ||
}; | ||
|
||
const handleVolume = (e) => { | ||
audio.volume = e.target.value / 100; | ||
}; | ||
|
||
const showHideKeys = () => { | ||
pianoKeys.forEach(key => key.classList.toggle("hide")); | ||
}; | ||
|
||
pianoKeys.forEach(key => { | ||
allKeys.push(key.dataset.key); | ||
// Calling playTune function with passing data-key value as an argument | ||
key.addEventListener("click", () => playTune(key.dataset.key)); | ||
}); | ||
|
||
const pressedKey = (e) => { | ||
if (allKeys.includes(e.key)) playTune(e.key); | ||
}; | ||
|
||
keyCheckbox.addEventListener("click", showHideKeys); | ||
volumeSlider.addEventListener("input", handleVolume); | ||
document.addEventListener("keydown", pressedKey); | ||
}); |
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,186 @@ | ||
|
||
@import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap'); | ||
|
||
*{ | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
font-family:'Poppins',sans-serif; | ||
} | ||
body{ | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
min-height: 100vh; | ||
background-color: rgb(207, 232, 255); | ||
} | ||
.wrapper{ | ||
border-radius: 20px; | ||
width:795px; | ||
background-color: black; | ||
padding: 32px 40px; | ||
|
||
} | ||
.wrapper header{ | ||
color: rgb(255, 255, 222); | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
justify-content: space-between; | ||
} | ||
header h2{ | ||
font-size:35px; | ||
} | ||
header .column{ | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
header .column span{ | ||
font-weight: 420; | ||
font-size: 18px; | ||
margin-right:15px; | ||
} | ||
.sound input{ | ||
accent-color: #c3c018; | ||
} | ||
.keys-checkbox input{ | ||
height:35px ; | ||
width:65px; | ||
cursor:pointer; | ||
border-radius:30px ; | ||
background: #118df3; | ||
appearance: none; | ||
outline:none; | ||
position: relative; | ||
} | ||
.keys-checkbox input::before{ | ||
content: ""; | ||
border-radius: inherit; | ||
position: absolute; | ||
background-color: rgb(137, 239, 217); | ||
width: 25px; | ||
height: 25px; | ||
top:50%; | ||
left: 5px; | ||
transform: translateY(-50%); | ||
transition: all 0.2s ease; | ||
} | ||
.keys-checkbox input:checked::before{ | ||
left:35px; | ||
background-color: antiquewhite; | ||
} | ||
.Piano{ | ||
display: flex; | ||
margin-top: 40px; | ||
/* padding: 20px 10px; */ | ||
justify-content: center; | ||
list-style: none; | ||
} | ||
.Piano .key{ | ||
list-style:none; | ||
/* color: rgb(143, 130, 112); */ | ||
text-transform: uppercase; | ||
cursor: pointer; | ||
user-select: none; | ||
position: relative; | ||
} | ||
.Piano .white{ | ||
width:80px; | ||
height:230px; | ||
border: 1px solid black; | ||
background: linear-gradient(#fff 96%,#eee 4%); | ||
border-radius: 9px; | ||
|
||
} | ||
.Piano .white:active{ | ||
box-shadow:inset -5px 5px 20px rgba(0,0,0,0.2); | ||
background-color: linear-gradient(to bottom, #fff 0%, #eee 100%); | ||
} | ||
.Piano .black{ | ||
width:44px; | ||
height:140px; | ||
/* border: 1px solid black; */ | ||
background: linear-gradient(#333 ,#000 ); | ||
border-radius: 0 0 5px 5px; | ||
z-index: 2; | ||
margin: 0 -22px 0 -22px; | ||
} | ||
.Piano .black:active{ | ||
box-shadow:inset -5px -10px 10px rgba(255,255,255,0.2); | ||
background-color: linear-gradient(to bottom, #000 , #434343); | ||
} | ||
.Piano span{ | ||
position: absolute; | ||
bottom: 20px; | ||
width: 100%; | ||
font-size: 1.15rem; | ||
text-align: center; | ||
} | ||
.Piano .key span { | ||
position: absolute; | ||
bottom: 20px; | ||
width: 100%; | ||
color: #A2A2A2; | ||
font-size: 1.13rem; | ||
text-align: center; | ||
} | ||
.Piano .key.hide span { | ||
display: none; | ||
} | ||
.Piano .black span { | ||
bottom: 13px; | ||
color: #888888; | ||
} | ||
.Piano .key{ | ||
list-style: none; | ||
color: rgba(174, 174, 174, 0.856); | ||
} | ||
.Piano .key.hide span { | ||
display: none; | ||
} | ||
.Piano .black span { | ||
bottom: 13px; | ||
color: #888888; | ||
} | ||
@media screen and (max-width: 815px) { | ||
.wrapper { | ||
padding: 25px; | ||
} | ||
header { | ||
flex-direction: column; | ||
} | ||
header :where(h2, .column) { | ||
margin-bottom: 13px; | ||
} | ||
.sound input { | ||
max-width: 100px; | ||
} | ||
.Piano { | ||
margin-top: 20px; | ||
} | ||
.Piano .key:where(:nth-child(9), :nth-child(10)) { | ||
display: none; | ||
} | ||
.Piano .black { | ||
height: 100px; | ||
width: 40px; | ||
margin: 0 -20px 0 -20px; | ||
} | ||
.Piano .white { | ||
height: 180px; | ||
width: 60px; | ||
} | ||
} | ||
@media screen and (max-width: 615px) { | ||
.Piano .key:nth-child(13), | ||
.Piano .key:nth-child(14), | ||
.Piano .key:nth-child(15), | ||
.Piano .key:nth-child(16), | ||
.Piano .key :nth-child(17) { | ||
display: none; | ||
} | ||
.Piano .white { | ||
width: 50px; | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.