Js Right
Js Right
DOCTYPE html>
<head>
<meta charset="utf-8">
</head>
<body>
<div class="wrapper">
<div class="game-details">
</div>
<div class="play-board"></div>
<div class="controls">
</div>
</div>
</body>
</html>
and your Styles.css FILE should have the following code/* Import Google font */
@import url('https://fonts.googleapis.com/css2?
family=Open+Sans:wght@400;500;600;700&display=swap');
*{
margin: 0;
padding: 0;
box-sizing: border-box;
body {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
background: #E3F2FD;
.wrapper {
width: 65vmin;
height: 70vmin;
display: flex;
overflow: hidden;
flex-direction: column;
justify-content: center;
border-radius: 5px;
background: #293447;
.game-details {
color: #B8C6DC;
font-weight: 500;
font-size: 1.2rem;
display: flex;
justify-content: space-between;
.play-board {
height: 100%;
width: 100%;
display: grid;
background: #212837;
.play-board .food {
background: #FF003D;
.play-board .head {
background: #60CBFF;
}
.controls {
display: none;
justify-content: space-between;
.controls i {
padding: 25px 0;
text-align: center;
font-size: 1.3rem;
color: #B8C6DC;
cursor: pointer;
.wrapper {
width: 90vmin;
height: 115vmin;
.game-details {
font-size: 1rem;
.controls {
display: flex;
.controls i {
padding: 15px 0;
font-size: 1rem;
}
let setIntervalId;
let score = 0;
clearInterval(setIntervalId);
alert( " MR KIKSY: Game Over! You are a FAILURE , you can never make it.. Press OK if you AGREE...");
location.reload();
velocityX = 0;
velocityY = -1;
velocityX = 0;
velocityY = 1;
velocityX = -1;
velocityY = 0;
velocityX = 1;
velocityY = 0;
// Calling changeDirection on each key click and passing key dataset value as an object
updateFoodPosition();
localStorage.setItem("high-score", highScore);
snakeX += velocityX;
snakeY += velocityY;
// Shifting forward the values of the elements in the snake body by one
snakeBody[0] = [snakeX, snakeY]; // Setting first element of snake body to current snake position
// Checking if the snake head hit the body, if so set gameOver to true
gameOver = true;
playBoard.innerHTML = html;
updateFoodPosition();
document.addEventListener("keyup", changeDirection);