JeuWeb - Crée ton jeu par navigateur
Création d'une carte pour mon jeux. - Version imprimable

+- JeuWeb - Crée ton jeu par navigateur (https://jeuweb.org)
+-- Forum : Discussions, Aide, Ressources... (https://jeuweb.org/forumdisplay.php?fid=38)
+--- Forum : Programmation, infrastructure (https://jeuweb.org/forumdisplay.php?fid=51)
+--- Sujet : Création d'une carte pour mon jeux. (/showthread.php?tid=6674)



Création d'une carte pour mon jeux. - Ducky_Duck - 26-02-2013

Bonjour à tous,



Je bloque en ce moment pour la création d'une carte codée en php réunissant 255 carrés de ce style :

[Image: carte.png]

Ma carte actuelle est sous forme de liste et j'aurait aimer la mettre sous forme de carte comme ci-dessus.

Voici à quoi ressemble le code de ma page actuelle :

Code :
<?php


if(!defined('INSIDE')){ die(header("location:../../"));}

include_once($xgp_root . 'includes/classes/class.GalaxyRows.' . $phpEx);

class ShowGalaxyPage extends GalaxyRows
{
    private function InsertGalaxyScripts ($CurrentPlanet)
    {
        $Script  = "<div style=\"top: 10px;\" id=\"content\">";
        $Script .= "<script language=\"JavaScript\">\n";
        $Script .= "function galaxy_submit(value) {\n";
        $Script .= "    document.getElementById('auto').name = value;\n";
        $Script .= "    document.getElementById('galaxy_form').submit();\n";
        $Script .= "}\n\n";
        $Script .= "function fenster(target_url,win_name) {\n";
        $Script .= "    var new_win = window.open(target_url,win_name,'resizable=yes,scrollbars=yes,menubar=no,toolbar=no,width=640,height=480,top=0,left=0');\n";
        $Script .= "    new_win.focus();\n";
        $Script .= "}\n";
        $Script .= "</script>\n";
        $Script .= "<script language=\"JavaScript\" src=\"scripts/tw-sack.js\"></script>\n";
        $Script .= "<script type=\"text/javascript\">\n\n";
        $Script .= "var ajax = new sack();\n";
        $Script .= "var strInfo = \"\";\n";
        $Script .= "function whenResponse () {\n";
        $Script .= "    retVals   = this.response.split(\"|\");\n";
        $Script .= "    Message   = retVals[0];\n";
        $Script .= "    Infos     = retVals[1];\n";
        $Script .= "    retVals   = Infos.split(\" \");\n";
        $Script .= "    UsedSlots = retVals[0];\n";
        $Script .= "    SpyProbes = retVals[1];\n";
        $Script .= "    Recyclers = retVals[2];\n";
        $Script .= "    Missiles  = retVals[3];\n";
        $Script .= "    retVals   = Message.split(\";\");\n";
        $Script .= "    CmdCode   = retVals[0];\n";
        $Script .= "    strInfo   = retVals[1];\n";
        $Script .= "    addToTable(\"done\", \"success\");\n";
        $Script .= "    changeSlots( UsedSlots );\n";
        $Script .= "    setShips(\"probes\", SpyProbes );\n";
        $Script .= "    setShips(\"recyclers\", Recyclers );\n";
        $Script .= "    setShips(\"missiles\", Missiles );\n";
        $Script .= "}\n\n";
        $Script .= "function doit (order, galaxy, system, planet, planettype, shipcount) {\n";
        $Script .= "    ajax.requestFile = \"FleetAjax.php?action=send\";\n";
        $Script .= "    ajax.runResponse = whenResponse;\n";
        $Script .= "    ajax.execute = true;\n\n";
        $Script .= "    ajax.setVar(\"thisgalaxy\", ". $CurrentPlanet["galaxy"] .");\n";
        $Script .= "    ajax.setVar(\"thissystem\", ". $CurrentPlanet["system"] .");\n";
        $Script .= "    ajax.setVar(\"thisplanet\", ". $CurrentPlanet["planet"] .");\n";
        $Script .= "    ajax.setVar(\"thisplanettype\", ". $CurrentPlanet["planet_type"] .");\n";
        $Script .= "    ajax.setVar(\"mission\", order);\n";
        $Script .= "    ajax.setVar(\"galaxy\", galaxy);\n";
        $Script .= "    ajax.setVar(\"system\", system);\n";
        $Script .= "    ajax.setVar(\"planet\", planet);\n";
        $Script .= "    ajax.setVar(\"planettype\", planettype);\n";
        $Script .= "    if (order == 6)\n";
        $Script .= "        ajax.setVar(\"ship210\", shipcount);\n";
        $Script .= "    if (order == 7) {\n";
        $Script .= "        ajax.setVar(\"ship208\", 1);\n\n";
        $Script .= "        ajax.setVar(\"ship203\", 2);\n\n";
        $Script .= "    }\n";
        $Script .= "    if (order == 8)\n";
        $Script .= "        ajax.setVar(\"ship209\", shipcount);\n\n";
        $Script .= "    ajax.runAJAX();\n";
        $Script .= "}\n\n";
        $Script .= "function addToTable(strDataResult, strClass) {\n";
        $Script .= "    var e = document.getElementById('fleetstatusrow');\n";
        $Script .= "    var e2 = document.getElementById('fleetstatustable');\n";
        $Script .= "    e.style.display = '';\n";
        $Script .= "    if(e2.rows.length > 2) {\n";
        $Script .= "        e2.deleteRow(2);\n";
        $Script .= "    }\n";
        $Script .= "    var row = e2.insertRow(0);\n";
        $Script .= "    var td1 = document.createElement(\"td\");\n";
        $Script .= "    var td1text = document.createTextNode(strInfo);\n";
        $Script .= "    td1.appendChild(td1text);\n";
        $Script .= "    var td2 = document.createElement(\"td\");\n";
        $Script .= "    var span = document.createElement(\"span\");\n";
        $Script .= "    var spantext = document.createTextNode(strDataResult);\n";
        $Script .= "    var spanclass = document.createAttribute(\"class\");\n";
        $Script .= "    spanclass.nodeValue = strClass;\n";
        $Script .= "    span.setAttributeNode(spanclass);\n";
        $Script .= "    span.appendChild(spantext);\n";
        $Script .= "    td2.appendChild(span);\n";
        $Script .= "    row.appendChild(td1);\n";
        $Script .= "    row.appendChild(td2);\n";
        $Script .= "}\n\n";
        $Script .= "function changeSlots(slotsInUse) {\n";
        $Script .= "    var e = document.getElementById('slots');\n";
        $Script .= "    e.innerHTML = slotsInUse;\n";
        $Script .= "}\n\n";
        $Script .= "function setShips(ship, count) {\n";
        $Script .= "    var e = document.getElementById(ship);\n";
        $Script .= "    e.innerHTML = count;\n";
        $Script .= "}\n";
        $Script .= "</script>\n";

        return $Script;
    }
    
    private function ShowGalaxyRows($Galaxy, $System, $HavePhalanx, $CurrentGalaxy, $CurrentSystem, $CurrentRC, $CurrentMIP)
    {
        global $planetcount, $dpath, $user, $xgp_root, $phpEx;

        $UserPoints    = doquery("SELECT * FROM {{table}} WHERE `stat_type` = '1' AND `stat_code` = '1' AND `id_owner` = '". intval($user['id']) ."';", 'statpoints', true);

        $Result = "";
        for ($Planet = 1; $Planet < 1+(MAX_PLANET_IN_SYSTEM); $Planet++)
        {
            unset($GalaxyRowPlanet);
            unset($GalaxyRowMoon);
            unset($GalaxyRowPlayer);
            unset($GalaxyRowAlly);

            $GalaxyRow = doquery("SELECT * FROM {{table}} WHERE `galaxy` = '".$Galaxy."' AND `system` = '".$System."' AND `planet` = '".$Planet."';", 'galaxy', true);

            $Result .= "\n";
            $Result .= "<tr>";

            if ($GalaxyRow)
            {
                if ($GalaxyRow["id_planet"] != 0)
                {
                    $GalaxyRowPlanet = doquery("SELECT * FROM {{table}} WHERE `id` = '". $GalaxyRow["id_planet"] ."';", 'planets', true);

                    if ($GalaxyRowPlanet['destruyed'] != 0 && $GalaxyRowPlanet['id_owner'] != '' && $GalaxyRow["id_planet"] != '')
                    {
                        $this->CheckAbandonPlanetState ($GalaxyRowPlanet);
                    }
                    else
                    {
                        $planetcount++;
                        $GalaxyRowPlayer = doquery("SELECT * FROM {{table}} WHERE `id` = '". $GalaxyRowPlanet["id_owner"] ."';", 'users', true);
                    }

                    if ($GalaxyRow["id_luna"] != 0)
                    {
                        $GalaxyRowMoon   = doquery("SELECT * FROM {{table}} WHERE `id` = '". $GalaxyRow["id_luna"] ."' AND planet_type='3';", 'planets', true);

                        if ($GalaxyRowMoon["destruyed"] != 0)
                        {
                            $this->CheckAbandonMoonState ($GalaxyRowMoon);
                        }
                    }

                    if ($GalaxyRowPlanet['id_owner'] <> 0)
                        $GalaxyRowUser     = doquery("SELECT * FROM {{table}} WHERE `id` = '". $GalaxyRowPlanet['id_owner'] ."';", 'users', true);
                    else
                        $GalaxyRowUser     = array();

                }
            }

            $Result .= $this->GalaxyRowPos        ( $GalaxyRow, $Galaxy, $System, $Planet, 1 );
            $Result .= $this->GalaxyRowPlanet     ( $GalaxyRow, $GalaxyRowPlanet, $GalaxyRowPlayer, $Galaxy, $System, $Planet, 1, $HavePhalanx, $CurrentGalaxy, $CurrentSystem);
            $Result .= $this->GalaxyRowPlanetName ( $GalaxyRow, $GalaxyRowPlanet, $GalaxyRowPlayer, $Galaxy, $System, $Planet, 1, $HavePhalanx, $CurrentGalaxy, $CurrentSystem);
            $Result .= $this->GalaxyRowUser       ( $GalaxyRow, $GalaxyRowPlanet, $GalaxyRowPlayer, $Galaxy, $System, $Planet, 0, $UserPoints );
            $Result .= $this->GalaxyRowAlly       ( $GalaxyRow, $GalaxyRowPlanet, $GalaxyRowPlayer, $Galaxy, $System, $Planet, 0 );
            $Result .= $this->GalaxyRowActions    ( $GalaxyRow, $GalaxyRowPlanet, $GalaxyRowPlayer, $Galaxy, $System, $Planet, 0, $CurrentGalaxy, $CurrentSystem, $CurrentMIP);
            $Result .= "</tr>";
        }
        return $Result;
    }


    private function showNormal($CurrentUser, $CurrentPlanet)
  {
        global $xgp_root, $phpEx, $dpath, $resource, $lang, $planetcount;

        $fleetmax          = ($CurrentUser['computer_tech'] + 1) + ($CurrentUser['rpg_commandant'] * COMMANDANT);
        $CurrentPlID       = $CurrentPlanet['id'];
        $CurrentMIP        = $CurrentPlanet['interplanetary_misil'];
        $CurrentRC         = $CurrentPlanet['recycler'];
        $CurrentSP         = $CurrentPlanet['spy_sonde'];
        $HavePhalanx       = $CurrentPlanet['phalanx'];
        $CurrentSystem     = $CurrentPlanet['system'];
        $CurrentGalaxy     = $CurrentPlanet['galaxy'];
        $CanDestroy        = $CurrentPlanet[$resource[213]] + $CurrentPlanet[$resource[214]];

        $maxfleet       = doquery("SELECT * FROM {{table}} WHERE `fleet_owner` = '". intval($CurrentUser['id']) ."';", 'fleets');
        $maxfleet_count = mysql_num_rows($maxfleet);

        if (!isset($mode))
        {
            if (isset($_GET['mode']))
            {
                $mode = intval($_GET['mode']);
            }
            else
            {
                $mode = 0;
            }
        }

        if ($mode == 0)
        {
            $galaxy        = $CurrentPlanet['galaxy'];
            $system        = $CurrentPlanet['system'];
            $planet        = $CurrentPlanet['planet'];
        }
        elseif ($mode == 1)
        {
            if (intval($_POST["galaxy"]))
            {
                $_POST["galaxy"] = ereg_replace("[^0-9]","",$_POST["galaxy"]);
            }
            else
            {
                $_POST["galaxy"] = 1;
            }

            if (intval($_POST["system"]))
            {
                $_POST["system"] = ereg_replace("[^0-9]","",$_POST["system"]);
            }
            else
            {
                $_POST["system"] = 1;
            }

            if ($_POST["galaxy"] > MAX_GALAXY_IN_WORLD)
                $_POST["galaxy"] = MAX_GALAXY_IN_WORLD;

            if ($_POST["system"] > MAX_SYSTEM_IN_GALAXY)
                $_POST["system"] = MAX_SYSTEM_IN_GALAXY;

            if ($_POST["galaxyLeft"])
            {
                if ($_POST["galaxy"] < 1)
                {
                    $_POST["galaxy"] = 1;
                    $galaxy          = 1;
                }
                elseif ($_POST["galaxy"] == 1)
                {
                    $_POST["galaxy"] = 1;
                    $galaxy          = 1;
                }
                else
                {
                    $galaxy = $_POST["galaxy"] - 1;
                }
            }
            elseif ($_POST["galaxyRight"])
            {
                if ($_POST["galaxy"] > MAX_GALAXY_IN_WORLD OR $_POST["galaxyRight"] > MAX_GALAXY_IN_WORLD)
                {
                    $_POST["galaxy"]      = MAX_GALAXY_IN_WORLD;
                    $_POST["galaxyRight"] = MAX_GALAXY_IN_WORLD;
                    $galaxy               = MAX_GALAXY_IN_WORLD;
                }
                elseif ($_POST["galaxy"] == MAX_GALAXY_IN_WORLD)
                {
                    $_POST["galaxy"]      = MAX_GALAXY_IN_WORLD;
                    $galaxy               = MAX_GALAXY_IN_WORLD;
                }
                else
                {
                    $galaxy = $_POST["galaxy"] + 1;
                }
            }
            else
            {
                $galaxy = $_POST["galaxy"];
            }

            if ($_POST["systemLeft"])
            {
                if ($_POST["system"] < 1)
                {
                    $_POST["system"] = 1;
                    $system          = 1;
                }
                elseif ($_POST["system"] == 1)
                {
                    $_POST["system"] = 1;
                    $system          = 1;
                }
                else
                {
                    $system = $_POST["system"] - 1;
                }
            }
            elseif ($_POST["systemRight"])
            {
                if ($_POST["system"]      > MAX_SYSTEM_IN_GALAXY OR $_POST["systemRight"] > MAX_SYSTEM_IN_GALAXY)
                {
                    $_POST["system"]      = MAX_SYSTEM_IN_GALAXY;
                    $system               = MAX_SYSTEM_IN_GALAXY;
                }
                elseif ($_POST["system"] == MAX_SYSTEM_IN_GALAXY)
                {
                    $_POST["system"]      = MAX_SYSTEM_IN_GALAXY;
                    $system               = MAX_SYSTEM_IN_GALAXY;
                }
                else
                {
                    $system = $_POST["system"] + 1;
                }
            }
            else
            {
                $system = $_POST["system"];
            }
        }
        elseif ($mode == 2)
        {
            $galaxy        = intval($_GET['galaxy']);
            $system        = intval($_GET['system']);
            $planet        = intval($_GET['planet']);
        }
        elseif ($mode == 3)
        {
            $galaxy        = intval($_GET['galaxy']);
            $system        = intval($_GET['system']);
        }
        else
        {
            $galaxy        = 1;
            $system        = 1;
        }

        if ( ( $CurrentPlanet['system'] != ( $_POST["system"] - 1 ) ) && ( $mode != 0 ) && ( $CurrentPlanet['deuterium'] < 10 ) )
        {
            die (message($lang['gl_no_deuterium_to_view_galaxy'], "game.php?page=galaxy&mode=0", 2));
        }
        elseif( ( $CurrentPlanet['system'] != ( $_POST["system"] - 1 ) ) && ( $mode != 0 ) )
        {
            $QryGalaxyDeuterium   = "UPDATE {{table}} SET ";
            $QryGalaxyDeuterium  .= "`deuterium` = `deuterium` -  10 ";
            $QryGalaxyDeuterium  .= "WHERE ";
            $QryGalaxyDeuterium  .= "`id` = '". $CurrentPlanet['id'] ."' ";
            $QryGalaxyDeuterium  .= "LIMIT 1;";
            doquery($QryGalaxyDeuterium, 'planets');
        }

        $planetcount = 0;
        $lunacount   = 0;

        $parse                        = $lang;
        $parse['galaxy']            = $galaxy;
        $parse['system']            = $system;
        $parse['planet']            = $planet;
        $parse['currentmip']        = $CurrentMIP;
        $parse['maxfleetcount']        = $maxfleet_count;
        $parse['fleetmax']            = $fleetmax;
        $parse['recyclers']           = pretty_number($CurrentRC);
        $parse['spyprobes']           = pretty_number($CurrentSP);
        $parse['missile_count']        = sprintf($lang['gl_missil_to_launch'], $CurrentMIP);
        $parse['current']            = $_GET['current'];
        $parse['current_galaxy']    = $CurrentPlanet["galaxy"];
        $parse['current_system']    = $CurrentPlanet["system"];
        $parse['current_planet']    = $CurrentPlanet["planet"];
        $parse['planet_type']         = $CurrentPlanet["planet_type"];

        $page['galaxyscripts']        = $this->InsertGalaxyScripts ($CurrentPlanet);
        $page['galaxyselector']        = parsetemplate(gettemplate('galaxy/galaxy_selector'), $parse);
        ($mode == 2) ? $page['mip'] = parsetemplate(gettemplate('galaxy/galaxy_missile_selector'), $parse) : " ";
        $page['galaxytitles']         = parsetemplate(gettemplate('galaxy/galaxy_titles'), $parse);
        $page['galaxyrows']         = $this->ShowGalaxyRows   ($galaxy, $system, $HavePhalanx, $CurrentGalaxy, $CurrentSystem, $CurrentRC, $CurrentMIP);

        $parse['planetcount']         = $planetcount ." ". $lang['gl_populed_planets'];

        $page['galaxyfooter']         = parsetemplate(gettemplate('galaxy/galaxy_footer'), $parse);

        return display(parsetemplate(gettemplate('galaxy/galaxy_body'), $page), false);
    }
    
        public function __construct($CurrentUser, $CurrentPlanet)
    {
       $galaxyMode=$CurrentUser['galaxyMode'];
       if($galaxyMode=="2D"){
       $this->show2D($CurrentUser, $CurrentPlanet);
       }
       else{
     $this->showNormal($CurrentUser, $CurrentPlanet);
     }
    }
    
    private function InsertGalaxyScripts2D ($CurrentPlanet)
    {
        $Script .= "<div style=\"top: 10px;\" id=\"content\">";
        $Script .= "<script language=\"JavaScript\">\n";
        $Script .= "function galaxy_submit(value) {\n";
        $Script .= "    document.getElementById('auto').name = value;\n";
        $Script .= "    document.getElementById('galaxy_form').submit();\n";
        $Script .= "}\n\n";
        $Script .= "function fenster(target_url,win_name) {\n";
        $Script .= "    var new_win = window.open(target_url,win_name,'resizable=yes,scrollbars=yes,menubar=no,toolbar=no,width=640,height=480,top=0,left=0');\n";
        $Script .= "    new_win.focus();\n";
        $Script .= "}\n";
        $Script .= "</script>\n";
        $Script .= "<script language=\"JavaScript\" src=\"scripts/tw-sack.js\"></script>\n";
        $Script .= "<script type=\"text/javascript\">\n\n";
        $Script .= "var ajax = new sack();\n";
        $Script .= "var strInfo = \"\";\n";
        $Script .= "function whenResponse () {\n";
        $Script .= "    retVals   = this.response.split(\"|\");\n";
        $Script .= "    Message   = retVals[0];\n";
        $Script .= "    Infos     = retVals[1];\n";
        $Script .= "    retVals   = Infos.split(\" \");\n";
        $Script .= "    UsedSlots = retVals[0];\n";
        $Script .= "    SpyProbes = retVals[1];\n";
        $Script .= "    Recyclers = retVals[2];\n";
        $Script .= "    Missiles  = retVals[3];\n";
        $Script .= "    retVals   = Message.split(\";\");\n";
        $Script .= "    CmdCode   = retVals[0];\n";
        $Script .= "    strInfo   = retVals[1];\n";
        $Script .= "    addToTable(\"done\", \"success\");\n";
        $Script .= "    changeSlots( UsedSlots );\n";
        $Script .= "    setShips(\"probes\", SpyProbes );\n";
        $Script .= "    setShips(\"recyclers\", Recyclers );\n";
        $Script .= "    setShips(\"missiles\", Missiles );\n";
        $Script .= "}\n\n";
        $Script .= "function doit (order, galaxy, system, planet, planettype, shipcount) {\n";
        $Script .= "    ajax.requestFile = \"FleetAjax.php?action=send\";\n";
        $Script .= "    ajax.runResponse = whenResponse;\n";
        $Script .= "    ajax.execute = true;\n\n";
        $Script .= "    ajax.setVar(\"thisgalaxy\", ". $CurrentPlanet["galaxy"] .");\n";
        $Script .= "    ajax.setVar(\"thissystem\", ". $CurrentPlanet["system"] .");\n";
        $Script .= "    ajax.setVar(\"thisplanet\", ". $CurrentPlanet["planet"] .");\n";
        $Script .= "    ajax.setVar(\"thisplanettype\", ". $CurrentPlanet["planet_type"] .");\n";
        $Script .= "    ajax.setVar(\"mission\", order);\n";
        $Script .= "    ajax.setVar(\"galaxy\", galaxy);\n";
        $Script .= "    ajax.setVar(\"system\", system);\n";
        $Script .= "    ajax.setVar(\"planet\", planet);\n";
        $Script .= "    ajax.setVar(\"planettype\", planettype);\n";
        $Script .= "    if (order == 6)\n";
        $Script .= "        ajax.setVar(\"ship210\", shipcount);\n";
        $Script .= "    if (order == 7) {\n";
        $Script .= "        ajax.setVar(\"ship208\", 1);\n\n";
        $Script .= "        ajax.setVar(\"ship203\", 2);\n\n";
        $Script .= "    }\n";
        $Script .= "    if (order == 8)\n";
        $Script .= "        ajax.setVar(\"ship209\", shipcount);\n\n";
        $Script .= "    ajax.runAJAX();\n";
        $Script .= "}\n\n";
        $Script .= "function addToTable(strDataResult, strClass) {\n";
        $Script .= "    var e = document.getElementById('fleetstatusrow');\n";
        $Script .= "    var e2 = document.getElementById('fleetstatustable');\n";
        $Script .= "    e.style.display = '';\n";
        $Script .= "    if(e2.rows.length > 2) {\n";
        $Script .= "        e2.deleteRow(2);\n";
        $Script .= "    }\n";
        $Script .= "    var row = e2.insertRow(0);\n";
        $Script .= "    var td1 = document.createElement(\"td\");\n";
        $Script .= "    var td1text = document.createTextNode(strInfo);\n";
        $Script .= "    td1.appendChild(td1text);\n";
        $Script .= "    var td2 = document.createElement(\"td\");\n";
        $Script .= "    var span = document.createElement(\"span\");\n";
        $Script .= "    var spantext = document.createTextNode(strDataResult);\n";
        $Script .= "    var spanclass = document.createAttribute(\"class\");\n";
        $Script .= "    spanclass.nodeValue = strClass;\n";
        $Script .= "    span.setAttributeNode(spanclass);\n";
        $Script .= "    span.appendChild(spantext);\n";
        $Script .= "    td2.appendChild(span);\n";
        $Script .= "    row.appendChild(td1);\n";
        $Script .= "    row.appendChild(td2);\n";
        $Script .= "}\n\n";
        $Script .= "function changeSlots(slotsInUse) {\n";
        $Script .= "    var e = document.getElementById('slots');\n";
        $Script .= "    e.innerHTML = slotsInUse;\n";
        $Script .= "}\n\n";
        $Script .= "function setShips(ship, count) {\n";
        $Script .= "    var e = document.getElementById(ship);\n";
        $Script .= "    e.innerHTML = count;\n";
        $Script .= "}\n";
        $Script .= "</script>\n";

        return $Script;
    }
    private function ShowGalaxyRows2D($Galaxy, $System, $HavePhalanx, $CurrentGalaxy, $CurrentSystem, $CurrentRC, $CurrentMIP)
    {
        global $planetcount, $dpath, $user, $xgp_root, $phpEx, $PlanetRow;

        $UserPoints    = doquery("SELECT * FROM {{table}} WHERE `stat_type` = '1' AND `stat_code` = '1' AND `id_owner` = '". $user['id'] ."';", 'statpoints', true);

        $Result = "";
        for ($Planet = 1; $Planet < 1+(MAX_PLANET_IN_SYSTEM); $Planet++)
        {
            unset($GalaxyRowPlanet);
            unset($GalaxyRowMoon);
            unset($GalaxyRowPlayer);
            unset($GalaxyRowAlly);

            $GalaxyRow = doquery("SELECT * FROM {{table}} WHERE `galaxy` = '".$Galaxy."' AND `system` = '".$System."' AND `planet` = '".$Planet."';", 'galaxy', true);

            $Result .= "\n";
            $Result .= "<tr>";

            if ($GalaxyRow)
            {
                if ($GalaxyRow["id_planet"] != 0)
                {
                    $GalaxyRowPlanet = doquery("SELECT * FROM {{table}} WHERE `id` = '". $GalaxyRow["id_planet"] ."';", 'planets', true);

                    if ($GalaxyRowPlanet['destruyed'] != 0 && $GalaxyRowPlanet['id_owner'] != '' && $GalaxyRow["id_planet"] != '')
                    {
                        $this->CheckAbandonPlanetState ($GalaxyRowPlanet);
                    }
                    else
                    {
                        $planetcount++;
                        $GalaxyRowPlayer = doquery("SELECT * FROM {{table}} WHERE `id` = '". $GalaxyRowPlanet["id_owner"] ."';", 'users', true);
                    }

                    if ($GalaxyRow["id_luna"] != 0)
                    {
                        $GalaxyRowMoon   = doquery("SELECT * FROM {{table}} WHERE `id` = '". $GalaxyRow["id_luna"] ."' AND planet_type='3';", 'planets', true);

                        if ($GalaxyRowMoon["destruyed"] != 0)
                        {
                            $this->CheckAbandonMoonState ($GalaxyRowMoon);
                        }
                    }

                    if ($GalaxyRowPlanet['id_owner'] <> 0)
                        $GalaxyRowUser     = doquery("SELECT * FROM {{table}} WHERE `id` = '". $GalaxyRowPlanet['id_owner'] ."';", 'users', true);
                    else
                        $GalaxyRowUser     = array();

                }
            }

            $Result .= $this->GalaxyRowPos        ( $GalaxyRow, $Galaxy, $System, $Planet, 1 );
            $Result .= $this->GalaxyRowPlanet     ( $GalaxyRow, $GalaxyRowPlanet, $GalaxyRowPlayer, $Galaxy, $System, $Planet, 1, $HavePhalanx, $CurrentGalaxy, $CurrentSystem);
            $Result .= $this->GalaxyRowPlanetName ( $GalaxyRow, $GalaxyRowPlanet, $GalaxyRowPlayer, $Galaxy, $System, $Planet, 1, $HavePhalanx, $CurrentGalaxy, $CurrentSystem);
            $Result .= $this->GalaxyRowMoon       ( $GalaxyRow, $GalaxyRowMoon  , $GalaxyRowPlayer, $Galaxy, $System, $Planet, 3 );
            $Result .= $this->GalaxyRowDebris     ( $GalaxyRow, $GalaxyRowPlanet, $GalaxyRowPlayer, $Galaxy, $System, $Planet, 2, $CurrentRC);
            $Result .= $this->GalaxyRowUser       ( $GalaxyRow, $GalaxyRowPlanet, $GalaxyRowPlayer, $Galaxy, $System, $Planet, 0, $UserPoints );
            $Result .= $this->GalaxyRowAlly       ( $GalaxyRow, $GalaxyRowPlanet, $GalaxyRowPlayer, $Galaxy, $System, $Planet, 0 );
            $Result .= $this->GalaxyRowActions    ( $GalaxyRow, $GalaxyRowPlanet, $GalaxyRowPlayer, $Galaxy, $System, $Planet, 0, $CurrentGalaxy, $CurrentSystem, $CurrentMIP);
            $Result .= "</tr>";
        }
        return $Result;
    }
  private function show2D($CurrentUser, $CurrentPlanet){
  global $xgp_root, $phpEx, $dpath, $resource, $lang, $planetcount;

    includeLang('galaxy');
    includeLang('INGAME');

        $fleetmax          = ($CurrentUser['computer_tech'] + 1) + ($CurrentUser['rpg_commandant'] * COMMANDANT);
        $CurrentPlID       = $CurrentPlanet['id'];
        $CurrentMIP        = $CurrentPlanet['interplanetary_misil'];
        $CurrentRC         = $CurrentPlanet['recycler'];
        $CurrentSP         = $CurrentPlanet['spy_sonde'];
        $HavePhalanx       = $CurrentPlanet['phalanx'];
        $CurrentSystem     = $CurrentPlanet['system'];
        $CurrentGalaxy     = $CurrentPlanet['galaxy'];
        $CanDestroy        = $CurrentPlanet[$resource[213]] + $CurrentPlanet[$resource[214]];

        $maxfleet       = doquery("SELECT * FROM {{table}} WHERE `fleet_owner` = '". $CurrentUser['id'] ."';", 'fleets');
        $maxfleet_count = mysql_num_rows($maxfleet);
        
                $parse                        = $lang;
        $parse['currentmip']        = $CurrentMIP;
        $parse['maxfleetcount']        = $maxfleet_count;
        $parse['fleetmax']            = $fleetmax;
        $parse['recyclers']           = pretty_number($CurrentRC);
        $parse['spyprobes']           = pretty_number($CurrentSP);
        $parse['missile_count']        = sprintf($lang['gl_missil_to_launch'], $CurrentMIP);
        $parse['current']            = $_GET['current'];
        $parse['current_galaxy']    = $CurrentPlanet["galaxy"];
        $parse['current_system']    = $CurrentPlanet["system"];
        $parse['current_planet']    = $CurrentPlanet["planet"];
        $parse['planet_type']         = $CurrentPlanet["planet_type"];
        $parse['planetcount']         = $planetcount ." ". $lang['gl_populed_planets'];

    CheckPlanetUsedFields($CurrentPlanet);
    CheckPlanetUsedFields($lunarow);

        if (!isset($mode))
        {
            if (isset($_GET['mode']))
            {
                $mode = intval($_GET['mode']);
            }
            else
            {
                $mode = 0;
            }
        }

        if ($mode == 0)
        {
            $galaxy        = $CurrentPlanet['galaxy'];
            $system        = $CurrentPlanet['system'];
            $planet        = $CurrentPlanet['planet'];
        }
        elseif ($mode == 1)
        {
            if (is_numeric($_POST["galaxy"]))
                $_POST["galaxy"] = abs($_POST["galaxy"]);
            else
                $_POST["galaxy"] = 1;

            if (is_numeric($_POST["system"]))
                $_POST["system"] = abs($_POST["system"]);
            else
                $_POST["system"] = 1;

            if ($_POST["galaxy"] > MAX_GALAXY_IN_WORLD)
                $_POST["galaxy"] = MAX_GALAXY_IN_WORLD;

            if ($_POST["system"] > MAX_SYSTEM_IN_GALAXY)
                $_POST["system"] = MAX_SYSTEM_IN_GALAXY;

            if ($_POST["galaxyLeft"])
            {
                if ($_POST["galaxy"] < 1)
                {
                    $_POST["galaxy"] = 1;
                    $galaxy          = 1;
                }
                elseif ($_POST["galaxy"] == 1)
                {
                    $_POST["galaxy"] = 1;
                    $galaxy          = 1;
                }
                else
                {
                    $galaxy = $_POST["galaxy"] - 1;
                }
            }
            elseif ($_POST["galaxyRight"])
            {
                if ($_POST["galaxy"] > MAX_GALAXY_IN_WORLD OR $_POST["galaxyRight"] > MAX_GALAXY_IN_WORLD)
                {
                    $_POST["galaxy"]      = MAX_GALAXY_IN_WORLD;
                    $_POST["galaxyRight"] = MAX_GALAXY_IN_WORLD;
                    $galaxy               = MAX_GALAXY_IN_WORLD;
                }
                elseif ($_POST["galaxy"] == MAX_GALAXY_IN_WORLD)
                {
                    $_POST["galaxy"]      = MAX_GALAXY_IN_WORLD;
                    $galaxy               = MAX_GALAXY_IN_WORLD;
                }
                else
                {
                    $galaxy = $_POST["galaxy"] + 1;
                }
            }
            else
            {
                $galaxy = $_POST["galaxy"];
            }

            if ($_POST["systemLeft"])
            {
                if ($_POST["system"] < 1)
                {
                    $_POST["system"] = 1;
                    $system          = 1;
                }
                elseif ($_POST["system"] == 1)
                {
                    $_POST["system"] = 1;
                    $system          = 1;
                }
                else
                {
                    $system = $_POST["system"] - 1;
                }
            }
            elseif ($_POST["systemRight"])
            {
                if ($_POST["system"]      > MAX_SYSTEM_IN_GALAXY OR $_POST["systemRight"] > MAX_SYSTEM_IN_GALAXY)
                {
                    $_POST["system"]      = MAX_SYSTEM_IN_GALAXY;
                    $system               = MAX_SYSTEM_IN_GALAXY;
                }
                elseif ($_POST["system"] == MAX_SYSTEM_IN_GALAXY)
                {
                    $_POST["system"]      = MAX_SYSTEM_IN_GALAXY;
                    $system               = MAX_SYSTEM_IN_GALAXY;
                }
                else
                {
                    $system = $_POST["system"] + 1;
                }
            }
            else
            {
                $system = $_POST["system"];
            }
        
        }
        elseif ($mode == 2)
        {
            $galaxy        = $_GET['galaxy'];
            $system        = $_GET['system'];
            $planet        = $_GET['planet'];
                $parse['galaxy']            = $galaxy;
                $parse['system']            = $system;
                $parse['planet']            = $planet;
                $parse['missile_count']        = sprintf($lang['gl_missil_to_launch'], $CurrentMIP);
                $CurrentPlanetID = $_GET['current'];
            message(parsetemplate(gettemplate('galaxy/galaxy_missile_selector'), $parse));
        }
        elseif ($mode == 3)
        {
            $galaxy        = $_GET['galaxy'];
            $system        = $_GET['system'];
        }
        else
        {
            $galaxy        = 1;
            $system        = 1;
        }

        if ( ( $CurrentPlanet['system'] != ( $_POST["system"] - 1 ) ) && ( $mode != 0 ) && ( $CurrentPlanet['deuterium'] < 10 ) )
        {
            die (message($lang['gl_no_deuterium_to_view_galaxy'], "game.php?page=galaxy&mode=0", 2));
        }
        elseif( ( $CurrentPlanet['system'] != ( $_POST["system"] - 1 ) ) && ( $mode != 0 ) )
        {
            $QryGalaxyDeuterium   = "UPDATE {{table}} SET ";
            $QryGalaxyDeuterium  .= "`deuterium` = `deuterium` -  10 ";
            $QryGalaxyDeuterium  .= "WHERE ";
            $QryGalaxyDeuterium  .= "`id` = '". $CurrentPlanet['id'] ."' ";
            $QryGalaxyDeuterium  .= "LIMIT 1;";
            doquery($QryGalaxyDeuterium, 'planets');
        }

        $planetcount = 0;
        $lunacount   = 0;
        
        $parse['galaxy']            = $galaxy;
        $parse['system']            = $system;
        $parse['planet']            = $planet;

        $parse['planetcount']         = $planetcount ." ". $lang['gl_populed_planets'];




    

    echo $this->InsertGalaxyScripts ( $CurrentPlanet );

    echo     "<body><br>
            <span><b> Sistema Solar</b></span>
            ";
    echo "<center>";
    echo parsetemplate(gettemplate('galaxy/galaxy_selector'), $parse);
    echo "</center>";
    
            

    echo  parsetemplate(gettemplate('galaxy/galaxy_footer2d'), $parse);


    echo "<table width=569><tbody>";

    echo "</center></tbody></table>";

echo "

<div id=\"raum_3\" style=\"z-index: 0; top: 110px; height: 0px;\"><img src=\"styles/images/galaxy/gala2.jpg\" border=\"10\" height=\"600\" width=\"900\"></div>
";

$e = 0; $f = 1; $g = 1;

$position = array(
"276;577; 347;590; 350;208; 593;590; 444;502; 110;400; 661;351; 725;220; 40;280; 751;483; 300;347; 186;192; 206;540; 494;380; 516;220;",
"350;308; 533;608; 444;472; 37;487; 176;610; 347;570; 641;351; 755;220; 444;320; 546;240; 126;200; 701;483; 240;347; 336;212; 246;500;",
"546;340; 176;597; 347;570; 350;208; 524;220; 533;600; 444;412; 70;530; 246;480; 641;351; 755;220; 106;230; 701;483; 380;347; 236;282;",
"533;428; 444;472; 137;450; 611;351; 755;220; 106;230; 701;483; 380;347; 236;282; 246;500; 584;550; 546;240; 46;607; 347;570; 350;208;",
"350;288; 533;588; 444;472; 36;607; 347;570; 107;450; 641;351; 755;220; 106;200; 701;483; 380;347; 306;232; 246;500; 240;280; 546;240;",
"187;470; 661;351; 755;220; 56;607; 347;570; 350;208; 533;588; 304;472; 546;240; 60;230; 701;503; 340;327; 524;400; 196;282; 166;500;");

$randomquote = mt_rand(0,count($position)-1);

$pos  = " . $position[$randomquote] . ";
$count = 1;
while($count < 16)
{
$missiontime = explode(";", $pos);
$pos1 = $missiontime[ $e ] +50;
$pos2 = $missiontime[ $f ];

echo "<div id=\"$e\" style=\"z-index: 6; position: absolute; left: ".$pos1."px; top: ".$pos2."px; width: 10px; height: 10px; visibility: visible;\">";
$leer = '';$img = '';

$query = doquery("SELECT * FROM {{table}} WHERE `galaxy` = '$galaxy' AND `system` = '$system' AND planet = '$count' AND planet_type =  '1';", 'planets');
while($row = mysql_fetch_assoc($query)){
$leer = $row['planet'];
$img = $row['image'];



//$planet_name = $row['name'];


$query1 = doquery("SELECT ally_id, ally_name, username, authlevel, onlinetime, id,bana  FROM {{table}} WHERE `id` = '".$row['id_owner']."';", 'users');
while($row1 = mysql_fetch_assoc($query1)){

if ($row1['ally_id'] == '0'){$ally = '';} else {
$ally = "Alianza: <a href=game.php?page=alliance&mode=ainfo&a=".$row1['ally_id'].">".$row1['ally_name']."</a><br/>";}

        if ($row1['authlevel'] == 3)
            {$username = "<font color=red>".$row1['username']."</font>";
            $planetname = "<font color=red>".$row['name']."</font>";
            
            
    } elseif ($row1['urlaubs_modus'] == 1)
            {$username = "<font color=skyblue>".$row1['username']."</font>";
            $planetname = "<font color=skyblue>".$row['name']."</font>";
            
    } elseif ($row1['onlinetime'] < (time()-60 * 60 * 24 * 7) AND
            $row1['onlinetime'] > (time()-60 * 60 * 24 * 28))
            {$username = "<font color=#aaaaaa>".$row1['username']."(i)</font>";
            $planetname = "<font color=#aaaaaa>".$row['name']."</font>";
            
    } elseif ($row1['onlinetime'] < (time()-60 * 60 * 24 * 28))
            {$username = "<font color=#cccccc>".$row1['username']."(Ii)</font>";
            $planetname = "<font color=#cccccc>".$row['name']."</font>";
            
    } elseif ($row1['bana'] == 1)
            {$username = "<font color=line-through>".$row1['username']."</font>";
            $planet_name = "<font color=line-through>".$row['name']."</font>";
            
    } else {$username = "<font color=limegreen>".$row1['username']."</font>";
            $planetname = "<font color=limegreen>".$row['name']."</font>";
            }

if ($row1['id'] != $user['id'])
{$buddy ="<a href=game.php?page=buddy&mode=2&u=16".$row['id_owner']."&u=".$row['id_owner']."><font color=blue>Amigos ?</a><br></font>";} else {$buddy ='';}

if ($row1['id'] != $user['id'])
{$mail ="<a href=game.php?page=messages&mode=write&id=".$row['id_owner']."><font color=red>MP</a><br></font>";} else {$mail ='';}
}


$query2 = doquery("SELECT * FROM {{table}} WHERE `galaxy` = '$galaxy' AND `system` = '$system' AND planet = '$g' Limit 1;", 'galaxy');
while($row2 = mysql_fetch_assoc($query2)){

if ($row2['id_luna'] != '0'){$mond = "<font color=yellow>Luna : Sí</font><br><a href=game.php?page=fleet&galaxy=$galaxy&system=$system&planet=$count&planettype=3&target_mission=9><font color=red>Destrucción de luna</font></a><br>";}else{$mond = "<font color=yellow>Luna: no</font><br>";}
if ($row2['id_luna'] != '0'){$mond1 = 1;}else{$mond1 = 0;}

if ($row2['metal'] == '0' || $row2['crystal'] == '0') {
$tr = "";
}else {
$galaxy = $row2['galaxy'];
$tr = "<a style=\"cursor: crosshair;\" onmouseover='return overlib(\"<table width=150><tr><td class=c colspan=2> TF: <br> Metal: ".$row2['metal']." <br>cristal: ".$row2['crystal']." </th></tr><a href=game.php?page=fleet&galaxy=$galaxy&system=$system&planet=$count&planettype=2&target_mission=8>Recolectar</a></th></tr></table>\", STICKY, MOUSEOFF, DELAY, 100, CENTER, OFFSETX, -100, OFFSETY, -100 );' onmouseout='return nd();'><img src=styles/images/galaxy/debris.gif>";
}
}






/**/


echo "<th width=30><a style=\"cursor: crosshair;\" onmouseover='return overlib(\" <table width=250><tr><td class=c colspan=2>Planeta ".$row['name']." [".$row['galaxy'].":".$row['system'].":".$row['planet']."]</td></tr><tr><th width=80><img src=styles/images/galaxy/sp".$g.".gif height=75 width=75 /></th><th align=left>Pos. ".$row['planet']."<br>Nombre: ".$row['name']."<br> Propietario: <a href=stat.php?who=player&start=".$row['id_owner']." title=Statistik alt=Statistik> $username </a><br>$mond  $ally $buddy $mail<hr><a href=game.php?page=fleet&galaxy=$galaxy&system=$system&planet=$count&planettype=1&target_mission=4>Espiar</a><br /><a href=# onclick=javascript:doit(6, $galaxy, $system, $g, 1, ".$user['spy_sonde'].");>Espiar Rápido</a><br /><a href=game.php?page=fleet&galaxy=$galaxy&system=$system&planet=$count&planettype=1&target_mission=3>Transportar</a><br/><a href=game.php?page=fleet&galaxy=$galaxy&system=$system&planet=$count&planettype=1&target_mission=1>Atacar</a><br /><a href=game.php?page=galaxy&mode=2&galaxy=$galaxy&system=$system&planet=$count&planettype=1>Mísil</a></th></tr>  </table>\",STICKY, MOUSEOFF, DELAY, 100, CENTER, OFFSETX, -100, OFFSETY, -150 );' onmouseout='return nd();'>";}


if ($leer ==''){
echo "<th width=30><a style=\"cursor: crosshair;\" onmouseover='return overlib(\" <table width=250><tr><td class=c colspan=2><center>Der Planet ist noch nicht <br>besiedelt [$galaxy : $system : $count]</center></td></tr> <th align=left><hr><a href=game.php?page=fleet&galaxy=$galaxy&system=$system&planet=$count&planettype=1&target_mission=7>Conquistar</a></th></tr>  </table>\",STICKY, MOUSEOFF, DELAY, 100, CENTER, OFFSETX, -100, OFFSETY, -150 );' onmouseout='return nd();'>";
}

if ($img != '') {

echo "$username $ally <a href=# onclick='javascript:doit(6, $galaxy, $system, $g, 1, ".$user['spy_sonde'].");'><img src=styles/images/galaxy/sp".$g.".gif  height=\"30\" width=\"30\">($planetname)$count</a><table  width=\"100\" height=\"50\"><p><a href=# onclick='javascript:doit(6, $galaxy, $system, $g, 3, ".$user["spy_sonde"].");'><img src=styles/images/galaxy/mond".$mond1.".gif>".$tr."<p></a></td></tr></table></div>";

} else {
echo"<a href=game.php?page=fleet&galaxy=$galaxy&system=$system&planet=$count&planettype=1&target_mission=7><img src=styles/images/galaxy/sp".$g.".gif height=\"40\" width=\"40\">(Planeta Libre)$count</a></th></div>";}

echo "<div id=\"99\" style=\" position: absolute; left: 20px; top: 170px; width: 20px; height: 10px;\"><a href=game.php?page=fleet&galaxy=$galaxy&system=$system&planet=16&planettype=1&target_mission=15><img src=styles/images/galaxy/wurmloch.png height=\"30\" width=\"30\">Espacio Infinito</a></th></div>";



$e++;$e++; $f++; $f++; $g++;
    $count++;
    }

    echo "<div id=\"99\" style=\"  left: 600px; top: 20px; width: 1000px; height: 10px;\"><center><tbody>";

            echo "</center></tbody></table></div></div>";
    
    
    display ($page, false);
/*
Ajout de la fonction Mippage par Ligmas de http://novazone.org.
*/
  
  }    

}
?>


Si quelqu'un aurait une solution ou des conseils je suis preneur Smile Car je suis bloquer en ce moment.



Cordialement,



Ducky.


RE: Création d'une carte pour mon jeux. - Thêta Tau Tau - 26-02-2013

Salut,

Commence déjà par séparer ton php, html et javascript en trois fichiers et à commenter ton code, ça sera plus compréhensible pour toi comme pour nous. Et si possible ne poste pas tout ton code mais que ce qui te pose problème (ou met le en évidence).

Pourrais tu préciser ta question aussi, pour qu'on puisse savoir de quoi il s'agit sans avoir lu le code?
Par exemple veux tu générer la carte sous la forme d'un tableau (table tr td), sous la forme d'une image, d'un svg?. Comment sont représentées les données?


RE: Création d'une carte pour mon jeux. - Xenos - 26-02-2013

J'approuve θττ
J'ajouterai également:
- il existe une balise bbcode "code=php" pour les codes en php, cela améliorera la lisibilité du code en ajoutant de la coloration syntaxique
- rien n'empêche une commande php de s'étaler sur plusieurs lignes:

$script .= "<script> <!-- language n'est plus un attribut html5, il n'est pas utile -->
var blabla =...
// code javascript qui continue
"; // fin de la commande php
- Les "unset" sont souvent inutiles en php; si la variable "$truc" est écrasée, précéder le "$truc =..." d'un "unset($truc)" n'est pas nécessaire
- Tu sembles partis pour mélanger allègrement javascript, php et html... je te conseillerai de bien les séparer comme l'a dit θττ, mais également, de ne pas utiliser du javascript à tort: n'insère pas des balises "script" après chaque case pour afficher cette case, mais insère une balise script à la fin de la carte (après la balise fermant le contenu de la carte par exemple) qui gèrera toute la carte (ce sera plus léger à lire, à exécuter, à entretenir et également un peu plus propre)


RE: Création d'une carte pour mon jeux. - Ducky_Duck - 27-02-2013

D'accord, merci beaucoup en tous cas je vais faire avec vos conseils et essayer de me débrouiller pour faire ça proprement Smile