Jump to content

Could use some help with creating my game field


jve2211

Recommended Posts

Hello guys..

 

Im trying to create a browser game but now im having some problems with my game map. it worked fine when i tested it all on my own pc ofc.

 

but now when i uploaded it to a remote server the refresh of the map everytime i press north,west,south,east just kinda ruins my game map.

 

here is my code maybe anyone got any suggestions on what i can do differently.. thanks..

 

<?php

include("vartest.php");

include("database.php");

 

if($_SESSION['x'] && $_SESSION['y'])

{

if(isset($_POST['go']))

{

$_SESSION['x'] = $_POST['givex'];

$_SESSION['y'] = $_POST['givey'];

}

}

 

else

{

db('open');

$name = $_SESSION['naam'];

$gethdpos = mysql_query("SELECT x,y FROM dorpen WHERE eigenaar='$name'") or die ("query mislukt");

$pos = mysql_fetch_row($gethdpos);

$_SESSION['x'] = $pos[0];

$_SESSION['y'] = $pos[1];

db('close');

}

 

 

if(isset($_POST['west']))

{

if($_SESSION['x'] > 2)

{

$_SESSION['x']--;

}

}

 

if(isset($_POST['north']))

{

if($_SESSION['y'] < 250)

{

$_SESSION['y']++;

}

}

 

if(isset($_POST['south']))

{

if($_SESSION['y'] > 2)

{

$_SESSION['y']--;

}

}

 

if(isset($_POST['east']))

{

if($_SESSION['x'] < 250)

{

$_SESSION['x']++;

}

}

 

 

$plaatje = Array(48);

$cellx = $_SESSION['x'];

$celly = $_SESSION['y'];

$id = Array(48);

$x = Array(48);

$y = Array(48);

$eigenaar = Array(48);

$type = Array(48);

$plaatje = Array(48);

$getpic = Array(48);

$pic = Array(48);

$i=0;

 

db("open");

for($v=-3; $v<=3; $v++)

{

$celly = $_SESSION['y'] + $v;

for($h=-3; $h<=3; $h++)

{

$cellx = $_SESSION['x'] + $h;

$getpic = mysql_query("SELECT * FROM velden WHERE x='$cellx' AND y='$celly'") or die ("bewerking mislukt");

$pic = mysql_fetch_array($getpic);

 

for($k=0; $k<=1; $k++)

{

$id[$i] = $pic[0];

$x[$i] = $pic[1];

$y[$i] = $pic[2];

$eigenaar[$i] = $pic[3];

$type[$i] = $pic[4];

$plaatje[$i] =$pic[5];

}

$i++;

}

}

db("close");

 

?>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

 

 

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

<style type="text/css">

<!--

body {

background-color: #000000;

}

.style1 {

color: #CCCCCC;

font-weight: bold;

font-size: 24px;

}

.style2 {color: #000000}

.whatever {background-image: url('leftupper.jpg'); }

.style3 {

font-family: Georgia, "Times New Roman", Times, serif;

font-size: 36px;

}

a {

font-size: 16px;

color: #000000;

}

a:link {

text-decoration: none;

}

a:visited {

text-decoration: none;

color: #000000;

}

a:hover {

text-decoration: none;

color: #FF0000;

}

a:active {

text-decoration: none;

color: #000000;

}

.style7 {

font-size: 9px;

color: #FFFFCC;

}

 

.myClass

{

cursor: pointer;

}

 

-->

</style></head>

 

<body>

<p> </p>

<table width="640" height="480" border="0" align="center" class=whatever bg>

  <tr>

    <td width="140" height="100"> </td>

    <td width="500" height="100"><div align="center" class="style1 style2 style3">คгt ๏Ŧ ฬคг ๏ภlเภє</div></td>

  </tr>

  <tr>

    <td width="140" height="300"><table width="100%" height="250">

      <tr>

        <td height="25"><div align="center"></div></td>

      </tr>

      <tr>

        <td height="25"><div align="center"><strong><a href="file:///E|/website/xampp/htdocs/testsite/temp.php">forum</a></strong></div></td>

      </tr>

      <tr>

        <td height="25"><div align="center"><strong><a href="file:///E|/website/xampp/htdocs/testsite/temp.php">screenshots</a></strong></div></td>

      </tr>

      <tr>

        <td height="25"><div align="center"></div></td>

      </tr>

      <tr>

        <td height="25"><div align="center"><strong><a href="register.php">hoofdstad</a></strong></div></td>

      </tr>

      <tr>

        <td height="25"><div align="center"><strong><a href="game.php">kaart</a></strong></div></td>

      </tr>

      <tr>

        <td height="25"><div align="center"><strong><a href="login.php">logout</a></strong></div></td>

      </tr>

      <tr>

        <td height="25"><div align="center"></div></td>

      </tr>

      <tr>

        <td height="25"><div align="center"></div></td>

      </tr>

      <tr>

        <td height="25"><div align="center"><a href="index.php"><strong>home</strong></a></div></td>

      </tr>

    </table></td>

    <td width="500" height="300"><form action="map.php" method="post"><div align="center">

      <table width="342" height="225" border="0" background="kaart.jpg">

        <tr>

          <td width="30"> </td>

          <td width="30" height="25"> </td>

          <td width="30" height="25"> </td>

          <td width="30" height="25"> </td>

          <td height="25" colspan="3"><div align="center">

            <input type="submit" name="north" id="north" value="N" />

          </div></td>

          <td width="30" height="25"> </td>

          <td width="30" height="25"> </td>

          <td width="30" height="25"> </td>

          <td width="30"> </td>

        </tr>

        <tr>

          <td width="30"> </td>

          <td width="30" height="25"> </td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[42]; ?>"><a title="<?php echo $eigenaar[42]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[43]; ?>"><a title="<?php echo $eigenaar[43]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[44]; ?>"><a title="<?php echo $eigenaar[44]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[45]; ?>"><a title="<?php echo $eigenaar[45]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[46]; ?>"><a title="<?php echo $eigenaar[46]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[47]; ?>"><a title="<?php echo $eigenaar[47]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[48]; ?>"><a title="<?php echo $eigenaar[48]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25"> </td>

          <td width="30"> </td>

        </tr>

        <tr>

          <td width="30"> </td>

          <td width="30" height="25"> </td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[35]; ?>"><a title="<?php echo $eigenaar[35]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[36]; ?>"><a title="<?php echo $eigenaar[36]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[37]; ?>"><a title="<?php echo $eigenaar[37]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[38]; ?>"><a title="<?php echo $eigenaar[38]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[39]; ?>"><a title="<?php echo $eigenaar[39]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[40]; ?>"><a title="<?php echo $eigenaar[40]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[41]; ?>"><a title="<?php echo $eigenaar[41]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25"> </td>

          <td width="30"> </td>

        </tr>

        <tr>

          <td width="30" rowspan="3"> </td>

          <td width="30" height="75" rowspan="3"><input type="submit" name="west" id="west" value="W" /></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[28]; ?>"><a title="<?php echo $eigenaar[28]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[29]; ?>"><a title="<?php echo $eigenaar[29]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[30]; ?>"><a title="<?php echo $eigenaar[30]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[31]; ?>"><a title="<?php echo $eigenaar[31]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[32]; ?>"><a title="<?php echo $eigenaar[32]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[33]; ?>"><a title="<?php echo $eigenaar[33]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[34]; ?>"><a title="<?php echo $eigenaar[34]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="75" rowspan="3"><label></label>            <input type="submit" name="east" id="east" value="O" /></td>

          <td width="30" rowspan="3"> </td>

        </tr>

        <tr>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[21]; ?>"><a title="<?php echo $eigenaar[21]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[22]; ?>"><a title="<?php echo $eigenaar[22]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[23]; ?>"><a title="<?php echo $eigenaar[23]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" bordercolor="#FF0000" background="<?php echo $plaatje[24]; ?>"><a title="<?php echo $eigenaar[24]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[25]; ?>"><a title="<?php echo $eigenaar[25]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[26]; ?>"><a title="<?php echo $eigenaar[26]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[27]; ?>"><a title="<?php echo $eigenaar[27]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          </tr>

        <tr>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[14]; ?>"><a title="<?php echo $eigenaar[14]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[15]; ?>"><a title="<?php echo $eigenaar[15]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[16]; ?>"><a title="<?php echo $eigenaar[16]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[17]; ?>"><a title="<?php echo $eigenaar[17]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[18]; ?>"><a title="<?php echo $eigenaar[18]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[19]; ?>"><a title="<?php echo $eigenaar[19]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[20]; ?>"><a title="<?php echo $eigenaar[20]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          </tr>

        <tr>

          <td width="30"> </td>

          <td width="30" height="25"> </td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[7]; ?>"><a title="<?php echo $eigenaar[7]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[8]; ?>"><a title="<?php echo $eigenaar[8]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[9]; ?>"><a title="<?php echo $eigenaar[9]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[10]; ?>"><a title="<?php echo $eigenaar[10]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[11]; ?>"><a title="<?php echo $eigenaar[11]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[12]; ?>"><a title="<?php echo $eigenaar[12]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[13]; ?>"><a title="<?php echo $eigenaar[13]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25"> </td>

          <td width="30"> </td>

        </tr>

        <tr>

          <td width="30"> </td>

          <td width="30" height="25"> </td>

          <td width="30" height="25" class="myClass" onclick="window.location.href='<?php echo "checkveld.php?id=".$id[0]."" ?>'" background="<?php echo $plaatje[0]; ?>"><a title="<?php echo $eigenaar[0]; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[1]; ?>"><a title="<?php echo $eigenaar[1]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[2]; ?>"><a title="<?php echo $eigenaar[2]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[3]; ?>"><a title="<?php echo $eigenaar[3]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[4]; ?>"><a title="<?php echo $eigenaar[4]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[5]; ?>"><a title="<?php echo $eigenaar[5]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[6]; ?>"><a title="<?php echo $eigenaar[6]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

          <td width="30" height="25"> </td>

          <td width="30"> </td>

        </tr>

        <tr>

          <td width="30"> </td>

          <td width="30" height="25"> </td>

          <td width="30" height="25"> </td>

          <td width="30" height="25"> </td>

          <td height="25" colspan="3"><div align="center">

            <input type="submit" name="south" id="south" value="S" />

          </div></td>

          <td width="30" height="25"> </td>

          <td width="30" height="25"> </td>

          <td width="30" height="25"> </td>

          <td width="30"> </td>

        </tr>

      </table>

    </div></form></td>

  </tr>

  <tr>

    <td width="140" height="80"> </td>

    <td width="500" height="80"><form action="map.php" method="post"><table width="400" align="center">

      <tr>

        <td width="50" height="50" align="center"><div align="center">x</div></td>

        <td width="50" height="50" align="center"><div align="center">

          <input name="givex" type="text" id="givex" value="<?php echo $_SESSION['x']; ?>" size="3"/>

        </div></td>

        <td width="50" height="50" align="center"><label>

          <div align="center">y            </div>

        </label></td>

        <td width="50" height="50" align="center"><div align="center">

          <input name="givey" type="text" id="givey" size="3" value="<?php echo $_SESSION['y']; ?>"/>

        </div></td>

        <td width="50" height="50" align="center"><div align="center">

          <input type="submit" name="go" id="go" value="go" />

        </div></td>

        <td width="50" height="50" align="center"><div align="center"></div></td>

        <td width="50" height="50" align="center"><div align="center"></div></td>

        <td width="50" height="50" align="center"><div align="center"></div></td>

      </tr>

    </table></form></td>

  </tr>

</table>

<div align="center"></div>

<p align="center" class="style7"> </p>

<p> </p>

</body>

</html>

 

 

long code :) dont be hard on me i only tryed PHP for about 4 months now..

Link to comment
Share on other sites

This will not work when you upload it to a server:

 

<a href="file:///E|/website/xampp/htdocs/testsite/temp.php">forum</a>

<a href="file:///E|/website/xampp/htdocs/testsite/temp.php">screenshots</a>

 

The refreshing is normal. You can overlap this using Ajax technology (JavaScript)

 

Don't use inline styles (i.e. <style></style>)

 

<td width="30" height="25" class="myClass" background="<?php echo $plaatje[14]; ?>"><a title="<?php echo $eigenaar[14]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>
          <td width="30" height="25" class="myClass" background="<?php echo $plaatje[15]; ?>"><a title="<?php echo $eigenaar[15]." is eigenaar van dit gebied"; ?>" style="display:block"> </a></td>

 

Use a loop to do this for you. If you ever tend to enlargen your map you will be otherwise writing it all over again.

 

Use semantics: tables are meant for tabular data, a website is not tabular data.

 

Create convenience functions for both db('open') as for db('close'). If you ever work in a team, your teammates may have a hard time figuring out what the db() function does or which parameters it should take (if insufficient documentation is provided).

 

Remove "or die()" it's a bad habbit. Use a combination of set_error_handler() and trigger_error() instead.

 

$pic = Array(48);

 

Does not create an array with 48 places instead it creates array ( 0 => 48 )

 

Use something differently then: $_POST['west']. Imagine I submitted this form to your game:

<input type="hidden" name="west" value="..">
<input type="hidden" name="north" value="..">
<input type="hidden" name="south" value="..">
<input type="hidden" name="east" value="..">

 

Where would I end up?

 

That's all.

Link to comment
Share on other sites

thx allot for those tips.. wil work on my coding habits :)

 

but my problem isnt solved i gues my problem lies in the following code.

 

$plaatje = Array(48);

$cellx = $_SESSION['x'];

$celly = $_SESSION['y'];

$id = Array(48);

$x = Array(48);

$y = Array(48);

$eigenaar = Array(48);

$type = Array(48);

$plaatje = Array(48);

$getpic = Array(48);

$pic = Array(48);

$i=0;

 

db("open");

for($v=-3; $v<=3; $v++)

{

  $celly = $_SESSION['y'] + $v;

  for($h=-3; $h<=3; $h++)

  {     

  $cellx = $_SESSION['x'] + $h;

  $getpic = mysql_query("SELECT * FROM velden WHERE x='$cellx' AND y='$celly'") or die ("bewerking mislukt");

  $pic = mysql_fetch_array($getpic);

     

      for($k=0; $k<=1; $k++)

      {

      $id[$i] = $pic[0];

      $x[$i] = $pic[1];

      $y[$i] = $pic[2];

      $eigenaar[$i] = $pic[3];

      $type[$i] = $pic[4];

      $plaatje[$i] =$pic[5]; 

      }

  $i++;

  }     

}

db("close");

 

this fills 49 table cells with a backgroundpicture from a database doing 49 querys.. the page refresh isnt rly a problem if i could get the information more efficiently or in less time somehow. or maybe i would need to redesign the whole game field in a better and more efficient way. i just dont have a clue how it would be done differently from this.

 

i was thinking maybe to use some array like $var = Array(Array("picture1","picture2","picture3"),Array("picture1","picture2","picture3"),Array("picture1","picture2","picture3"));

 

but like this i would have to put my entire gamefield into some array wich is like 250x250 fields big. and i gues this would have a very long load time :)

 

Link to comment
Share on other sites

I was thinking of doing something like that but its pain. Here is the idea I came up with though use a cron to update the game map into an array once a day. Have it save the array in a php file so that you can just include it in your explore script and have the full area with no query and the ability to change it easy (to change a image you just have to run a query once instead of updating each and every part of the array). This might not be the best solution for you but it will work.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.