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

Hints and HighScore #172

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
34 changes: 33 additions & 1 deletion JS/Simon Says/app.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
let gameSeq = [];
let userSeq = [];
//new
let highScore = 0;


let btns = ["yellow", "red", "purple", "green"];

let started = false;
let level = 0;

let h2 = document.querySelector("h2");
let highScoreDisplay = document.querySelector(".highscore");

document.addEventListener("keypress", function () {
if (started == false) {
Expand Down Expand Up @@ -42,6 +46,17 @@ function levelUp() {
gameSeq.push(randColor);
console.log(gameSeq);
gameFlash(randBtn);
//new
resetHint();
}
//new
function gameScoreDisplay(){
if (level === 0){
h2.innerHTML = `Game Over! Your score was <b>${level}</b> <br> Press any key to start. `;
}else{
h2.innerHTML = `Game Over! Your score was <b>${level-1}</b> <br> Press any key to start. `;
}

}

function checkAns(idx) {
Expand All @@ -50,12 +65,19 @@ function checkAns(idx) {
setTimeout(levelUp, 1000);
}
} else {
h2.innerHTML = `Game Over! Your score was <b>${level}</b> <br> Press any key to start.`;
gameScoreDisplay();
document.querySelector("body").style.backgroundColor = "red";
setTimeout(function () {
document.querySelector("body").style.backgroundColor = "white";
}, 150);
if (level-1 > highScore){
highScore = level-1;
highScoreDisplay.innerHTML = `<h1> <b> High Score: ${highScore} </b> </h1>`;

}

reset();
resetHint();
}
}

Expand All @@ -80,3 +102,13 @@ function reset() {
userSeq = [];
level = 0;
}
//new
function resetHint(){
hintBox.innerHTML="";
}

let hintBtn = document.querySelector(".hint");
let hintBox = document.querySelector(".hintBox");
hintBtn.addEventListener("click",function(){
hintBox.innerHTML=`${gameSeq}`
});
12 changes: 12 additions & 0 deletions JS/Simon Says/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Simon Says Game</title>
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0&icon_names=lightbulb" />
</head>
<body>
<h1>Simon Says Game</h1>
Expand All @@ -20,6 +21,17 @@ <h2>Press any key to start the game</h2>
<div class="btn purple" type="button" id="purple">4</div>
</div>
</div>
<!--Hint button addition -->
<div class="hintMain">
<div class="hint" type = "button">
<span class="material-symbols-outlined">lightbulb</span>
</div>
<div class="hintBox"></div>
</div>

</div>
<!--High score -->
<div class="highscore"></div>

<script src="app.js"></script>
</body>
Expand Down
32 changes: 32 additions & 0 deletions JS/Simon Says/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,35 @@ body {
.userflash {
background-color: green;
}
/* new */
.highscore{
height: 50px;
width: 300px;
/* border: 1px solid black; */
border-radius:25%;
margin: auto;
padding:auto;
}

.hintMain{
display:flex;
justify-content:center;
width:100px;
height:50px;
}

.hint{
background-color: yellow;
height: 30px;
width: 30px;
border-radius: 50%;
margin:auto;
padding: auto;
cursor: pointer;
}

.hintBox{
margin:auto;
/* padding: auto; */
width:60px;
}