Simple PHP: A Barcode Monster Generator!

Barcodes can contain lots of useful information, and now you can find some crazy monsters out of them as well! Though the idea has been around for decades, it’s still as entertaining as ever! See what I came up with!

Let’s start with some math: if you have two arrays with 10 elements each, how many different combinations can you make? Yes, roughly a hundred, as 10 into the power of 2 equals 100. To keep things simple, I made a generator that could produce 10,000 different combinations out of four 10-element arrays, though it would be trivial to extend the number exponentially by adding more arrays, or, better yet, by adding more elements into each array for a little more diversity.

When it comes to monsters, those tables could contain pretty crazy stuff! Let’s make a 10-element PHP-array with some monster qualities:

$monster_qualities =
"0" => "Helpless",
"1" => "Lazy",
"2" => "Friendly",
"3" => "Loyal",
"4" => "Trustworthy",
"5" => "Crazy",
"6" => "Angry",
"7" => "Powerful",
"8" => "Superior",
"9" => "The Ultimate"

Oh yeah, at this point it seems, the bigger the number, the stronger the monster. Let’s add a second array containing some information about the monster’s habits:

$monster_habits =
"0" => "underwater",
"1" => "subterranean",
"2" => "crawling",
"3" => "lurking",
"4" => "hideous",
"5" => "omnivorous",
"6" => "coldblooded",
"7" => "urban",
"8" => "flying",
"9" => "intergalaxial"

The third array would contain some original monster names, perhaps:

$monster_names =
"0" => "beetlebug",
"1" => "landworm",
"2" => "spiderthing",
"3" => "rattlesnake",
"4" => "werewolf",
"5" => "zombiecreep",
"6" => "boogeyman",
"7" => "killerbat",
"8" => "executioner",
"9" => "grim reaper"

And finally, as every self-respecting monster should wield a weapon, the last array could be as follows:

$monster_weapons =
"0" => "a banana",
"1" => "brass knuckles",
"2" => "a golf club",
"3" => "a knife",
"4" => "a longsword",
"5" => "a handgun",
"6" => "a shotgun",
"7" => "a flamethrower",
"8" => "a machine gun",
"9" => "a rocket launcher"

Next, we need some creative thinking in order to resolve barcodes into these monster things. That could be done in many ways, but I thought it would be simple enough to pass the barcode into the program using a regular HTTP POST form. I would suggest something like this:

$code = $_POST['code'];

$mq = substr($code, 5, 1);
$mh = substr($code, 3, 1);
$mn = substr($code, 2, 1);
$mw = substr($code, 6, 1);

$q = $monster_qualities[“$mq”];
$h = $monster_habits[“$mh”];
$n = $monster_names[“$mn”];
$w = $monster_weapons[“$mw”];

echo “$q $h $n with $w”;

Simple as that! Pick a number from the passed code for each array, pick the string at that index from the corresponding array and combine the strings into a brand new monster! Of course, you would check the passed code for non-numeric values before processing, but in the end, for example, if you give it an EAN-8 barcode of “23714781”, you would say hello to “Powerful subterranean killerbat with a machine gun”!

If you refine the idea a little further, you could as well create similar arrays for different entities, like treasures, items or gold, make them go into a database, derive monster stats from barcode numbers for a monster battle or implement a multi-user platform for trading those treasures and items!

Go ahead and write a full-blown barcode collector game for some serious entertainment value while you’re at it, but be aware of mister “99999999”, for he is The Ultimate Intergalaxial Grim Reaper with a Rocket Launcher!


One comment

  1. Nice 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: