0

I am creating an online version of Stratego, but I've run into a wall.
I want my pieces to switch places in the initial phase, where you can set up your game.
They are placed within a table.

Table:

Include_once 'StukkenPos.php';
echo '<img src="../../Images/board/strategoboard.png" class="test">';
echo "<table border='1' style='width: 590px; height: 590px' class='test2'>";
for($i = 0; $i < 10; $i++) {
    echo "<tr>";
    for($j = 0; $j < 10; $j++) {
        if (isset($stukken[$i][$j])) {
            $stuk = $stukken[$i][$j];
            $s = "style= 'z-index:1; width:52px; height:52px; position:inherit'";
            $inhoud = "<img src='../../Images/stukken/$stuk' $s>";
        } else {
        $inhoud = '&nbsp;';
        }
        echo     "<td class='cell'; id=${i}_$j; rij=$i col=$j;"
                . " style=height:55px>$inhoud</td>";
    }
    echo "</tr>";
}
echo "<table>";

StukkenPos.php is an array that contains the position of the images and the image that is related to that position innitially. The table is a 10x10 field. The first echo contains the image of the board-background.

The way the pieces/ images are inserted:

<?php
$stukken[0][0] = "b1.png";
$stukken[0][1] = "b2.png";
$stukken[0][2] = "b2.png";

To get me on my feet; Can you get the x,y coordinates of an images with onclick? If so, how do you form your code to get them?

such as:

<img src="b1.png" onclick="//save coordinates;"/>

but then without changing the $stukken array, so it's within another script.

L. de Boer
  • 88
  • 1
  • 11
  • You may want to look at this answer: http://stackoverflow.com/questions/2159044/getting-the-x-y-coordinates-of-a-mouse-click-on-an-image-with-jquery :) – node_modules May 25 '16 at 12:00
  • Thank you for the suggestion, but that is not relative to table positioning if I'm not mistaken. – L. de Boer May 25 '16 at 12:02
  • It gives the position of the image, whereas I created a table and want to switch up the position on those coordinates – L. de Boer May 25 '16 at 12:29

0 Answers0