Thread: Your old code?
View Single Post
Old 12-01-2007, 04:40 PM   #15 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Hehe. I found some of my old code. This is a snippet from my Javascript hangman game which is still quite addictive! The RAR file is dated the 12th of Match, 2006, so you can see how far I've come. Without further ado:

(I would edit the DB details, but it's years old anyway.)

php Code:
define('MS_GAME', 'GAME'.substr(rand(99999, 10000).ip2long($_SERVER['REMOTE_ADDR']), 0, 12));
define('MYSQL_USER', 'adam_mine05user');
define('MYSQL_PASS', 'sYi3haVveV39qQ');
define('MYSQL_HOST', 'localhost');
define('MYSQL_DB', 'adam_minesweeper');
ini_set('max_execution_time', '120');

$minesweeperSQL = @mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS) or die('<div style="font-size: 10px; font-family: Tahoma, Verdana, Helvetica">MySQL Server not responding.</div>');
@mysql_select_db(MYSQL_DB) or die('<div style="font-size: 10px; font-family: Tahoma, Verdana, Helvetica">MySQL database "'.MYSQL_DB.'" does not exist.</div>');

if(isset($_GET['records'])) {
    $level = mysql_real_escape_string(strip_tags($_GET['records']));
    $sql = "SELECT rName, rTime FROM `records` WHERE rLevel = '$level' ORDER BY rTime ASC LIMIT 0,10";
    $resultsRS = mysql_query($sql);
    $records = '<table id="records"><tr id="record"><th style="width: 10px"></th><th style="width: 120px">Name</th><th>Time (Seconds)</th>';
    $n = 1;
    while($row = mysql_fetch_array($resultsRS)) {
        $records .= '<tr><td>'.$n.'</td><td>'.$row['rName'].'</td><td>'.$row['rTime'].'</td></tr>';
        $n++;
    }
    $records .= '</tr></table>';
    echo $records;
    mysql_free_result($resultsRS);
    die();
} elseif(isset($_GET['name']) && isset($_GET['seconds'])) {
    function microtime_float() {
        list($usec, $sec) = explode(" ", microtime());
        return ((float)$usec + (float)$sec);
    }
    $time_start = mysql_real_escape_string(strip_tags($_GET['seconds']));
    $time_end = microtime_float();
    $time = $time_end - $time_start;
    $name = substr(mysql_real_escape_string(strip_tags($_GET['name'])), 0, 40);
    $level = mysql_real_escape_string(strip_tags($_GET['level']));
    $level = $_GET['level'];
    setcookie('Minesweeper', $name);
    $sql = "INSERT INTO `records` (rName, rLevel, rTime) VALUES ('$name', '$level', '$time')";
    mysql_query($sql);
} elseif(isset($_GET['cell']) && isset($_GET['game'])) {
    $cell = substr(mysql_real_escape_string($_GET['cell']), 0, 3);
    $game = $_GET['game'];
    $sql = "SELECT `gValue` FROM `game` WHERE gCell = '$cell' AND gID = '$game'";
    $resultsRS = mysql_query($sql);
    $row = mysql_fetch_array($resultsRS);
    if($row == 0) {
        echo $row[0];   
    }
    elseif($row[0] == 'Mine') {
        echo $row[0];
        die()
    } else {
        switch($row[0]) {
            case(1):
                $number = 1;
                $colour = '#5B35FF';
                break;
            case(2):
                $number = 2;
                $colour = '#007103';
                break;
            case(3):
                $number = 3;
                $colour = '#FF3535';
                break;
            case(4):
                $number = 4;
                $colour = '#002B8C';
                break;
            case(5):
                $number = 5;
                $colour = '#910202';
                break;
            case(6):
                $number = 6;
                $colour = '#00A997';
                break;
            case(7):
                $number = 7;
                $colour = '#000000';
                break;
            case(8):
                $number = 8;
                $colour = '#CB9900';
                break;
            default;
                $number = 0;
                $colour = '#000000';
                break;
        }   
    }
    echo '<font color="'.$colour.'">'.$number.'</font>';
    mysql_free_result($resultsRS);
    die();
}

Hopefully I've laid a foundation Don't be shy anybody!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote