How to build a HTML game in 5 lines Part II

Summary
Ninjas learn to build their first text-based game using HTML.

Tips for use
You will need to either install Scratch on the Ninja's machine or use the web-based editor in advance of using these cards.

Content
So it's several months later, you've built 10-20 pages and you've got divs and css and bits of javascript here and there. But it's starting to get complicated, the pages are difficult to maintain, there is no memory between pages and it's starting to become boring.

This is where php steps in.

Instead of a room.html for every room we are now going to go back over all our html files and copy the contents into one file called message.php.

The contents of each file will go into one position in an array like so

$room[0] = " You are standing outside a castle. There is a moat....... ";

$room[1] = " You are inside the castle. ";

$room[2] =" You are dead. ";

How you move from one room to another (from array [index] to array [index]) is entirely down to the individual chapters and coder style. I use an index.php file to jump through case/switch staements and if statements.

index.php Begin the adventure

index2.php

Turn on Your computer”; echo “or ”; echo “Leave”; }   if ($job ==”computer”) {       //do stuff }   if ($job ==”Leave_Room”) {       //do stuff }   ?>

I save the room index locations to each individuals players mysql table, so they can continue where they left off.

How to build a HTML game in 5 lines- From Galway Dojo #1,1. Credit: Techbot How to build a HTML game in 5 lines Part II - From Galway Dojo #1,2. Credit: Techbot How to build a HTML game in 5 lines Part III - From Galway Dojo #1,3. Credit: Techbot