Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

OL Crossword puzzle server/client

by wombat (Curate)
on Aug 27, 2000 at 07:05 UTC ( #29848=sourcecode: print w/ replies, xml ) Need Help??

Category: Fun Stuff
Author/Contact Info Adam For writing the original table generating code.
wombat For form functionality.
Description: This is an improvement over Adam's crossword puzzle generator. Each cell now conatins a 1 character text field, allowing you to actually fill it in and submit your answers to a site. The processing script is straightforward and one can program any number of events to happen when someone solves a puzzle (or submits an incorrect answer) :-). The one in the example is the same puzzle that was written by KM here. Since he said that he would post the answers in a few days, I shall refrain from including the solution in the code.

Basically, in order to find the correct solution string to plug into the solution checker, you need to run each block's character together into one long string. It's ugly from a human standpoint, but it's easy to process. I hope to create a dynamic generator in the near future which would, from a list of words and corresponding clues automatically generate the grid, and thereby easily generate the solution string. Enjoy! ~W
The grid generator code:
#!/usr/bin/perl -w

use strict;
# I wrote this to generate a file, not be a cgi script, but you could.
+..
# use CGI.pm;

open GRID, '>../html/grid.html' or die $!;
select GRID;

print "<HTML><BODY>\n";
print "<FORM method=GET action=http://your.host.machine/cgi-bin/crossp
+rocess.pl>
\n";

my $cellwidth = '20';  # pixel or percent
my $cellheight = '4'; # pixels only
my $counter = 0;

sub Solid
{
    return "<TD WIDTH='$cellwidth' HEIGHT='$cellheight' ".
           "BGCOLOR='BLACK'>&nbsp;</TD>\n";
}

sub Open
{
    return "<TD WIDTH='$cellwidth' HEIGHT='$cellheight' ".
           "BGCOLOR='WHITE' VALIGN='BOTTOM'><input type=text size=1 na
+me='x' max
length=1></TD>\n";
}

sub Numbered
{
    ++$counter;
    return "<TD WIDTH='$cellwidth' HEIGHT='$cellheight' BGCOLOR='WHITE
+'".
           "ALIGN='LEFT' VALIGN='TOP'><FONT SIZE=-2>$counter</FONT><in
+put type=t
ext size=1 name='x' maxlength=1></TD>\n";
}

# These two arrays are used to generate the grid.
# numbers in @line correspond to the functions in @type.
# 0 black box, 1, white box, 2, numbered box.
my @type = ( \&Solid, \&Open, \&Numbered );
my @line = (
'020000002000002000000000000',
'020000002000002000000000000',
'010200201021111110000020000',
'010100101000001002111110000',
'010102111121111111000010020',
'010100000010001001000202010',
'211121111110001021111101010',
'100010000010001001000101010',
'100010212111001002111111110',
'100010001010000001000101010',
'100010001000021111120001010',
'102111001000000000010001010',
'101010211000000000010200200',
'101010001000000000211111111',
'101010000000211111010100100',
'102211111111100000000100100',
'100100000000102020000100100',
'000100000000101010000100100',
'002111000211111111100000000',
'000000000000101000000000000',
'000000211111111000000000000',
);

print "<TABLE BORDER=1 SHADE=0>\n";
foreach ( @line )
{
    print "<TR>\n";
    print map { &{$type[$_]} } split //;
    print "</TR>";
}
print "\n</TABLE>";
print "<input type=submit value=\"I'd like to solve the puzzle please\
+">\n";
print "\n</form>";
print "</body></html>";


And the processing code:

#! /usr/bin/perl -w
require ("cgi-lib.pl");

$success=0;

print "Content-type: text/html\n\n";

@my_query = split(/&/,$ENV{'QUERY_STRING'});

foreach (@my_query)
 {
@key_value = split(/=/,$_);
push @solved, $key_value[1];
 }

$solved_str = join('',@solved);

if ($solved_str eq "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx
+yzabcdefgh
ijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
+abcdefghij
klmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzab
+cd")
 {
  $success=1;
 }

if ($success)
 {
print << 'End_Of_Text';
<html>
<head>
<title>
Success.
</title>
</head>
<body bgcolor=#004400 text=ffffff>
<h3>Hooray!  You've solved the puzzle!</h3>
Congrats.  Go out, have a beer. Eat some salami.  
</body>
</html>
End_Of_Text
 }
else 
 {
print << 'End_Of_Text';
<html>
<head>
<title>
Failure.
</title>
</head>
<body bgcolor=#440000 text=ffffff>
<h3>Sorry, try again.</h3>
One of your answers is incorrect.  Click back and try again.
</body>
</html>
End_Of_Text
 }

Comment on OL Crossword puzzle server/client
Select or Download Code
RE: OL Crossword puzzle server/client
by vroom (Pope) on Aug 27, 2000 at 08:01 UTC
    One idea that might be cool is if you were to select a naming convention for the parameters such as a1_1 for the first letter in 1 across for instance than you could show which clues the user had answered correctly/incorrectly.

    I really like the idea of being able to take the word galaxy generator to input a clue and then a word. Then Adam's table generator to pretty the output up and your text field functionality to test for correct answers. So anyone could input a set of clues and answers and then have a crossword puzzle and then be able to check whether users have entered correct answers.

    ok it's late and I haven't had nearly enough sleep lately. Hopefully some of that made sense. I really like to see group collaboration happening on this crossword puzzle idea.

    vroom | Tim Vroom | vroom@cs.hope.edu

Re: OL Crossword puzzle server/client
by OxYgEn (Acolyte) on Feb 29, 2004 at 19:06 UTC
    I'm sorry I'm very very extremely new at perl and I am wondering how exactly you use this? I've researched a few web languages including HTML and I understand all the HTML tags that i see in there, yet I don't know what to do...

    Thanks, Oxygen

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://29848]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (19)
As of 2014-10-23 13:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (125 votes), past polls