Introduction to the Snake Game

Get familiarized with the snake game that we are going to build in this chapter.

We'll cover the following

Introduction

From this lesson onwards, we'll start building our first project with arrays and object-oriented programming. We'll build the snake game in four steps, which will be covered in each subsequent lesson. Below are the four steps that we'll follow:

  1. Create a board and then plot a snake on that board.

  2. Add the movement to the snake.

  3. Add movement to the snake based on the user input through the keyboard.

  4. Add a food object for the snake.

We'll be creating a server that will serve our HTML pages. We can then even deploy the games online, which we make throughout this course—we'll create a server, and you will get a unique URL for your games. You can visit this URL to build and play the games. Since this course does not focus on how to make web apps, we will keep it super simple. All the server-related functionalities will be handled in the backend, and you can focus on building your games.

Note: If you cannot move the snake with your keyboard input, try opening the app URL in a different browser tab and playing it there.

What is the game about?

This simple game builds upon the concepts that we've covered so far in this course. The player will move the snake around the board with the keyboard arrow keys. The goal is to eat food and lengthen the snake, without hitting the boundary of the canvas. We'll be using similar logic to what we used earlier in this chapter to move objects in multiple directions using keyboard input. The game will be over if the objects reach the boundary of the canvas. By clicking on the "Click to launch app!" button below, you can try playing the game:

Get hands-on with 1200+ tech skills courses.