date = 2023-04-29
tags = ["deno", "game"]

Snake on Deno

 #########################
 #                       #
 #                       #
 #          oo           #
 #        oOo            #
 #  SNAKE is DEAD.       #
 #                       #
 #  Press Enter to restart   Score: 5
 #                       #
 #           @           #
 #                       #
 #                       #
 #                       #
 #                       #
 #                       #
 #                       #
 #                       #
 #                       #
 #                       #
 #########################
 Press 'q' to quit

I was looking around for what I can do with Deno, and I got off to a tangent of the old text-based UI applications of the MS-DOS era. By nostalgia, I watched YouTube videos about the early PCs and the applications, and installed FreeDOS on QEMU and played with it a bit.

FreeDOS

A Deno program cannot present the rich visual and interactivity of Web or native applications. But with the ANSI escape sequences, you can make the next best thing, a text-based UI application.

https://en.wikipedia.org/wiki/ANSI_escape_code

There are lengths of descriptions about ANSI escape codes on the Wikipedia page but the codes needed just to draw characters on the screen are only a few. The following videos were helpful to get me started:

ANSI Sequence video by Sebastien Filion

'I will teach you how to make games in your terminal' by Tom

And here is how to run a rudimentary Snake game on Deno:

% deno run https://jaeyoung.se/toys/snake.js