More efficient than an if statement?
<p>I'm making a game in PHP (don't ask lol), and the player has a location which is an integer. There's a travel page and this basically shows a 5x5 tiled map. Each tile is a different part of the player's universe. By clicking on it he can travel there.
Just to give you an idea of the integers behind the map:</p>

<ul>
<li>11, 12, 13, 14, 15</li>
<li>21, 22, 23, 24, 25</li>
<li>31, 32, 33, 34, 35</li>
<li>41, 42, 43, 44, 45</li>
<li>51, 52, 53, 54, 55</li>
</ul>

<p>Let's say the player starts at 33(the middle) and I wanted to charge him different rates depending on how far he traveled. So, for example, 1 tile in any direction is a 100 credits, 2 tiles is 200 and so on.</p>

<p>So what I came up with is this. <code>$ol</code> represents the player's current location and <code>$nl</code> is where they are travelling to...</p>

<pre><code>if($ol-11==$nl || $ol-10==$nl || $ol-9==$nl || $ol+1==$nl || $ol+11==$nl || $ol+10==$nl || $ol+9==$nl || $ol-1==$nl || $ol-11==$nl ){
echo "cost 100 credits!";
}
else if($ol-22==$nl || $ol-21==$nl || $ol-20==$nl || $ol-19==$nl || $ol-18==$nl || $ol-8==$nl || $ol+2==$nl || $ol+12==$nl || $ol+22==$nl 

|| $ol+21==$nl || $ol+20==$nl || $ol+19==$nl || $ol+18==$nl || $ol+8==$nl || $ol-2==$nl || $ol-12==$nl ){
echo "cost 200 credits!";
}
</code></pre>

<p>That's the code for 1 and 2 tile travel. As you can see it's a lengthy statement.</p>

<p>I basically worked out a pattern for the grid I'd set up. For example, travelling up 1 tile would always be -10 of the current tile.</p>

<p>Before I type out any more ridiculously long if statements, is there a neater or more efficient way to do this?</p>
