Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question

4 Answers 4

up vote 9 down vote accepted

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.
share|improve this answer

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.

share|improve this answer

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

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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