<?php
    
include('games.php');



    
$good=0;
    for (
$i=0$i<sizeof($gamelist); $i++) {
    if (
$_POST["g$i"] != "") {
        
$nm "res$i"
        $
$nm $_POST["g$i"];
        
#session_register("res$i");
            
$_SESSION["res$i"]="res$i";
    } else { 
        
$nm "res$i"
        $
$nm $_SESSION["res$i"];
    }
    
#if (preg_match("/".$gamelist[$i][1]."/i", $_POST["g$i"])) {
    
if (preg_match("/".$gamelist[$i][1]."/i", $$nm)) {
        
$good++; 
    }
    }

    print 
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";

?>

<html><head><title>Videogame Quizz</title>
<link rel="stylesheet" type="text/css" href="style.css" title="" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head><body>


<h1>Videogame Quizz</h1>

Little hint: only games I played.<br>
Source <a href="sources/">files</a> of this quizz.<br>
<a href="highscores.php">High scores</a><br>
<?php
    
if ($good<sizeof($gamelist)) {
    print 
"<h2>Score : $good/".sizeof($gamelist)."</h2>";
    } else {
    print 
"<h2>VICTORY!!!</h2>\n";
    }
?>
<form method="post">
<table>
<?php

    
for ($i=0$i<sizeof($gamelist); $i++) {

    if (
$i%!= 1) {
        print 
"<tr>\n";
    }
    print 
"  <td><img src=game$i.png></td>";
    
$nm "res$i";
    if (
preg_match("/".$gamelist[$i][1]."/i", $$nm)) {
        print 
"<td>$i : <input type=\"hidden\" name=\"g$i\" ".
        
"value=\"".$gamelist[$i][0]."\">".
        
$gamelist[$i][0]."</td>\n";
    } else {
        print 
"<td>$i : <input type=\"text\" name=\"g$i\" ".
        
"value=\"".$$nm."\"></td>\n";
    }
    if (
$i%== 1) {
        print 
"</tr>\n";
    }
    }
?>
</table>
<input type="submit" value="go">
</form>
<?php
    
if ($good<sizeof($gamelist)) {
    print 
"<h2>Score : $good/".sizeof($gamelist)."</h2>";
    } else {
    print 
"<h2>VICTORY!!!</h2>\n";
    }
?>
<hr>

<form method="post" action="register.php">
Ok, let me come in high-scores.<br>
My name: <input type="text" name="user" value="">
<input type="hidden" name="score" value="<?=$good?>">
<input type="submit" value="go">
</form>

<hr>

</body>
</html>