Re: Ideas on how to do this without so many ifs
Posted: Sat May 08, 2010 4:44 am
Could you paste your database structure and a data example or two?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?php
$victemquerystring = "SELECT * FROM `character` WHERE charname = '$victem'";
$victemquery = mysql_query($victemquerystring) or die(mysql_error());
$shooterquerystring = "SELECT * FROM `character` WHERE charname = '$charname'";
$shooterquery = mysql_query($shooterquerystring) or die(mysql_error());
$shooterget = mysql_fetch_assoc($shooterquery);
$victemquerystring2 = "SELECT * FROM `character` WHERE charname = '$victem'";
$victemquery2 = mysql_query($victemquerystring2) or die(mysql_error());
$victemget = mysql_fetch_assoc($victemquery2);
//attacker statistics
$cattack = $shooterget['attack'];
$cdefense = $shooterget['defense'];
$cstealth = $shooterget['stealth'];
$chealth = $shooterget['health'];
$conhand = $shooterget['onhand'];
$calive = $shooterget['alive'];
//victim statistics
$vattack = $victemget['attack'];
$vdefense = $victemget['defense'];
$vstealth = $victemget['stealth'];
$vhealth = $victemget['health'];
$vonhand = $victemget['onhand'];
$valive = $victemget['alive'];
if ($cattack > $vdefense) {
$hit = 'true';
}
else {
$hit = 'false';
}
//
if ($vattack > $cdefense) {
$whackback = 'true';
}
else {
$whackbask = 'false';
}
//
if ($hit == true) {
$shotpower = $cattack - $vdefense;
$vdamage = getshotpower($shotpower);
//get type of wound
if ($vdamage > $vhealth) {
$wound = 'Fatal';
$valive = 0;
}
else {
$vhealth = $vhealth - $vdamage;
$wound = getwoundtype($vhealth);
}
}
//
if ($whackback == true) {
$shootpower2 = $vattack - $cdefense;
$cdamage = getshotpower($shootpower);
if ($cdamage > $chealth) {
$wound = 'Fatal';
$calive = 0;
}
else {
$chealth = $chealth - $cdamage;
$wound2 = getwoundtype($chealth);
}
}
//
// set up messages based on scenario
if ($hit == true && $whackback == false) {
$message = 'Your shots find the target.'. ' '.$victem.' '.'has
suffered a'. ' '.$wound.' wound';
echo $message;
}
if ($hit == true && $whackback == true) {
$message = 'Your shot finds the target.'. ' '.$victem.' '.'has
suffered a'. ' '.$wound.' wound, but '.$victem.' does not miss
either. You have suffred a '.$wound2.' wound';
echo $message;
}
if ($hit == false && $whackback == true) {
$message = 'Your shots failt to find the target but '.$victem.'
does not miss. You have suffered a '.$wound2.' wound';
echo $message;
}
if ($hit == false && $whackback == false) {
$message = 'Your shots fail to find the target';
echo $message;
}
} ?>