$l = 0; } reset_game($l); Header("Location: " . BASEPAGE); exit; } else { if ("stop" == $_action) { $name = isset($_SESSION[S_NAME]['name']) ? $_SESSION[S_NAME]['name'] : "Anonymous"; $_SESSION[S_NAME] = array(); $_SESSION[S_NAME]['name'] = $name; Header("Location: " . BASEPAGE); exit; } else { if ("newlevel" == $_action && isset($_GET['newlevel'])) { if (isset($pusher[$_GET['newlevel']])) { reset_game($_GET['newlevel']); } Header("Location: " . BASEPAGE); exit; } else { if ("move" == $_action && isset($_POST['to'], $_POST['to'][0], $_POST['to'][1])) { $_pusher = $_SESSION[S_NAME]['pusher']; $_coords = $_POST['to']; if ($_coords[1] == $_pusher[1] && $_coords[0] + 1 == $_pusher[0]) { // UP $dx1 = -1; $dx2 = -2; $dy1 = 0; $dy2 = 0; } else { if ($_coords[1] == $_pusher[1] && $_coords[0] - 1 == $_pusher[0]) {
<?php // Pixelus define('S_NAME', 'pxl'); $g_arrLevels = array(1 => array('map' => array('xxx xx', 'o x', 'x x', 'x x', 'x o', 'xoxxx '), 'stones' => 3), 2 => array('map' => array(' xx', ' xxx', ' xxx x ', ' ox x', ' o x', ' o x', 'o xx x', 'x x x', 'x x', 'x x', 'x o', ' oox x ', ' ox x ', ' xxxxx '), 'stones' => 8), 3 => array('map' => array(' xx ', ' x x ', ' xx x x ', ' x o x x ', 'o x x x ', 'x x x ', ' x x ', ' oo xx ', ' o o', ' x o', ' x xx x ', ' x x xxx ', ' x x x ', ' xxx x ', ' x ', ' xx '), 'stones' => 7), 4 => array('map' => array(' xxxo ', ' x o ', ' x o ', ' x x o ', ' x x x ', 'x x x', 'x x x', 'x xx x x', 'x x xx', 'x x x', ' x x ', ' x x ', ' x x ', ' xxxx '), 'stones' => 4), 5 => array('map' => array(' oooo ', ' ooo o ', ' x oo o ', ' x x o ', ' x x o ', ' x x x xx ', 'xx x xx xxxx ', ' xxxxxxxx x ', ' xxxxxxxxx ', ' xx ', ' x '), 'stones' => 13), 6 => array('map' => array(' xxo ', ' ox x o ', 'x xxxxxx o ', 'x x ', ' o x ', ' x x ', ' o o o ', ' o x ', ' x x ', ' x xx ', ' oxx xx ', ' xxxxxxxx '), 'stones' => 10), 7 => array('map' => array(' x ', ' x x ', ' x x', ' xxxxxxxxx xx ', ' x x ', 'x x x ', 'x x xxxxx x ', 'x xxx xxx ', ' oo o oo o ', ' o o o o ', ' o o x'), 'stones' => 12), 8 => array('map' => array(' xxxxx ', ' xx ox ', ' o o ', ' x x ', 'x x x', 'x x x', 'x xx x', 'x x', 'x x x', 'x x x ', ' x x ', ' o oo ', ' oxxxxx '), 'stones' => 7), 9 => array('map' => array(' xx ', ' xx x x oo ', ' xoxx xx o ', ' o o ', 'xxxx xxx x ', ' xx xx x xxx ', ' x xxx x', ' o xx ', ' x oxx xx x ', ' x o x x x x ', ' x x x x x ', ' x x xx ', ' x '), 'stones' => 8), 10 => array('map' => array(' x ', 'oxxxxxxxxxxox ', ' ', ' xxxxoxx', ' ', ' ', ' ', ' xx o ', ' xxxxxxxxxx x ', ' oo x ', 'o x x ', ' xxxxxxx x ', ' xxxxxxxxxo '), 'stones' => 8), 11 => array('map' => array(' o ', ' o ', ' o ', ' o o o ', ' x x x x o ', ' x x x x x x o', ' x x x x x x x ', ' x x x x x x x ', 'x x xx x x xx ', 'x x x x x x x ', 'x x x x x x x '), 'stones' => 8), 12 => array('map' => array(' xxxx ', ' xx x ', ' xxx xxx ', ' xxxxx x xxx', 'xxxx x ', ' xx x xxxx', ' xxx x ', ' xx x ', ' o o ', ' o o ', ' oo o ', ' oo xxx', ' oo ', ' oo ', ' o '), 'stones' => 14), 13 => array('map' => array(' xxx ooo ', ' x x x x ', ' xx xo xx ', 'xxx xxx ', 'xxx x ', ' xx ', ' o o xx ', ' xx ', ' xx ', ' xx ', ' ox ', ' x ox ', ' ox oxxx', ' x ', ' x '), 'stones' => 10)); /** START GAME **/ if (isset($_REQUEST['get_map'])) { $level = (int) $_REQUEST['get_map']; if (!isset($g_arrLevels[$level])) { exit('Invalid level [' . $level . ']'); } $arrLevel = $g_arrLevels[$level]; reset_game($level); exit(json_encode(array('level' => $_SESSION[S_NAME]['level'], 'map' => $_SESSION[S_NAME]['map'], 'stones' => $_SESSION[S_NAME]['stones']))); } ?> <!doctype html> <html lang="en"> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, maximum-scale=1.0, minimum-scale=1.0" /> <meta charset="utf-8" /> <title>Pixelus</title> <link rel="stylesheet" href="games.css" /> <style> #loading { border:medium none; height:100px; left:50%; margin-left:-50px; margin-top:-50px; position:absolute; top:50%; visibility:hidden; width:100px; } #map-container span { display: block; height:100%; width: 100%; border-radius: 50px; } #map-container td.target { background-color:#87cefa; } #map-table #map-container td.stone span { background-color: #8b4513; } #map-table #map-container td.valid { background-color:green; } #map-table #map-container td.invalid { background-color:red; }
if (empty($_SESSION[S_NAME])) { reset_game($eerste_level); } /** RESET **/ if ('reset' === $_action) { $_SESSION[S_NAME] = null; reset_game($eerste_level); header('Location: ' . BASEPAGE); exit; } else { if ('get_maps' === $_action) { if (!isset($_POST['level'], $g_arrLevels[(int) $_POST['level']])) { exit(json_encode(array('error' => true))); } $arrLevel = $g_arrLevels[(int) $_POST['level']]; reset_game((int) $_POST['level']); exit(json_encode(array('level' => $_SESSION[S_NAME]['level'], 'map' => $arrLevel['map'], 'pusher' => $arrLevel['pusher'], 'boxes' => $arrLevel['boxes']))); } else { if ("move" == $_action && isset($_POST['dir'], $_POST['level'])) { if (!isset($g_arrLevels[$_POST['level']])) { exit('Invalid level!'); } $arrLevel = $g_arrLevels[$_POST['level']]; $arrDirs = explode(',', $_POST['dir']); foreach ($arrLevel['map'] as $szLine) { $arrLine = array(); for ($i = 0; $i < strlen($szLine); $i++) { $szField = substr($szLine, $i, 1); $arrLine[] = new BoxField('x' === $szField, false, 't' === $szField); } $arrMap[] = $arrLine;
} /** RESET **/ if ('reset' === $_action) { $_SESSION[S_NAME] = null; reset_game($eerste_level); header('Location: ' . BASEPAGE); exit; } else { if ('get_maps' == $_action) { if (!isset($_POST['level'], $g_arrLevels[$_POST['level']])) { $iLevel = 0; } else { $iLevel = $_POST['level']; } $arrLevel = $g_arrLevels[$iLevel]; reset_game($iLevel); exit(json_encode(array('level' => $iLevel, 'map' => $arrLevel['map'], 'pusher' => $arrLevel['pusher'], 'boxes' => $arrLevel['boxes']))); } else { if ("move" == $_action && isset($_POST['dir'], $_POST['level'])) { if (!isset($g_arrLevels[$_POST['level']])) { exit('Invalid level!'); } $arrLevel = $g_arrLevels[$_POST['level']]; $arrDirs = explode(',', $_POST['dir']); foreach ($arrLevel['map'] as $szLine) { $arrLine = array(); for ($i = 0; $i < strlen($szLine); $i++) { $szField = substr($szLine, $i, 1); $arrLine[] = new BoxField('x' === $szField, false, 't' === $szField); } $arrMap[] = $arrLine;