Skip to content

Commit

Permalink
Merge pull request #8 from BijanRegmi/restart
Browse files Browse the repository at this point in the history
Restart functionality added
  • Loading branch information
YugalPradhan committed Oct 12, 2022
2 parents 94ca1af + 2c60cda commit cfdad7f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions index.html
Expand Up @@ -112,6 +112,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 @@ -138,6 +140,7 @@
moveenemy(car);
score.innerHTML="score :"+ score1;
}
function createRoadStrip(){
for(i=0;i<6;i++)
{
let roadstrip=document.createElement('div');
Expand All @@ -146,6 +149,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 @@ -158,6 +164,7 @@
enemy.style.left=enemy.x + "px";
enemy.style.backgroundImage=`url('enemycar${sinn}.png')`;
}
}

function movelines()
{
Expand Down Expand Up @@ -210,8 +217,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>

0 comments on commit cfdad7f

Please sign in to comment.