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

Restart functionality added #8

Merged
merged 1 commit into from Oct 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions index.html
Expand Up @@ -113,6 +113,8 @@
gamearea.classList.remove('hide');
startscreen.classList.add('hide');
score.classList.remove('hide');
createRoadStrip()
createEnemies()
window.requestAnimationFrame(gameplay);
let car= document.createElement('div');
car.setAttribute('class','car');
Expand All @@ -139,6 +141,7 @@
moveenemy(car);
score.innerHTML="score :"+ score1;
}
function createRoadStrip(){
for(i=0;i<6;i++)
{
let roadstrip=document.createElement('div');
Expand All @@ -147,6 +150,9 @@
roadstrip.style.top=(i*110) + "px";
roadstrip.y=(i*110);
}
}

function createEnemies(){
for(i=0;i<3;i++)
{
let enemy=document.createElement('div');
Expand All @@ -157,6 +163,7 @@
enemy.x=Math.random()*330 + 25;
enemy.style.left=enemy.x + "px";
}
}

function movelines()
{
Expand Down Expand Up @@ -209,8 +216,12 @@
}
function restart()
{
document.location.href='';
// above code is to refresh the code
gamearea.innerHTML = ''
gamearea.classList.add('hide')
startscreen.innerHTML = 'Click to replay'
startscreen.classList.remove('hide')
score.classList.add('hide')
score1 = 0
}
</script>
</html>