<?php
if ($user->getRoom() == 403) {
    $s = db::c()->query('SELECT * FROM podzem2 WHERE name= "?s"', $mir['name'])->fetch_assoc();

    $rooms[0] = "";
    // характеристики комнат
    $rhar = [];
    $vector = 0;
    $rhar['01'] = [$s["v1"], $s["p1"], $s["n1"], $s["l1"]];
    $rhar['02'] = [$s["v2"], $s["p2"], $s["n2"], $s["l2"]];
    $rhar['03'] = [$s["v3"], $s["p3"], $s["n3"], $s["l3"]];
    $rhar['04'] = [$s["v4"], $s["p4"], $s["n4"], $s["l4"]];
    $rhar['05'] = [$s["v5"], $s["p5"], $s["n5"], $s["l5"]];
    $rhar['06'] = [$s["v6"], $s["p6"], $s["n6"], $s["l6"]];
    $rhar['07'] = [$s["v7"], $s["p7"], $s["n7"], $s["l7"]];
    $rhar['08'] = [$s["v8"], $s["p8"], $s["n8"], $s["l8"]];
    $rhar['09'] = [$s["v9"], $s["p9"], $s["n9"], $s["l9"]];


    $rhar['11'] = [$s["v11"], $s["p11"], $s["n11"], $s["l11"]];
    $rhar['12'] = [$s["v12"], $s["p12"], $s["n12"], $s["l12"]];
    $rhar['13'] = [$s["v13"], $s["p13"], $s["n13"], $s["l13"]];
    $rhar['14'] = [$s["v14"], $s["p14"], $s["n14"], $s["l14"]];
    $rhar['15'] = [$s["v15"], $s["p15"], $s["n15"], $s["l15"]];
    $rhar['16'] = [$s["v16"], $s["p16"], $s["n16"], $s["l16"]];
    $rhar['17'] = [$s["v17"], $s["p17"], $s["n17"], $s["l17"]];
    $rhar['18'] = [$s["v18"], $s["p18"], $s["n18"], $s["l18"]];
    $rhar['19'] = [$s["v19"], $s["p19"], $s["n19"], $s["l19"]];

    $rhar['21'] = [$s["v21"], $s["p21"], $s["n21"], $s["l21"]];
    $rhar['22'] = [$s["v22"], $s["p22"], $s["n22"], $s["l22"]];
    $rhar['23'] = [$s["v23"], $s["p23"], $s["n23"], $s["l23"]];
    $rhar['24'] = [$s["v24"], $s["p24"], $s["n24"], $s["l24"]];
    $rhar['25'] = [$s["v25"], $s["p25"], $s["n25"], $s["l25"]];
    $rhar['26'] = [$s["v26"], $s["p26"], $s["n26"], $s["l26"]];
    $rhar['27'] = [$s["v27"], $s["p27"], $s["n27"], $s["l27"]];
    $rhar['28'] = [$s["v28"], $s["p28"], $s["n28"], $s["l28"]];
    $rhar['29'] = [$s["v29"], $s["p29"], $s["n29"], $s["l29"]];

    $rhar['31'] = [$s["v31"], $s["p31"], $s["n31"], $s["l31"]];
    $rhar['32'] = [$s["v32"], $s["p32"], $s["n32"], $s["l32"]];
    $rhar['33'] = [$s["v33"], $s["p33"], $s["n33"], $s["l33"]];
    $rhar['34'] = [$s["v34"], $s["p34"], $s["n34"], $s["l34"]];
    $rhar['35'] = [$s["v35"], $s["p35"], $s["n35"], $s["l35"]];
    $rhar['36'] = [$s["v36"], $s["p36"], $s["n36"], $s["l36"]];
    $rhar['37'] = [$s["v37"], $s["p37"], $s["n37"], $s["l37"]];
    $rhar['38'] = [$s["v38"], $s["p38"], $s["n38"], $s["l38"]];
    $rhar['39'] = [$s["v39"], $s["p39"], $s["n39"], $s["l39"]];

    $rhar['41'] = [$s["v41"], $s["p41"], $s["n41"], $s["l41"]];
    $rhar['42'] = [$s["v42"], $s["p42"], $s["n42"], $s["l42"]];
    $rhar['43'] = [$s["v43"], $s["p43"], $s["n43"], $s["l43"]];
    $rhar['44'] = [$s["v44"], $s["p44"], $s["n44"], $s["l44"]];
    $rhar['45'] = [$s["v45"], $s["p45"], $s["n45"], $s["l45"]];
    $rhar['46'] = [$s["v46"], $s["p46"], $s["n46"], $s["l46"]];
    $rhar['47'] = [$s["v47"], $s["p47"], $s["n47"], $s["l47"]];
    $rhar['48'] = [$s["v48"], $s["p48"], $s["n48"], $s["l48"]];
    $rhar['49'] = [$s["v49"], $s["p49"], $s["n49"], $s["l49"]];

    $rhar['51'] = [$s["v51"], $s["p51"], $s["n51"], $s["l51"]];
    $rhar['52'] = [$s["v52"], $s["p52"], $s["n52"], $s["l52"]];
    $rhar['53'] = [$s["v53"], $s["p53"], $s["n53"], $s["l53"]];
    $rhar['54'] = [$s["v54"], $s["p54"], $s["n54"], $s["l54"]];
    $rhar['55'] = [$s["v55"], $s["p55"], $s["n55"], $s["l55"]];
    $rhar['56'] = [$s["v56"], $s["p56"], $s["n56"], $s["l56"]];
    $rhar['57'] = [$s["v57"], $s["p57"], $s["n57"], $s["l57"]];
    $rhar['58'] = [$s["v58"], $s["p58"], $s["n58"], $s["l58"]];
    $rhar['59'] = [$s["v59"], $s["p59"], $s["n59"], $s["l59"]];

    $rhar['61'] = [$s["v61"], $s["p61"], $s["n61"], $s["l61"]];
    $rhar['62'] = [$s["v62"], $s["p62"], $s["n62"], $s["l62"]];
    $rhar['63'] = [$s["v63"], $s["p63"], $s["n63"], $s["l63"]];
    $rhar['64'] = [$s["v64"], $s["p64"], $s["n64"], $s["l64"]];
    $rhar['65'] = [$s["v65"], $s["p65"], $s["n65"], $s["l65"]];
    $rhar['66'] = [$s["v66"], $s["p66"], $s["n66"], $s["l66"]];
    $rhar['67'] = [$s["v67"], $s["p67"], $s["n67"], $s["l67"]];
    $rhar['68'] = [$s["v68"], $s["p68"], $s["n68"], $s["l68"]];
    $rhar['69'] = [$s["v69"], $s["p69"], $s["n69"], $s["l69"]];

    $rhar['71'] = [$s["v71"], $s["p71"], $s["n71"], $s["l71"]];
    $rhar['72'] = [$s["v72"], $s["p72"], $s["n72"], $s["l72"]];
    $rhar['73'] = [$s["v73"], $s["p73"], $s["n73"], $s["l73"]];
    $rhar['74'] = [$s["v74"], $s["p74"], $s["n74"], $s["l74"]];
    $rhar['75'] = [$s["v75"], $s["p75"], $s["n75"], $s["l75"]];
    $rhar['76'] = [$s["v76"], $s["p76"], $s["n76"], $s["l76"]];
    $rhar['77'] = [$s["v77"], $s["p77"], $s["n77"], $s["l77"]];
    $rhar['78'] = [$s["v78"], $s["p78"], $s["n78"], $s["l78"]];
    $rhar['79'] = [$s["v79"], $s["p79"], $s["n79"], $s["l79"]];

    $rhar['81'] = [$s["v81"], $s["p81"], $s["n81"], $s["l81"]];
    $rhar['82'] = [$s["v82"], $s["p82"], $s["n82"], $s["l82"]];
    $rhar['83'] = [$s["v83"], $s["p83"], $s["n83"], $s["l83"]];
    $rhar['84'] = [$s["v84"], $s["p84"], $s["n84"], $s["l84"]];
    $rhar['85'] = [$s["v85"], $s["p85"], $s["n85"], $s["l85"]];
    $rhar['86'] = [$s["v86"], $s["p86"], $s["n86"], $s["l86"]];
    $rhar['87'] = [$s["v87"], $s["p87"], $s["n87"], $s["l87"]];
    $rhar['88'] = [$s["v88"], $s["p88"], $s["n88"], $s["l88"]];
    $rhar['89'] = [$s["v89"], $s["p89"], $s["n89"], $s["l89"]];

    $rhar['91'] = [$s["v91"], $s["p91"], $s["n91"], $s["l91"]];
    $rhar['92'] = [$s["v92"], $s["p92"], $s["n92"], $s["l92"]];
    $rhar['93'] = [$s["v93"], $s["p93"], $s["n93"], $s["l93"]];
    $rhar['94'] = [$s["v94"], $s["p94"], $s["n94"], $s["l94"]];
    $rhar['95'] = [$s["v95"], $s["p95"], $s["n95"], $s["l95"]];
    $rhar['96'] = [$s["v96"], $s["p96"], $s["n96"], $s["l96"]];
    $rhar['97'] = [$s["v97"], $s["p97"], $s["n97"], $s["l97"]];
    $rhar['98'] = [$s["v98"], $s["p98"], $s["n98"], $s["l98"]];
    $rhar['99'] = [$s["v99"], $s["p99"], $s["n99"], $s["l99"]];


    function build_move_image($location, $vector, $styles)
    {
        $step1 = next_step($location, $vector);
        if ($step1['fwd']) {
            $step2 = next_step($step1['fwd'], $vector);
        }
        if (!empty($step2['fwd'])) {
            $step3 = next_step($step2['fwd'], $vector);
        }
        if (!empty($step3['fwd'])) {
            $step4 = next_step($step3['fwd'], $vector);
        } else {
            $step4['fwd'] = false;
        }
        $s = '';

        if (!$step4['left']) {
            $s .= '<div style="position:absolute; left:11px; top:10px;"><img src="labirint3/' . $styles . '/ln4.gif" width="352" height="240" title="Этаж 1 - Канализация"></div>';
        }
        if ($step4['left']) {
            $s .= '<div style="position:absolute; left:11px; top:10px;"><img src="labirint3/' . $styles . '/ly4.gif" width="352" height="240" title="Этаж 1 - Канализация"></div>';
        }
        if ($step4['right']) {
            $s .= '<div style="position:absolute; left:11px; top:10px;"><img src="labirint3/' . $styles . '/ry4.gif" width="352" height="240" title="Этаж 1 - Канализация"></div>';
        }
        if (!$step4['right']) {
            $s .= '<div style="position:absolute; left:11px; top:10px;"><img src="labirint3/' . $styles . '/rn4.gif" width="352" height="240" title="Этаж 1 - Канализация"></div>';
        }

        if (!$step3['right']) {
            $s .= '<div style="position:absolute; left:11px; top:10px;"><img src="labirint3/' . $styles . '/rn3.gif" width="352" height="240" title="Этаж 1 - Канализация"></div>';
        }
        if ($step3['right']) {
            $s .= '<div style="position:absolute; left:11px; top:10px;"><img src="labirint3/' . $styles . '/ry3.gif" width="352" height="240" title="Этаж 1 - Канализация"></div>';
        }
        if ($step3['left']) {
            $s .= '<div style="position:absolute; left:11px; top:10px;"><img src="labirint3/' . $styles . '/ly3.gif" width="352" height="240" title="Этаж 1 - Канализация"></div>';
        }
        if (!$step3['left']) {
            $s .= '<div style="position:absolute; left:11px; top:10px;"><img src="labirint3/' . $styles . '/ln3.gif" width="352" height="240" title="Этаж 1 - Канализация"></div>';
        }

        if (!$step2['right']) {
            $s .= '<div style="position:absolute; left:11px; top:10px;"><img src="labirint3/' . $styles . '/rn2.gif" width="352" height="240" title="Этаж 1 - Канализация"></div>';
        }
        if ($step2['right']) {
            $s .= '<div style="position:absolute; left:11px; top:10px;"><img src="labirint3/' . $styles . '/ry2.gif" width="352" height="240" title="Этаж 1 - Канализация"></div>';
        }
        if ($step2['left']) {
            $s .= '<div style="position:absolute; left:11px; top:10px;"><img src="labirint3/' . $styles . '/ly2.gif" width="352" height="240" title="Этаж 1 - Канализация"></div>';
        }
        if (!$step2['left']) {
            $s .= '<div style="position:absolute; left:11px; top:10px;"><img src="labirint3/' . $styles . '/ln2.gif" width="352" height="240" title="Этаж 1 - Канализация"></div>';
        }

        if (!$step1['right']) {
            $s .= '<div style="position:absolute; left:11px; top:10px;"><img src="labirint3/' . $styles . '/rn1.gif" width="352" height="240" title="Этаж 1 - Канализация"></div>';
        }
        if ($step1['right']) {
            $s .= '<div style="position:absolute; left:11px; top:10px;"><img src="labirint3/' . $styles . '/ry1.gif" width="352" height="240" title="Этаж 1 - Канализация"></div>';
        }
        if ($step1['left']) {
            $s .= '<div style="position:absolute; left:11px; top:10px;"><img src="labirint3/' . $styles . '/ly1.gif" width="352" height="240" alt="Этаж 1 - Канализация"></div>';
        }
        if (!$step1['left']) {
            $s .= '<div style="position:absolute; left:11px; top:10px;"><img src="labirint3/' . $styles . '/ln1.gif" width="352" height="240" alt="Этаж 1 - Канализация"></div>';
        }

///////stenq////////
        if (!$step4['fwd']) {
            $s .= '<div style="position:absolute; left:11px; top:10px;"><img src="labirint3/' . $styles . '/cy3.gif" width="352" height="240" title="Этаж 1 - Канализация"></div>';
        }
        if (!$step3['fwd']) {
            $s .= '<div style="position:absolute; left:11px; top:10px;"><img src="labirint3/' . $styles . '/cn3.gif" width="352" height="240" title="Этаж 1 - Канализация"></div>';
        }
        if (!$step2['fwd']) {
            $s .= '<div style="position:absolute; left:11px; top:10px;"><img src="labirint3/' . $styles . '/cn2.gif" width="352" height="240" title="Этаж 1 - Канализация"></div>';
        }
        if (!$step1['fwd']) {
            $s .= '<div style="position:absolute; left:11px; top:10px;"><img src="labirint3/' . $styles . '/cn1.gif" width="352" height="240" title="Этаж 1 - Канализация"></div>';
        }


        $rs = mysql_query("select * from labirint where user_id='" . $_SESSION['uid'] . "'");
        $t = mysql_fetch_array($rs);

        /*
         ///Удаляем убитых ботов с локации

          // Узнаем номер ледующей локи(где проводилась зачистка)
          $apol = mysql_fetch_array(mysql_query("SELECT * FROM `labirint` WHERE glava='$glava' and name='".$t['name']."'"));
          $comment1 = "лабиринт".$apol['boi'];

          //Ищем бой, проверяем кто победил
          $apol1 = mysql_fetch_array(mysql_query("SELECT * FROM `battle` WHERE coment='{$comment1}' and timeout='3'"));

          //Если победил мобов, то убираем их из таблицы лабиринт
          if($apol1['win']=='1') {
         mysql_query("UPDATE podzem3 SET `n".$apol['boi']."` = '' WHERE glava = '{$glava}' LIMIT 2");
          }       */


        $f = mysql_query("SELECT * FROM podzem3 WHERE glava='$glava' and name='" . $t['name'] . "'");
        while ($rt = mysql_fetch_array($f)) {

            if ($vector == '0') {
                $loc4 = $location + 30;
            }
            if ($vector == '0') {
                $loc3 = $location + 20;
            }
            if ($vector == '0') {
                $loc2 = $location + 10;
            }

            if ($vector == '180') {
                $loc4 = $location - 30;
            }
            if ($vector == '180') {
                $loc3 = $location - 20;
            }
            if ($vector == '180') {
                $loc2 = $location - 10;
            }

            if ($vector == '90') {
                $loc4 = $location + 3;
            }
            if ($vector == '90') {
                $loc3 = $location + 2;
            }
            if ($vector == '90') {
                $loc2 = $location + 1;
            }

            if ($vector == '270') {
                $loc4 = $location - 3;
            }
            if ($vector == '270') {
                $loc3 = $location - 2;
            }
            if ($vector == '270') {
                $loc2 = $location - 1;
            }

            $mesto = $location;
            if ($location == '01') {
                $mesto = '1';
            }
            if ($location == '02') {
                $mesto = '2';
            }
            if ($location == '03') {
                $mesto = '3';
            }
            if ($location == '04') {
                $mesto = '4';
            }
            if ($location == '05') {
                $mesto = '5';
            }
            if ($location == '06') {
                $mesto = '6';
            }
            if ($location == '07') {
                $mesto = '7';
            }
            if ($location == '08') {
                $mesto = '8';
            }
            if ($location == '09') {
                $mesto = '9';
            }

            include "podzem/raschet_bot.php";

////////////////////////////////////////////////
            $fd = mysql_query("SELECT * FROM podzem4 WHERE glava='$glava' and name='" . $t['name'] . "'");
            $repa = mysql_fetch_array($fd);
//////////////Объекты////////////////
            if ($repa["n$mesto"] == '20') {
                mysql_query("UPDATE `users`,`online` SET `users`.`room` = '404',`online`.`room` = '404' WHERE `online`.`id` = `users`.`id` AND `online`.`id` = '{$_SESSION['uid']}' ;");
                print "<script>location.href='main.php?act=none'</script>";
                exit;
            }
///////

//Вход на 2ой этаж
            if ($repa["n$loc2"] == 'et2' and $vector == $repa["v$loc2"]) {
                $s .= '<div style="position:absolute; left:150px; top:165px;"><a href="?act=et2"><img src="labirint3/stok.gif" width="65" border="0" height="15" title="Спуск на нижний ярус"></a></div>';
            }
//Вход на 1ый этаж
            if ($repa["n$loc2"] == 'et1' and $vector == $repa["v$loc2"]) {
                $s .= '<div style="position:absolute; left:150px; top:50px;"><a href="?act=et1"><img src="labirint3/lestnica.gif" width="65" border="0" height="120" title="Подъем на верхний ярус"></a></div>';
            }

            if ($repa["n$loc2"] == '20' and $vector == $repa["v$loc2"]) {
                $s .= '<div style="position:absolute; left:60px; top:34px;"><img src="labirint3/sclad.gif" width="255" border="0" height="172" alt="Бывший скад мартына."></div>';
            }
            if ($repa["n$loc3"] == '20' and $vector == $repa["v$loc3"]) {
                $s .= '<div style="position:absolute; left:107px; top:55px;"><img src="labirint3/sclad2.jpg" width="162" border="0" height="110" alt="Бывший скад мартына."></div>';
            }
            if ($repa["n$loc4"] == '20' and $vector == $repa["v$loc4"]) {
                $s .= '<div style="position:absolute; left:130px; top:66px;"><img src="labirint3/sclad3.jpg" width="117" border="0" height="80" alt="Бывший скад мартына."></div>';
            }
            if ($repa["n$loc2"] == 'el' and $vector == $repa["v$loc2"]) {
                $s .= '<div style="position:absolute; left:150px; top:115px;"><a href="?act=el"><img src="labirint3/zel.gif" width="80" border="0" height="80" alt="Зелье"></a></div>';
            }
            if ($repa["n$loc3"] == 'el' and $vector == $repa["v$loc3"]) {
                $s .= '<div style="position:absolute; left:165px; top:115px;"><img src="labirint3/zel.gif" width="50" border="0" height="50" alt="Зелье"></div>';
            }
            if (($repa["n$mesto"] == '11.1' or $repa["n$mesto"] == '11.0') and $vector == $repa["v$mesto"]) {
                $s .= '<div onmouseout="closeMenu();" style="position:absolute; left:180px; top:165px;"><img src="labirint3/1/kanal.gif" width="40" height="40" border="0" alt="Водосток" style="CURSOR:pointer;" onClick="stok(' . $mesto . ')"></div>';
            }
            if (($repa["n$loc2"] == '11.1' or $repa["n$loc2"] == '11.0') and $vector == $repa["v$loc2"]) {
                $s .= '<div  style="position:absolute; left:180px; top:140px;"><img src="labirint3/1/kanal.gif" width="25" height="25" border="0" alt="Водосток"></div>';
            }
            if (($repa["n$loc3"] == '11.1' or $repa["n$loc3"] == '11.0') and $vector == $repa["v$loc3"]) {
                $s .= '<div  style="position:absolute; left:182px; top:130px;"><img src="labirint3/1/kanal.gif" width="15" height="15" border="0" alt="Водосток"></div>';
            }
            if (($repa["n$loc4"] == '11.1' or $repa["n$loc4"] == '11.0') and $vector == $repa["v$loc4"]) {
                $s .= '<div  style="position:absolute; left:182px; top:125px;"><img src="labirint3/1/kanal.gif" width="10" height="10" border="0" alt="Водосток"></div>';
            }
/////////////
            if (($repa["n$loc2"] == '12.1' or $repa["n$loc2"] == '12.0') and $vector == $repa["v$loc2"]) {
                $s .= '<div onmouseout="closeMenu();" style="position:absolute; left:160px; top:170px;"><img src="labirint3/1/stok.gif" width="60" height="15" border="0" alt="Водосток" style="CURSOR:pointer;" onClick="stok2(' . $loc2 . ')"></div>';
            }
            if (($repa["n$loc3"] == '12.1' or $repa["n$loc3"] == '12.0') and $vector == $repa["v$loc3"]) {
                $s .= '<div  style="position:absolute; left:175px; top:150px;"><img src="labirint3/1/stok.gif" width="40" height="8" border="0" alt="Водосток"></div>';
            }
            if (($repa["n$loc4"] == '12.1' or $repa["n$loc4"] == '12.0') and $vector == $repa["v$loc4"]) {
                $s .= '<div  style="position:absolute; left:178px; top:138px;"><img src="labirint3/1/stok.gif" width="20" height="5" border="0" alt="Водосток"></div>';
            }
////////////////klju4i/////////////////////////
            if ($repa["n$mesto"] == 'key1' or $repa["n$loc2"] == 'key1' or $repa["n$loc3"] == 'key1' or $repa["n$loc4"] == 'key1') {
                $nomers = '1';
            }
            if ($repa["n$mesto"] == 'key2' or $repa["n$loc2"] == 'key2' or $repa["n$loc3"] == 'key2' or $repa["n$loc4"] == 'key2') {
                $nomers = '2';
            }
            if ($repa["n$mesto"] == 'key3' or $repa["n$loc2"] == 'key3' or $repa["n$loc3"] == 'key3' or $repa["n$loc4"] == 'key3') {
                $nomers = '3';
            }
            if ($repa["n$mesto"] == 'key4' or $repa["n$loc2"] == 'key4' or $repa["n$loc3"] == 'key4' or $repa["n$loc4"] == 'key4') {
                $nomers = '4';
            }
            if ($repa["n$mesto"] == 'key5' or $repa["n$loc2"] == 'key5' or $repa["n$loc3"] == 'key5' or $repa["n$loc4"] == 'key5') {
                $nomers = '5';
            }
            if ($repa["n$mesto"] == 'key6' or $repa["n$loc2"] == 'key6' or $repa["n$loc3"] == 'key6' or $repa["n$loc4"] == 'key6') {
                $nomers = '6';
            }
            if ($repa["n$mesto"] == 'key7' or $repa["n$loc2"] == 'key7' or $repa["n$loc3"] == 'key7' or $repa["n$loc4"] == 'key7') {
                $nomers = '7';
            }
            if ($repa["n$mesto"] == 'key8' or $repa["n$loc2"] == 'key8' or $repa["n$loc3"] == 'key8' or $repa["n$loc4"] == 'key8') {
                $nomers = '8';
            }
            if ($repa["n$mesto"] == 'key9' or $repa["n$loc2"] == 'key9' or $repa["n$loc3"] == 'key9' or $repa["n$loc4"] == 'key9') {
                $nomers = '9';
            }
            if ($repa["n$mesto"] == 'key10' or $repa["n$loc2"] == 'key10' or $repa["n$loc3"] == 'key10' or $repa["n$loc4"] == 'key10') {
                $nomers = '10';
            }
            if (($repa["n$mesto"] == 'key1' or $repa["n$mesto"] == 'key2' or $repa["n$mesto"] == 'key3' or $repa["n$mesto"] == 'key4' or $repa["n$mesto"] == 'key5' or $repa["n$mesto"] == 'key6' or $repa["n$mesto"] == 'key7' or $repa["n$mesto"] == 'key8' or $repa["n$mesto"] == 'key9' or $repa["n$mesto"] == 'key10') and $vector == $repa["v$mesto"]) {
                $s .= '<div onmouseout="closeMenu();" style="position:absolute; left:160px; top:165px;"><img src="labirint3/' . $repa["n$mesto"] . '.gif" width="60" height="60" border="0" alt="Ключ №' . $nomers . '" style="CURSOR:pointer;" onClick="key(' . $mesto . ',' . $nomers . ')"></div>';
            }
            if (($repa["n$loc2"] == 'key1' or $repa["n$loc2"] == 'key2' or $repa["n$loc2"] == 'key3' or $repa["n$loc2"] == 'key4' or $repa["n$loc2"] == 'key5' or $repa["n$loc2"] == 'key6' or $repa["n$loc2"] == 'key7' or $repa["n$loc2"] == 'key8' or $repa["n$loc2"] == 'key9' or $repa["n$loc2"] == 'key10') and $vector == $repa["v$loc2"]) {
                $s .= '<div  style="position:absolute; left:175px; top:140px;"><img src="labirint3/' . $repa["n$loc2"] . '.gif" width="40" height="40" border="0" alt="Ключ №' . $nomers . '"></div>';
            }
            if ($step2['fwd'] and ($repa["n$loc3"] == 'key1' or $repa["n$loc3"] == 'key2' or $repa["n$loc3"] == 'key3' or $repa["n$loc3"] == 'key4' or $repa["n$loc3"] == 'key5' or $repa["n$loc3"] == 'key6' or $repa["n$loc3"] == 'key7' or $repa["n$loc3"] == 'key8' or $repa["n$loc3"] == 'key9' or $repa["n$loc3"] == 'key10') and $vector == $repa["v$loc3"]) {
                $s .= '<div  style="position:absolute; left:175px; top:130px;"><img src="labirint3/' . $repa["n$loc3"] . '.gif" width="25" height="25" border="0" alt="Ключ №' . $nomers . '"></div>';
            }
            if ($step3['fwd'] and ($repa["n$loc4"] == 'key1' or $repa["n$loc4"] == 'key2' or $repa["n$loc4"] == 'key3' or $repa["n$loc4"] == 'key4' or $repa["n$loc4"] == 'key5' or $repa["n$loc4"] == 'key6' or $repa["n$loc4"] == 'key7' or $repa["n$loc4"] == 'key8' or $repa["n$loc4"] == 'key9' or $repa["n$loc4"] == 'key10') and $vector == $repa["v$loc4"]) {
                $s .= '<div  style="position:absolute; left:182px; top:125px;"><img src="labirint3/' . $repa["n$loc4"] . '.gif" width="15" height="15" border="0" alt="Ключ №' . $nomers . '"></div>';
            }

            if ($step3['fwd'] and ($repa["n$loc4"] == '13.1' or $repa["n$loc4"] == '13.0')) {
                $s .= '<div  style="position:absolute; left:178px; top:120px;"><img src="labirint3/sun.gif" width="25" height="25" border="0" alt="Сундук"></div>';
            }
            if ($step3['fwd'] and ($repa["n$loc4"] == '14.1' or $repa["n$loc4"] == '14.0')) {
                $s .= '<div  style="position:absolute; left:178px; top:120px;"><img src="labirint3/2.gif" width="25" height="25" border="0" alt="Сундук"></div>';
            }
//////////////////////3/////////////////////////
            if ($step3['fwd'] and $rt["n$loc4"] != '') {
                if ($k_b == '1') {
                    $s .= '<div style="position:absolute; left:165px; top:65px;"><img src="labirint3/' . $ob . '.gif" width="50" height="85" title=' . $b_n . '></div>';
                }
                if ($k_b == '2') {
                    $s .= '<div style="position:absolute; left:140px; top:65px;"><img src="labirint3/' . $ob . '.gif" width="50" height="85" title=' . $b_n . '></div>';
                    $s .= '<div style="position:absolute; left:190px; top:65px;"><img src="labirint3/' . $ob2 . '.gif" width="50" height="85" title=' . $b_n2 . '></div>';
                }
                if ($k_b == '3') {
                    $s .= '<div style="position:absolute; left:135px; top:70px;"><img src="labirint3/' . $ob . '.gif" width="50" height="80" title=' . $b_n . '></div>';
                    $s .= '<div style="position:absolute; left:190px; top:70px;"><img src="labirint3/' . $ob3 . '.gif" width="50" height="80" title=' . $b_n3 . '></div>';
                    $s .= '<div style="position:absolute; left:165px; top:80px;"><img src="labirint3/' . $ob2 . '.gif" width="50" height="80" title=' . $b_n2 . '></div>';
                }
            }
            $rogs = mysql_query("SELECT login,location FROM `labirint` WHERE `glava`='$glava'");
            $i = 0;
            while ($mores = mysql_fetch_array($rogs)) {
                $i++;
                $nus = mysql_num_rows($rogs);

                if ($vector == 0) {
                    $lac = $location + 30;
                }
                if ($vector == 90) {
                    $lac = $location + 3;
                }
                if ($vector == 180) {
                    $lac = $location - 30;
                }
                if ($vector == 270) {
                    $lac = $location - 3;
                }
                if ($step3['fwd'] and $lac == $mores['location'] and $nus >= 2) {
                    if ($nus == 2) {
                        $l = '170';
                    }
                    if ($nus == 3) {
                        if ($i == 1) {
                            $l = '140';
                        }
                        if ($i == 2) {
                            $l = '170';
                        }
                        if ($i == 3) {
                            $l = '200';
                        }
                    }
                    if ($nus == 4) {
                        if ($i == 1) {
                            $l = '140';
                        }
                        if ($i == 2) {
                            $l = '160';
                        }
                        if ($i == 3) {
                            $l = '180';
                        }
                        if ($i == 4) {
                            $l = '200';
                        }
                    }
                    $s .= '<div style="position:absolute; left:' . $l . 'px; top:70px;"><img src="labirint3/0.gif" width="35" height="75" title=' . $mores['login'] . '></div>';
                }
            }
            if ($step3['fwd'] and $repa["n$loc4"] >= '1' and $repa["n$loc4"] <= '10') {
                $s .= '<div style="position:absolute; left:124px; top:66px;"><img src="labirint3/rewet.gif" width="122" border="0" height="82" alt="Решетка(нужен ключ №' . $repa["n$loc4"] . ')"></div>';
            }
/////////////////////////////////////////////
            if ($step2['fwd'] and ($repa["n$loc3"] == '13.1' or $repa["n$loc3"] == '13.0')) {
                $s .= '<div  style="position:absolute; left:170px; top:120px;"><img src="labirint3/sun.gif" width="40" height="40" border="0" alt="Сундук"></div>';
            }
            if ($step2['fwd'] and ($repa["n$loc3"] == '14.1' or $repa["n$loc3"] == '14.0')) {
                $s .= '<div  style="position:absolute; left:170px; top:120px;"><img src="labirint3/2.gif" width="40" height="40" border="0" alt="Сундук"></div>';
            }
/////////////////////2///////////////////////
            if ($step2['fwd'] and $rt["n$loc3"] != '') {

                if ($k_b3 == '1') {
                    $s .= '<div style="position:absolute; left:155px; top:60px;"><img src="labirint3/' . $ob3 . '.gif" width="65" height="110" title=' . $b_n3 . '></div>';
                }

                if ($k_b3 == '2') {
                    $s .= '<div style="position:absolute; left:120px; top:60px;"><img src="labirint3/' . $ob3 . '.gif" width="65" height="110" title=' . $b_n3 . '></div>';
                    $s .= '<div style="position:absolute; left:185px; top:60px;"><img src="labirint3/' . $ob32 . '.gif" width="65" height="110" title=' . $b_n32 . '></div>';
                }

                if ($k_b3 == '3') {
                    $s .= '<div style="position:absolute; left:115px; top:60px;"><img src="labirint3/' . $ob3 . '.gif" width="65" height="110" title=' . $b_n3 . '></div>';
                    $s .= '<div style="position:absolute; left:190px; top:60px;"><img src="labirint3/' . $ob33 . '.gif" width="65" height="110" title=' . $b_n33 . '></div>';
                    $s .= '<div style="position:absolute; left:155px; top:70px;"><img src="labirint3/' . $ob32 . '.gif" width="65" height="110" title=' . $b_n32 . '></div>';
                }
            }
            $rogs = mysql_query("SELECT login,location FROM `labirint` WHERE `glava`='$glava'");
            $i = 0;
            while ($mores = mysql_fetch_array($rogs)) {
                $i++;
                $nus = mysql_num_rows($rogs);
                if ($vector == 0) {
                    $lac = $location + 20;
                }
                if ($vector == 90) {
                    $lac = $location + 2;
                }
                if ($vector == 180) {
                    $lac = $location - 20;
                }
                if ($vector == 270) {
                    $lac = $location - 2;
                }
                if ($step2['fwd'] and $lac == $mores['location'] and $nus >= 2) {
                    if ($nus == 2) {
                        $l = '160';
                    }
                    if ($nus == 3) {
                        if ($i == 1) {
                            $l = '130';
                        }
                        if ($i == 2) {
                            $l = '160';
                        }
                        if ($i == 3) {
                            $l = '190';
                        }
                    }
                    if ($nus == 4) {
                        if ($i == 1) {
                            $l = '120';
                        }
                        if ($i == 2) {
                            $l = '150';
                        }
                        if ($i == 3) {
                            $l = '180';
                        }
                        if ($i == 4) {
                            $l = '210';
                        }
                    }
                    $s .= '<div style="position:absolute; left:' . $l . 'px; top:50px;"><img src="labirint3/0.gif" width="50" height="110" title=' . $mores['login'] . '></div>';
                }
            }
            if ($step2['fwd'] and $repa["n$loc3"] >= '1' and $repa["n$loc3"] <= '10') {
                $s .= '<div  style="position:absolute; left:103px; top:50px;"><img src="labirint3/rewet.gif" width="172" border="0" height="120" alt="Решетка(нужен ключ №' . $repa["n$loc3"] . ')"></div>';
                $s .= '<div style="position:absolute; left:124px; top:66px;"><img src="labirint3/rewet.gif" width="122" border="0" height="82" alt="Решетка(нужен ключ №' . $repa["n$loc3"] . ')"></div>';
            }
///////////////////////////////////////////
            if ($step1['fwd'] and ($repa["n$loc2"] == '13.1' or $repa["n$loc2"] == '13.0')) {
                $s .= '<div onmouseout="closeMenu();" style="position:absolute; left:155px; top:130px;"><img src="labirint3/sun.gif" width="60" height="60" border="0" alt="Сундук" style="CURSOR:pointer;" onClick="sunduk(' . $loc2 . ')"></div>';
            }
            if ($step1['fwd'] and ($repa["n$loc2"] == '14.1' or $repa["n$loc2"] == '14.0')) {
                $s .= '<div onmouseout="closeMenu();" style="position:absolute; left:155px; top:130px;"><img src="labirint3/2.gif" width="60" height="60" border="0" alt="Сундук" style="CURSOR:pointer;" onClick="sunduk2(' . $loc2 . ')"></div>';
            }
/////////////////////1/////////////////////

            if ($step1['fwd'] and $rt["n$loc2"] != '') {

                if ($k_b2 == '1') {
                    if ($rt["n$loc2"] == '8') {
                        $s .= '<div onmouseover="closeMenu();" style="position:absolute; left:135px; top:40px;"><img src="labirint3/' . $ob2 . '.gif" width="100" height="160" title=' . $b_n2 . ' style="CURSOR:pointer;" onClick="Opendialog(' . $loc2 . ',event)"></div>';
                    } else {
                        $s .= '<div onmouseover="closeMenu();" style="position:absolute; left:135px; top:40px;"><img src="labirint3/' . $ob2 . '.gif" width="100" height="160" title=' . $b_n2 . ' style="CURSOR:pointer;" onClick="OpenMenu(' . $loc2 . ',event)"></div>';
                    }

                }
                if ($k_b2 == '2') {
                    $s .= '<div onmouseover="closeMenu();" style="position:absolute; left:90px; top:40px;"><img src="labirint3/' . $ob2 . '.gif" width="100" height="160" title=' . $b_n2 . ' style="CURSOR:pointer;" onClick="OpenMenu(' . $loc2 . ',event)"></div>';
                    $s .= '<div onmouseover="closeMenu();" style="position:absolute; left:180px; top:40px;"><img src="labirint3/' . $ob22 . '.gif" width="100" height="160" title=' . $b_n22 . ' style="CURSOR:pointer;" onClick="OpenMenu(' . $loc2 . ',event)"></div>';
                }
                if ($k_b2 == '3') {
                    $s .= '<div onmouseover="closeMenu();" style="position:absolute; left:80px; top:40px;"><img src="labirint3/' . $ob2 . '.gif" width="100" height="160" title=' . $b_n2 . ' style="CURSOR:pointer;" onClick="OpenMenu(' . $loc2 . ',event)"></div>';
                    $s .= '<div onmouseover="closeMenu();" style="position:absolute; left:195px; top:40px;"><img src="labirint3/' . $ob23 . '.gif" width="100" height="160" title=' . $b_n23 . ' style="CURSOR:pointer;" onClick="OpenMenu(' . $loc2 . ',event)"></div>';
                    $s .= '<div onmouseover="closeMenu();" style="position:absolute; left:140px; top:60px;"><img src="labirint3/' . $ob22 . '.gif" width="100" height="160" title=' . $b_n22 . ' style="CURSOR:pointer;" onClick="OpenMenu(' . $loc2 . ',event)"></div>';
                }

            }
            $rogs = mysql_query("SELECT login,location FROM `labirint` WHERE `glava`='$glava'");
            $i = 0;
            while ($mores = mysql_fetch_array($rogs)) {
                $i++;
                $nus = mysql_num_rows($rogs);
                if ($vector == 0) {
                    $lac = $location + 10;
                }
                if ($vector == 90) {
                    $lac = $location + 1;
                }
                if ($vector == 180) {
                    $lac = $location - 10;
                }
                if ($vector == 270) {
                    $lac = $location - 1;
                }
                if ($step1['fwd'] and $lac == $mores['location'] and $nus >= 2) {
                    if ($nus == 2) {
                        $l = '150';
                    }
                    if ($nus == 3) {
                        if ($i == 1) {
                            $l = '90';
                        }
                        if ($i == 2) {
                            $l = '150';
                        }
                        if ($i == 3) {
                            $l = '180';
                        }
                    }
                    if ($nus == 4) {
                        if ($i == 1) {
                            $l = '100';
                        }
                        if ($i == 2) {
                            $l = '140';
                        }
                        if ($i == 3) {
                            $l = '180';
                        }
                        if ($i == 4) {
                            $l = '210';
                        }
                    }
                    $s .= '<div style="position:absolute; left:' . $l . 'px; top:40px;"><img src="labirint3/0.gif" width="75" height="160" title=' . $mores['login'] . '></div>';
                }

            }
////////////////////////////////////////
            if ($step1['fwd'] and $repa["n$loc2"] >= '1' and $repa["n$loc2"] <= '10') {
                $s .= '<div  style="position:absolute; left:50px; top:31px;"><img src="labirint3/rewet.gif" width="265" border="0" height="180" alt="Решетка(нужен ключ №' . $repa["n$loc2"] . ')"></div>';
                $s .= '<div  style="position:absolute; left:103px; top:50px;"><img src="labirint3/rewet.gif" width="172" border="0" height="120" alt="Решетка(нужен ключ №' . $repa["n$loc2"] . ')"></div>';
            }

            $mesto = $location;
            if ($location == '01') {
                $mesto = '1';
            }
            if ($location == '02') {
                $mesto = '2';
            }
            if ($location == '03') {
                $mesto = '3';
            }
            if ($location == '04') {
                $mesto = '4';
            }
            if ($location == '05') {
                $mesto = '5';
            }
            if ($location == '06') {
                $mesto = '6';
            }
            if ($location == '07') {
                $mesto = '7';
            }
            if ($location == '08') {
                $mesto = '8';
            }
            if ($location == '09') {
                $mesto = '9';
            }
//////////////0-ja////////////////
            if ($step1['fwd'] and $repa["n$mesto"] >= '1' and $repa["n$mesto"] <= '10') {
                $s .= '<div  style="position:absolute; left:55px; top:31px;"><img src="labirint3/rewet.gif" width="265" border="0" height="180" alt="Решетка(нужен ключ №' . $repa["n$mesto"] . ')"></div>';
            }


        }

        return $s;
    }

    function next_step($location, $vector)
    {
        global $rhar;
        $row = intval(substr($location, 0, 1));
        $col = intval(substr($location, 1));
        $cell = [];
        // fwd
        $c = $col;
        $r = $row;
        if ($vector == 90) {
            $c = $col + 1;
        } elseif ($vector == 180) {
            $r = $row - 1;
        } elseif ($vector == 270) {
            $c = $col - 1;
        } else {
            $r = $row + 1;
        }
        $cell['fwd'] = $r . $c;
        if ($r > 9 || $r < 0 || $c > 9 || $c < 0 || !in_array($cell['fwd'], $rhar[$location])) {
            $cell['fwd'] = false;
        }

        // left
        $c = $col;
        $r = $row;
        if ($vector == 90) {
            $r = $row + 1;
        } elseif ($vector == 180) {
            $c = $col + 1;
        } elseif ($vector == 270) {
            $r = $row - 1;
        } else {
            $c = $col - 1;
        }
        $cell['left'] = $r . $c;
        if ($r > 9 || $r < 0 || $c > 9 || $c < 0 || !in_array($cell['left'], $rhar[$location])) {
            $cell['left'] = false;
        }
        // right
        $c = $col;
        $r = $row;
        if ($vector == 90) {
            $r = $row - 1;
        } elseif ($vector == 180) {
            $c = $col - 1;
        } elseif ($vector == 270) {
            $r = $row + 1;
        } else {
            $c = $col + 1;
        }
        $cell['right'] = $r . $c;
        if ($r > 9 || $r < 0 || $c > 9 || $c < 0 || !in_array($cell['right'], $rhar[$location])) {
            $cell['right'] = false;
        }
        // back
        $c = $col;
        $r = $row;
        if ($vector == 90) {
            $c = $col - 1;
        } elseif ($vector == 180) {
            $r = $row + 1;
        } elseif ($vector == 270) {
            $c = $col + 1;
        } else {
            $r = $row - 1;
        }

        $cell['back'] = $r . $c;
        if ($r > 9 || $r < 0 || $c > 9 || $c < 0 || !in_array($cell['back'], $rhar[$location])) {
            $cell['back'] = false;
        }
        return $cell;
    }
}