Hoora

How to Create a Snake Game with AI

Snake is one of the best-known games out there. It was already on the old Nokia phones, and people still play it today. The rules are super simple and the difficulty ramps up on its own, which makes it a great first game to create with AI.

What makes a good Snake game

You know the idea: a snake moves on its own across a grid and you only choose its direction. An apple appears at random, and when the snake eats it, it grows by one segment and the score goes up. The game ends if the snake bites its own tail or hits a wall. The more it eats, the longer it gets, and the harder it is not to trap yourself.

The prompt to copy to create your Snake

This prompt asks for a standalone file straight away, with controls that work on keyboard and on mobile:

Create the Snake game in a single standalone HTML file (HTML, CSS and JS included, no external resources). Portrait 9:16 format. The snake is controlled by swipe (touch) and keyboard arrows. An apple appears at random, eating it makes the snake grow and adds +1 to the score, shown at the top. Collision with itself or with an edge = game over screen with the score and a "Play Again" button. Clean grid, smooth movement, a small animation when eating.

And there you go, you have your Snake. Test it, then let's refine it. If you want to understand the logic behind this kind of prompt, our guide on creating a game with ai covers it all from the start.

Iterating to give your game some punch

The first result works, but two or three tweaks make it a lot better. Stay in the same conversation and send these requests:

  • The pace. "Make the snake speed up slightly as the score goes up, so the difficulty increases naturally."
  • The feel. "Add a small pulse when an apple is eaten, an effect on collision, and a best score kept during the session."
  • Mobile. "Make the swipe precise and lag-free, enlarge the grid a bit on small screens, and stop the page from scrolling while playing."

You'll find more prompts in this style, sorted by type of game, in our article on the best prompts for an html5 game.

Customizing your snake to make it yours

The classic Snake already exists. To give yours its own identity, a few changes are enough:

  • The snake. A train, a caterpillar, a dragon, etc. The apple can become any object that fits your theme.
  • The walls. With walls you can pass through, the snake comes out on the other side, which makes the game more forgiving.
  • The obstacles. Put some in the middle of the grid to make games tougher.

Describe your idea to the AI, for example "turn the snake into a dragon and replace the apple with a treasure chest", and it takes care of the rest. For another classic that's easy to customize, see our guide to creating a 2048 puzzle game with ai.

Publishing your game online

When you're done, you have a standalone HTML file that contains all of the game's JavaScript. Except that as long as it stays on your computer, you're the only one who can play it. To let others play, it has to go online, and that's what Hoora does: you import your file and it becomes playable by the whole community.

Go to the website and click the purple "Import" button in the left-hand menu.

The Import button in the Hoora website side menu
  1. Drop in your HTML file, and a playable preview appears right away.
  2. Add a title and a description.
  3. Publish.

It's free, and the only limit is a maximum file size of 100 KB. The details of each step are in our article on publishing your ai creations.

A game published on Hoora with its community stats

Once published, your Snake is attached to your creator profile, and you follow its stats (views, likes, shares, comments) to see if people like it. Players get to it from the website or from the app, available on Android and iOS, and Hoora's funding round was covered by Gizmodo.

Frequently asked questions

  • Do you need to know how to code to create Snake with AI? No. The prompt gives you a complete, playable game: you copy it, paste it, and get the file back.
  • Which AI should you choose? ChatGPT, Claude, Gemini or Mistral all do the job. The precision of your prompt matters more than the model.
  • The snake is too fast or too slow, how do I adjust it? Ask the AI to set the starting speed and how much it speeds up with the score. Just mention it in the conversation.
  • Can I change the look or the rules? Yes. Snake appearance, walls you can pass through, obstacles, theme: describe your version and the AI applies it.
  • The swipe responds badly on my phone, what can I do? Ask for more responsive touch controls, then check on your device with our guide to testing an html5 game on mobile.
  • Do I need separate hosting? No, importing to Hoora doubles as hosting. The other options are compared in our guide on hosting an html5 game for free.
  • Where do I publish my Snake once it's made? On the Hoora website, with the "Import" button. It becomes playable by the community, with no hosting to set up.

Everybody knows how to play Snake, so everybody will get your version right away. Create yours, dress it up your way, and see who can beat your best score.