note 30824 added to function.rand
| From: | daily-hunt at daily-hunt dot dk | Date: | Mon, 31 Mar 2003 18:12:55 +0000 |
| Subject: | note 30824 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-46016@lists.php.net to get a copy of this message | ||
I found a way to make a battleplayermodul there (maby) can be used to find a winner in a Web-based
multiplayer game, så there isn't 50/50 chance for both players to win...
<%
/* Player 1 info
int = intelegents
str = strenge
dex = dexterity
stat = calculate the info to %*/
$int1 = 2;
$str1 = 2;
$dex1 = 2;
$intpoint1 = $int1 * 30;
$strpoint1 = $str1 * 100;
$dexpoint1 = $dex1 * 70;
$stat1 = $intpoint1 + $strpoint1 + $dexpoint1;
/* Player 2 info
int = intelegents
str = strenge
dex = dexterity
stat = calculate the info to %*/
$int2 = 10;
$str2 = 10;
$dex2 = 10;
$intpoint2 = $int2 * 30;
$strpoint2 = $str2 * 100;
$dexpoint2 = $dex2 * 70;
$stat2 = $intpoint2 + $strpoint2 + $dexpoint2;
$player1 = round($stat1/($stat1+$stat2)*100,0);
$player2 = round($stat2/($stat1+$stat2)*100,0);
/* this make a random nummer in a range of 0-100 */
$randomcounter = rand(0,100);
/* Here it looks at the random number and se who there have most chance to win, but still the weakes
have a cchance */
if($player1 >= $randomcounter)
{
echo "player 1 wins";
}
else
{
echo "player 2 wins";
}
%>
--
http://www.php.net/manual/en/function.rand.php
http://master.php.net/manage/user-notes.php?action=edit+30824
http://master.php.net/manage/user-notes.php?action=delete+30824
http://master.php.net/manage/user-notes.php?action=reject+30824