Boggle Game Generator

Boggle game generator! A simple PHP script that creates a 5x5 Boggle board game layout. The PHP script creates random letters -- print them out and you and your friends or co-workers can play for hours!
show me!

A friend of mine mentioned Boggle one day and I had an unusual desire arise that I could easily create a web page that generated a random Boggle board game. I thought it would be so easy, I touted 20 minutes to make the site. From the source code below, you can clearly see that 20 minutes is do-able – I think it may have taken me more like 45 minutes due to the little graphic and the stylesheet modifications. However, as promised, take a look at the simple source code for creating your own Boggle board game page.

<html>
<head>
 <title>devtrends.com Boggle generator</title>

 <STYLE>
 <!--
 .letterbox {
 padding:25px;
 margin:4px;
 border:1px dashed #9E7760;
 width:38px;
 text-align:center;
 background-image:url('./boggle_letter_1.jpg');
 }
 -->
 </STYLE>

</head>
<body style="background-color:#FFFFFF;">

<center>
 <table style="border:1px solid #9E7760;font-size:25px;font-family:Verdana;color:#000000;font-weight:bold;">
 <tr><td><?php echo returnLetter(rand(1, 26)); ?></td><td><?php echo returnLetter(rand(1, 26)); ?></td><td><?php echo returnLetter(rand(1, 26)); ?></td><td><?php echo returnLetter(rand(1, 26)); ?></td><td><?php echo returnLetter(rand(1, 26)); ?></td></tr>
 <tr><td><?php echo returnLetter(rand(1, 26)); ?></td><td><?php echo returnLetter(rand(1, 26)); ?></td><td><?php echo returnLetter(rand(1, 26)); ?></td><td><?php echo returnLetter(rand(1, 26)); ?></td><td><?php echo returnLetter(rand(1, 26)); ?></td></tr>
 <tr><td><?php echo returnLetter(rand(1, 26)); ?></td><td><?php echo returnLetter(rand(1, 26)); ?></td><td><?php echo returnLetter(rand(1, 26)); ?></td><td><?php echo returnLetter(rand(1, 26)); ?></td><td><?php echo returnLetter(rand(1, 26)); ?></td></tr>
 <tr><td><?php echo returnLetter(rand(1, 26)); ?></td><td><?php echo returnLetter(rand(1, 26)); ?></td><td><?php echo returnLetter(rand(1, 26)); ?></td><td><?php echo returnLetter(rand(1, 26)); ?></td><td><?php echo returnLetter(rand(1, 26)); ?></td></tr>
 <tr><td><?php echo returnLetter(rand(1, 26)); ?></td><td><?php echo returnLetter(rand(1, 26)); ?></td><td><?php echo returnLetter(rand(1, 26)); ?></td><td><?php echo returnLetter(rand(1, 26)); ?></td><td><?php echo returnLetter(rand(1, 26)); ?></td></tr>
 </table>
</center>

</body>
</html>

<?php
function returnLetter($num) {
 switch ($num) {
 case 1: $returnVal = "A";break;
 case 2: $returnVal = "B";break;
 case 3: $returnVal = "C";break;
 case 4: $returnVal = "D";break;
 case 5: $returnVal = "E";break;
 case 6: $returnVal = "F";break;
 case 7: $returnVal = "G";break;
 case 8: $returnVal = "H";break;
 case 9: $returnVal = "I";break;
 case 10: $returnVal = "J";break;
 case 11: $returnVal = "K";break;
 case 12: $returnVal = "L";break;
 case 13: $returnVal = "M";break;
 case 14: $returnVal = "N";break;
 case 15: $returnVal = "O";break;
 case 16: $returnVal = "P";break;
 case 17: $returnVal = "Q";break;
 case 18: $returnVal = "R";break;
 case 19: $returnVal = "S";break;
 case 20: $returnVal = "T";break;
 case 21: $returnVal = "U";break;
 case 22: $returnVal = "V";break;
 case 23: $returnVal = "W";break;
 case 24: $returnVal = "X";break;
 case 25: $returnVal = "Y";break;
 case 26: $returnVal = "Z";break;
 }
 return $returnVal;
}
?>

3 Comments

  1. Tom Gilbert said:

    Now I want to see a script that will find all the possible words using a dictionary file.

    October 17, 2009
    Reply
  2. Elizabeth said:

    On a real boggle board, each letter does not have the same probability of appearing. Also, “Qu” is a letter. I’d like to see a script that better reflects this, because this boggle board does not look like any I’ve ever seen before.

    January 11, 2010
    Reply
    • said:

      You make a valid point. The randomization on the script would be any of the 26 letters, whereas, in a real Boggle game each cube only has a chance of 6 letters. When I have a moment, I’ll update the code.

      January 18, 2010
      Reply

Leave a Reply to Elizabeth Cancel reply

Your email address will not be published. Required fields are marked *