Approaching the Javascript Game: How Do the Parts Fit Together?
Before you dive in to a project like this, it helps to understand how the individual parts will fit together. What programming skills are you going to need to build a browser-based game run by Javascript and PHP?
Javascript is a perfect option for the interface. You can rig elements to capture input - mouse clicks, button presses, etc. This input can then be used to dynamically alter the face of the site - redrawing the game's canvas.
A PHP script would be better suited for handling the logic of the game. You could use this to interface with files or a database (for game saving), evaluating victory conditions, and programming an artificial intelligence. This also shields some of your code from the viewer - so they don't know what the answer is to the quiz show, or what the computer is going to do next.
Finally, you need a way to join the Javascript and the PHP. The solution? AJAX. After your script captures some input, it fires off an AJAX request to the PHP script and then uses the response to determine how to alter the output.
If you're unfamiliar with some of these things, check out this list of AJAX and DOM resources. You can also check out some of these PHP Tutorials for guidance in that direction.
Where to Start? Building a Tic Tac Toe Board
A good first project would be to build a Tic Tac Toe board. It's a simple visual design, the choices are limited enough to make an AI possible, and the user-input is fairly straightforward.
How should we design a graphical interface for this? Using HTML and CSS, we can build our board out of div tags. Each div is a square with a fixed height/width. These are then stacked into a 3x3 board using floats and clears where needed.
Each div can have a javascript function attacked to its onClick attribute. This calls a piece of Javascript to give it a certain background - therefore marking it as circle or square. Here's a good article about the idea behind this type of Javascript game board.
To finalize the functionality, you'll have to add some logic to your Javascript. It should track the current player - which determines which background image (circle or cross) is added to the div. You can also use some more DOM trickery to add a message to the user - printing the current player's term.
You could dive right in and try to develop this yourself, or check out this example script with working game demo.
Published by B. Rock
I'm a recent graduate, a newly wed, and a (no longer first year) teacher. I teach HS Social Studies in a New Jersey city. I graduated from the Rutgers Grad School of Ed in May of 2007. In July '07, I... View profile
- Jobs in the Game Industry that Don't Require Coding or Scripting ExperienceEver want to work in the game industry, but don't have any of the technical computer experience? Not to worry, there are other opportunities to get involved.
- Which Video Game Company is the Best Employer?So you decided to join the game industry - what company do you want to join though?
How Modding for Your Favorite Computer Game Could Land You a Job in the...Many people trying to get a job in the video game industry are discouraged by the experience requirement. In order to get a job, most game developers prefer experience, but how...- Game Careers: ProgrammersFind out everything you need to get started to be a video game programmer.
- Video Game Careers: AudioThis is something I am working on getting involved in. Find out what it takes for you to be a composer in the video game industry.
- Asynchronous JavaScript and XML (AJAX)
- Getting into the Video Game Designing Industry
- Westwood College Online's Game Art and Design Program
- More Oddness from Oddworld with Release of Angry Unknown-Person Game
- PS3 Game Review - Resistance: Fall of Man
- Essential Tools in Preparing for a Job as a Video Game Designer
- Virtual Console Quick Picks : Reviews of Every Wii VC Game in 2007
- DOM and Javascript allow you to manipulate the webpage and create an interface.
- A PHP script can handle the more intense logic operations like AI and victory conditions.
- Check out the working examples in the last link to see how it all comes together.



