I'd like to make a simple text-based game using either JavaScript or PHP. Ideally I'd like to be able to render ASCII text in a kind of blackscreen "console" style (think console roguelikes such as Crawl or Nethack, or old Infocom text adventure games). The game would be simple, mostly text entry and menu choices.

Is this easily done using JS or PHP; if so, could you give me some pointers, and if not, what could I use to have this kind of game running from a browser rather than an executeable?

  • \$\begingroup\$ Don't use fancy frameworks just for the sake of it. Also, have a look at this for a ready-made javascript console: openexchangerates.github.io/javascript-sandbox-console There might be others, as I remember using a different one, but this is the one I found with a quick search. \$\endgroup\$ – rootlocus Dec 21 '14 at 23:13

You could build the entire game in JavaScript for sure. Be aware that the source-code will be visible to the user. So if you're concerned about cheating (probably a non-issue if it's just a single-player game), then you should have your game logic on the server.

JavaScript and PHP is definitely going to work.

If I were creating such a game, I would do the following:

  • Use a robust JavaScript framework like jQuery or Mootools for the client.
  • Write the game logic in PHP. This could be plain PHP, but a framework like Zend, Saphire or Symfony can speed up development of complex projects quite a bit.
  • Try to have your game-quests and items in data-files or a database to facilitate updates to your game-world. Avoid having your data in your code.
  • Start with simple page-requests for testing, then move to asynchronous requests (AJAX) for a nicer user-experience.
  • Always start with the most simple input method possible. A form field and a send button should be sufficient to start sending some user-input to the server. You can implement more sophisticated methods in your client as soon as the basic communication works.
  • Don't trust the user input! Always validate/sanitize data coming from the client.

On top of bummzack's answer, which is pretty well fleshed out, I would give you one bit of advice.

Before you get into animating, make sure your PHP is solid. One good way of testing is to have several buttons on the page for your various actions, and use them with a simple POST call.

If you can nail down your game processing logic, then animating it should be a simple step forward. But, debugging AJAX requests can certainly be a headache if you're not careful.


This is very much possible in javascript, you can also load your preferred console font from an .ttf or .otf file.


Yep, should be pretty easy to do in HTML/JavaScript. Take a pre block and style it as you see fit. For input you should probably ditch text input fields and just use the key events.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.