src/games/snakeGame/level1/services/logic.js
//draw position of food and snake in board
draw position of food and snake in board
draw position of food and snake in board
draww() {
        this.canvas.width = Math.floor(window.innerWidth / this.box) * this.box - this.box;
        this.canvas.height = Math.floor(window.innerHeight / this.box) * this.box;
           this.snake.draw();
        this.board.draw();
        this.food.draw();
      of mouth
 this.snake.updateMouhtPositon(this.dir);
        if (this.snake.isFoodEated(this.food)) {
            if (this.score === 0) {
                this.score++;
            }
            else if (this.score % 10 === 0) {
                this.score += 101;
            } else {
                this.score++;
            }
            this.gameRef.updateScore(this.score)
            this.eat.play();
            this.food.updateFoodPosition(this.board.width, this.board.height)
        } else {
            this.snake.pop();
        }
        if (this.snake.isCollidedWithBoard()) {
            this.gameOver();
        }
        if (this.snake.isCollidedWithItself()) {
            this.gameOver();
        }
        this.snake.addSnakeCell();
    }
draww ( ) { this . canvas . width = Math . floor ( window . innerWidth / this . box ) * this . box - this . box ; this . canvas . height = Math . floor ( window . innerHeight / this . box ) * this . box ; this . snake . draw ( ) ; this . board . draw ( ) ; this . food . draw ( ) ; this . snake . updateMouhtPositon ( this . dir ) ; if ( this . snake . isFoodEated ( this . food ) ) { if ( this . score === 0 ) { this . score ++ ; } else if ( this . score % 10 === 0 ) { this . score += 101 ; } else { this . score ++ ; } this . gameRef . updateScore ( this . score ) this . eat . play ( ) ; this . food . updateFoodPosition ( this . board . width , this . board . height ) } else { this . snake . pop ( ) ; } if ( this . snake . isCollidedWithBoard ( ) ) { this . gameOver ( ) ; } if ( this . snake . isCollidedWithItself ( ) ) { this . gameOver ( ) ; } this . snake . addSnakeCell ( ) ; }
draw position of food and snake in board
draw position of food and snake in board
//draw the snake (each cell) //now draw the board //draw the food //update the position //update the position of mouth //update the food position //check if snake is collided with board or not //check if snake collided with itself or not