<?php
// auxiliary_verb_again.php
// RJM Programming
// January, 2015


 $sentenceparts = array(
 "The cheetah", "is", "chasing the antelope.",
 "I", "have", "tidied my bedroom.",
 "We",  "shall",  "go.",
 "Maria", "has", "won the race.",
 "It", "will have been", "in vain if the scheme collapses.",
 "The race", "has been", "won by Maria.",
 "Che", "will", "be eights years old next January.",
 "The teacher", "could", "see that the puzzle caused difficulties for the children.",
 "Space travel", "will be", "very hard to fund into the future.",
 "I regret not", "having had", "the confidence to take more risks.",
 "They", "have", "given their all.",
 '"Prayer', 'does', 'not change God, but it changes him who prays." - Søren Kierkegaard',
 "They", "do", "beneficial jobs for the community.",
 "Those people", "did", "see what happened.",
 "The world", "is", "a small place, seen from space.",
 "The main actress", "has had", "a costume change.",
 "", "Do", "you believe in ghosts?",
 "You", "may", "leave the room.",
 '"Purity of heart', 'is', 'to will one thing." - Søren Kierkegaard',
 "Air travel", "was", "impossible in the Middle Ages.",
 "Several dogs", "are", "playing in the park.",
 "Work", "can be", "very dull.",
 '"Take away paradox from the thinker and you', 'have', 'a professor." - Søren Kierkegaard',
 "Thorough planning", "would have been", "a good idea.",
 "The scope of the problem", "must be", "seen in context.",
 "The job", "might have been", "easier with clear instructions.",
 "Airline passengers", "must", "wear seatbelts during takeoff and landing.",
 "They", "were being", "very quiet during the class.",
 "The cyclone", "may", "cross the coast tonight.",
 "", "May", "I see you home?",
 "The student", "does", "homework after school.",
 "I", "can", "carry that box by myself.",
 "I", "am", "very angry at people who act selfishly.",
 "", "Can", "you drive a car?",
 '', 'Might', 'I borrow your ruler?',
 "The rain", "may", "spoil the event.",
 "She", "has had", "many peanuts out of that bowl.",
 "The accident", "might", "have been worse.",
 "We", "shall", "see what happens next.",
 "Sarah", "should have", "won the race."
);

$wordpick = rand(0, (sizeof($sentenceparts) - 1));
if (isset($_GET['wpick'])) {
  $wordpick = $_GET['wpick'];
} else if (isset($_GET['spick'])) {
  $wordpick = $_GET['spick'] * 3;
}
$sentencepick = ($wordpick - ($wordpick % 3)) / 3; 


$score = 0;
$goes = 0;

if (isset($_GET['score'])) $score = $_GET['score'];
if (isset($_GET['goes'])) $goes = $_GET['goes'];
if (isset($_POST['score'])) $score = $_POST['score'];
if (isset($_POST['goes'])) $goes = $_POST['goes'];

$sbit = "";
$mbit = "";
$ebit = "";
$lmr = "left";

if (($wordpick % 3) == 0) {
  $ebit = " " . $sentenceparts[$sentencepick * 3 + 1] . " " . urldecode($sentenceparts[$sentencepick * 3 + 2]);
  $lmr = "left";
} else if (($wordpick % 3) == 1) {
  $sbit = urldecode($sentenceparts[$sentencepick * 3 + 0]) . " ";
  $ebit = " " . urldecode($sentenceparts[$sentencepick * 3 + 2]);
  $lmr = "center";
} else {
  $sbit = urldecode($sentenceparts[$sentencepick * 3 + 0]) . " " . urldecode($sentenceparts[$sentencepick * 3 + 1]) . " ";
  $lmr = "right";
}

$selbit = "<select style='text-align:" . $lmr . ";' onchange=' goes=goes + 1; if (this.value == \"\") { alert(\"Correct answer is ... " . $sentenceparts[$wordpick] . "\"); } else { score=score+1;  } location.href=\"./auxiliary_verb_again.php?score=\" + score + \"&goes=\" + goes; ' id='myps'><option value='  '>...</option>";

for ($i=0; $i<sizeof($sentenceparts); $i++) {
  if ($i == $wordpick || $sentenceparts[$i] == $sentenceparts[$wordpick]) {
   if ($sentenceparts[$i] == "") {
    $selbit .= "<option value='" . $sentenceparts[$i] . " '>" . $sentenceparts[$i] . "</option>";
   } else {
    $selbit .= "<option value='" . $sentenceparts[$i] . "'>" . $sentenceparts[$i] . "</option>";
   }
  } else {
   $selbit .= "<option value=''>" . $sentenceparts[$i] . "</option>";
  }
}

$selbit .= "</select>";

$cols = array('lime','black','blue','purple','navy','teal','fuchsia','olive','maroon','gray','green');
$colpick = rand(0, (sizeof($cols) - 1));
$mycol = $cols[$colpick];

echo "
<html>
<head>
<meta charset='UTF-8'>
<title>Canvas HTML Element Auxiliary Verb Board Game Tutorial ... RJM Programming ... January 2015 ... thanks to http://stackoverflow.com/questions/9880279/how-do-i-add-a-simple-onclick-event-handler-to-a-canvas-element</title>
<link href='//www.rjmprogramming.com.au/PHP/emboss_h1.css' rel='stylesheet' type='text/css'>

<style> 
#myh1:before {
    content: 'Canvas HTML Element Auxiliary Verb Board Game Tutorial';
}
 
#myh1:after {
    content: '';
}
 
#myh2:before {
    content: 'RJM Programming ... January 2015';
}
 
#myh2:after {
    content: '';
}
 
#myp:before {
    content: '" . $sbit . $mbit . "';
}
 
#myp:after {
    content: '" . $mbit . $ebit . "';
}
 
#myh3:before {
    content: '';
}
 
#myh4:before {
    content: 'Score: " . $score . " Goes: " . $goes . "';
}
 
#myh3:after {
    content: '';
}
 
#myh4:after {
    content: '';
}
</style>
<script language='JavaScript'>

 var score=" . $score . ";
 var goes=" . $goes . ";
 var pseudo_sentence='" . str_replace("......", "...", (str_replace("~", "", str_replace("~~", "...", ("~" . $sbit . "~"))) .  str_replace("~", "", str_replace("~~", "...", ("~" . $mbit . "~"))) .  str_replace("~", "", str_replace("~~", "...", ("~" . $ebit . "~"))))) . "';
";
?>


    // Thanks to A Shorter Guide to English Usage by M.A. Ramsay p.34
    // Thanks to http://www.brainyquote.com/quotes/authors/s/soren_kierkegaard.html


var sentenceparts = new Array(
 "The cheetah", "is", "chasing the antelope.",
 "I", "have", "tidied my bedroom.",
 "We",  "shall",  "go.",
 "Maria", "has", "won the race.",
 "It", "will have been", "in vain if the scheme collapses.",
 "The race", "has been", "won by Maria.",
 "Che", "will", "be eights years old next January.",
 "The teacher", "could", "see that the puzzle caused difficulties for the children.",
 "Space travel", "will be", "very hard to fund into the future.",
 "I regret not", "having had", "the confidence to take more risks.",
 "They", "have", "given their all.",
 '"Prayer', 'does', 'not change God, but it changes him who prays." - Søren Kierkegaard',
 "They", "do", "beneficial jobs for the community.",
 "Those people", "did", "see what happened.",
 "The world", "is", "a small place, seen from space.",
 "The main actress", "has had", "a costume change.",
 "", "Do", "you believe in ghosts?",
 "You", "may", "leave the room.",
 '"Purity of heart', 'is', 'to will one thing." - Søren Kierkegaard',
 "Air travel", "was", "impossible in the Middle Ages.",
 "Several dogs", "are", "playing in the park.",
 "Work", "can be", "very dull.",
 '"Take away paradox from the thinker and you', 'have', 'a professor." - Søren Kierkegaard',
 "Thorough planning", "would have been", "a good idea.",
 "The scope of the problem", "must be", "seen in context.",
 "The job", "might have been", "easier with clear instructions.",
 "Airline passengers", "must", "wear seatbelts during takeoff and landing.",
 "They", "were being", "very quiet during the class.",
 "The cyclone", "may", "cross the coast tonight.",
 "", "May", "I see you home?",
 "The student", "does", "homework after school.",
 "I", "can", "carry that box by myself.",
 "I", "am", "very angry at people who act selfishly.",
 "", "Can", "you drive a car?",
 '', 'Might', 'I borrow your ruler?',
 "The rain", "may", "spoil the event.",
 "She", "has had", "many peanuts out of that bowl.",
 "The accident", "might", "have been worse.",
 "We", "shall", "see what happens next.",
 "Sarah", "should have", "won the race."
);
 
 var wordpick = (location.search.split('wpick=')[1] ? location.search.split('wpick=')[1].split('&')[0] : Math.floor((Math.random()*sentenceparts.length)+0));
 var sentencepick = (location.search.split('spick=')[1] ? location.search.split('spick=')[1].split('&')[0] : ((wordpick - (wordpick % 3)) / 3));
 
 </script>
 
</head>

<body style='background-color:yellow;' onload=' var elem = document.getElementById("canvaselement"); var context = elem.getContext("2d"); context.font = "22px Verdana"; context.strokeText(pseudo_sentence.replace("&#248;", "ø"),30,30);  '>
<div align='center'>
<h1 id='myh1'></h1>
<h2 id='myh2'></h2>
<h3 id='myh3'></h3>
<h4 id='myh4'></h4>
<p id='myp'><?php echo $selbit; ?></p>
<canvas onclick='location.href="./auxiliary_verb_again.php?score=" + score + "&goes=" + goes;' style='border: 5px solid green; background-color: <?php echo $mycol; ?>; opacity: 0.8;' title='Click for your next sentence to solve' id="canvaselement" width="1350" height="400" style="border: 1px solid green;" />
</div>
</body>
 </html>
 
