Login   Register  
PHP Classes
elePHPant
Icontem

File: example_en.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Murat Atay  >  Mine Checker  >  example_en.php  >  Download  
File: example_en.php
Role: Example script
Content type: text/plain
Description: English Example Page
Class: Mine Checker
Web based minesweeper game
Author: By
Last change:
Date: 2005-08-01 08:36
Size: 4,306 bytes
 

Contents

Class file image Download
<?php
require('minechecker.php');
session_start();

$minechecker = new minechecker();

if (isset(
$_GET['new'])) {session_unset('area');}

if (!isset(
$_SESSION['area']))
{
    
$minechecker->newarea(1055);
    
$_SESSION['area'] = $minechecker->area;
}
else
{
    
$minechecker->loadarea($_SESSION['area']);

    if (isset(
$_GET['x']) && isset($_GET['y']))
    {
            if (isset(
$_GET['flag'])) $minechecker->flagarea($_GET['x'], $_GET['y']);
            else 
$minechecker->openarea($_GET['x'], $_GET['y']);
            
$_SESSION['area'] = $minechecker->area;
            if (
$minechecker->status) {session_unset('area');}
    }

    if (isset(
$_GET['check'])) {$minechecker->wincheck();}
}
?>
<style type="text/css">
a {font-family: Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#00F;}
a:hover {color:#00FF00;}
.info {font-family: Verdana, Arial, Helvetica, sans-serif; font-size:10px; border: 1px solid #000;}
.area {border-collapse:collapse;}
.opened {width:25px; height:25px; border:1px solid #000; background-color:#FFF; text-align:center;}
.closed {width:25px; height:25px; border:1px solid #000; background-color:#999; text-align:center;}
.flaged {width:25px; height:25px; border:1px solid #000; background-color:#F00; text-align:center;}
.mined {width:25px; height:25px; border:1px solid #000; background-color:#000; text-align:center;}
.light {background-color:#FC3; text-align:center;}
</style>
<script language="javascript">
var $clicked = <?=$minechecker->status;?>;

function light($ref, $color)
{
    if ($color) $ref.className = 'light';
    else $ref.className = 'closed';
}
function openarea($x, $y)
{
    if (!$clicked)
    {
        $clicked = -1;
        document.location.href = 'example_en.php?x=' + $x + '&y=' + $y;
        return false;
    }
    return false;
}
function flagarea($x, $y)
{
    if (!$clicked)
    {
        $clicked = -1;
        document.location.href = 'example_en.php?flag=-1&x=' + $x + '&y=' + $y;
        return false;
    }
    return false;
}
function noright()
{
    return false;
}
</script>
<a href="example_en.php?new">New Game</a> <a href="example_en.php?check">Win Check<br></a>
<br>
<?=($minechecker->status == 1) ? '<font color="#FF0000">You Win</font><br><br>' '';?>
<?=
($minechecker->status == -1) ? '<font color="#FF0000">You Loose</font><br><br>' '';?>
<table class="area">
<?php for ($i 1$i <= $minechecker->height$i++) { ?>
<tr>
<?php for ($j 1$j <= $minechecker->width$j++) { ?>
<td class="closed"><?=$minechecker->area[$i][$j];?></td>
<?php ?>
</tr>
<?php ?>
</table>
<br>
<table class="area">
<?php for ($i 1$i <= $minechecker->height$i++) { ?>
<tr>
<?php for ($j 1$j <= $minechecker->width$j++) { ?>
<?php 
if ($minechecker->area[$i][$j] < 0) { ?>
<td class="<?=(abs($minechecker->area[$i][$j] % 10) == 9) ? 'mined' 'opened';?>" oncontextmenu="return noright();"><?=abs($minechecker->area[$i][$j] % 10);?></td>
<?php } elseif ($minechecker->area[$i][$j] >= 10) { ?>
<td class="flaged" oncontextmenu="return flagarea(<?=$j;?><?=$i;?>);"></td>
<?php } else { ?>
<td class="closed" onMouseOver="light(this, -1);" onMouseOut="light(this, 0);" onClick="return openarea(<?=$j;?><?=$i;?>);" oncontextmenu="return flagarea(<?=$j;?><?=$i;?>);"></td>
<?php ?>
<?php 
?>
</tr>
<?php ?>
</table>
<br>
<table class="info">
<tr><td>0:</td><td>Closed</td><td>Box with no bombs around.</td></tr>
<tr><td>1 to 8:</td><td>Closed</td><td>Number of bombs around the box.</td></tr>
<tr><td>9:</td><td>Closed</td><td>Mine box</td></tr>
<tr><td colspan="3" style="border-top:1px solid #000;">&nbsp;</td></tr>
<tr><td>-10:</td><td>Opened</td><td>Box with no bombs around.</td></tr>
<tr><td>-1 to -8:</td><td>Opened</td><td>Number of bombs around the box.</td></tr>
<tr><td>-9:</td><td>Opened</td><td>Mine box</td></tr>
<tr><td colspan="3" style="border-top:1px solid #000;">&nbsp;</td></tr>
<tr><td>100:</td><td>Flaged</td><td>Box with no bombs around.</td></tr>
<tr><td>10 to 80:</td><td>Flaged</td><td>Number of bombs around the box.</td></tr>
<tr><td>90:</td><td>Flaged</td><td>Mine box</td></tr>
<tr><td colspan="3" style="border-top:1px solid #000;">&nbsp;</td></tr>
<tr><td colspan="2">Left Click:</td><td>Open box</td></tr>
<tr><td colspan="2">Right Click:</td><td>Flag / UnFlag box</td></tr>
</table>