connect_errno .") " . $conn->connect_error;}/**********Generate random monsters***********/$randMax = getNumRecords("monsters", $conn);$rand = rand(1,$randMax);$monsterA = createMonster($rand, $conn);$rand = rand(1,$randMax);$monsterB = createMonster($rand, $conn);/**********Generate random weapons***********/$randMax = getNumRecords("weapons", $conn);$rand = rand(1,$randMax);$weaponA = createWeapon($rand, $conn);$rand = rand(1,$randMax);$weaponB = createWeapon($rand, $conn);/**********Generate random armors***********/$randMax = getNumRecords("armor", $conn);$rand = rand(1,$randMax);$armorA = createArmor($rand, $conn);$rand = rand(1,$randMax);$armorB = createArmor($rand, $conn);/**********Generate random accessories***********/$randMax = getNumRecords("accessories", $conn);$rand = rand(1,$randMax);$accessoryA = createAccessory($rand, $conn);$rand = rand(1,$randMax);$accessoryB = createAccessory($rand, $conn);/***************Calculate bonuses for OUTPUT*******************/if ($accessoryA->HP > 0 || $accessoryA->HP < 0) { $operator = getOperator($accessoryA->HP); $hpBonusA = "(" . $operator; $hpBonusA .= $accessoryA->HP; $hpBonusA .= ")";}if ($accessoryB->HP > 0 || $accessoryB->HP < 0) { $operator = getOperator($accessoryB->HP); $hpBonusB = "(" . $operator; $hpBonusB .= $accessoryB->HP; $hpBonusB .= ")";}if ($accessoryA->SPD > 0) { $spdBonusA = "(+"; $spdBonusA .= $accessoryA->SPD; $spdBonusA .= ")";}if ($accessoryB->SPD > 0) { $spdBonusB = "(+"; $spdBonusB .= $accessoryB->SPD; $spdBonusB .= ")";}$totalATKbonusA = $weaponA->ATK + $accessoryA->ATK;$totalATKbonusB = $weaponB->ATK + $accessoryB->ATK;$totalDEFbonusA = $armorA->DEF + $accessoryA->DEF;$totalDEFbonusB = $armorB->DEF + $accessoryB->DEF;$operator = getOperator($totalATKbonusA);$atkBonusA = "(" . $operator;$atkBonusA .= $totalATKbonusA;$atkBonusA .= ")";$operator = getOperator($totalATKbonusB);$atkBonusB = "(" . $operator;$atkBonusB .= $totalATKbonusB;$atkBonusB .= ")";$operator = getOperator($totalDEFbonusA);$defBonusA = "(" . $operator;$defBonusA .= $totalDEFbonusA;$defBonusA .= ")";$operator = getOperator($totalDEFbonusB);$defBonusB = "(" . $operator;$defBonusB .= $totalDEFbonusB;$defBonusB .= ")";/***************Calculate persistence variables************/$totalHPa = $monsterA->HP + $accessoryA->HP;$totalHPb = $monsterB->HP + $accessoryB->HP;$totalATKa = $totalATKbonusA + $monsterA->ATK;$totalATKb = $totalATKbonusB + $monsterB->ATK;$totalDEFa = $totalDEFbonusA + $monsterA->DEF;$totalDEFb = $totalDEFbonusB + $monsterB->DEF;$totalSPDa = $monsterA->SPD + $accessoryA->SPD;$totalSPDb = $monsterB->SPD + $accessoryB->SPD;/***************TABLE OUTPUT*************************/print << | $monsterA->name | $monsterB->name |
HP | $monsterA->HP $hpBonusA | $monsterB->HP $hpBonusB |
ATK | $monsterA->ATK $atkBonusA | $monsterB->ATK $atkBonusB |
DEF | $monsterA->DEF $defBonusA | $monsterB->DEF $defBonusB |
SPD | $monsterA->SPD $spdBonusA | $monsterB->SPD $spdBonusB |
Special | $monsterA->special | $monsterB->special |
Weapon | $weaponA->name | $weaponB->name |
Armor | $armorA->name | $armorB->name |
Accessory | $accessoryA->name | $accessoryB->name |
You choose: | | |
Current cash: $$cash HERE;/*****************************FUNCTIONS***********************************//**********getNumRecords()*********************Calculates the number of records in any given table**and returns the result. This essentially calculates****the max range for my random numbers*********************************************************/function getNumRecords($table, $conn) { $sql = "SELECT * FROM " . $table; $result = mysqli_query($conn, $sql); $numRecords = mysqli_num_rows($result); return $numRecords;}/**********createMonster()*********************Grabs a monster from the database and stores its***values, then returns the values as a custom class.************************************************/function createMonster($random, $conn) { $sql = "SELECT name, hitpoints, attack, defense, speed, special FROM monsters WHERE monstersID = " . $random; $rs = mysqli_query($conn, $sql); $row = mysqli_fetch_row($rs); $theMonster->name = $row[0]; $theMonster->HP = $row[1]; $theMonster->ATK = $row[2]; $theMonster->DEF = $row[3]; $theMonster->SPD = $row[4]; $theMonster->special = $row[5]; return $theMonster;}/**********createWeapon()*********************Grabs a weapon from the database and stores its***values, then returns the values as a custom class.************************************************/function createWeapon($random, $conn) { $sql = "SELECT name, attack FROM weapons WHERE weaponsID = " . $random; $rs = mysqli_query($conn, $sql); $row = mysqli_fetch_row($rs); $theWeapon->name = $row[0]; $theWeapon->ATK = $row[1]; return $theWeapon;}/**********createArmor()***********************Grabs an armor from the database and stores its****values, then returns the values as a custom class.************************************************/function createArmor($random, $conn) { $sql = "SELECT name, defense FROM armor WHERE armorID = " . $random; $rs = mysqli_query($conn, $sql); $row = mysqli_fetch_row($rs); $theArmor->name = $row[0]; $theArmor->DEF = $row[1]; return $theArmor;}/**********createAccessory()*********************Grabs an accessory from the database and stores its**values, then returns the values as a custom class.*************************************************/function createAccessory($random, $conn) { $sql = "SELECT name, hitpoints, attack, defense, speed FROM accessories WHERE accessoriesID = " . $random; $rs = mysqli_query($conn, $sql); $row = mysqli_fetch_row($rs); $theAccessory->name = $row[0]; $theAccessory->HP = $row[1]; $theAccessory->ATK = $row[2]; $theAccessory->DEF = $row[3]; $theAccessory->SPD = $row[4]; return $theAccessory;}/*********getOperator()***********************Simple function that returns the correct operator**based on the value passed to it.************************************************************/function getOperator($value) { if ($value > 0) { $theOperator = "+"; } else { $theOperator = ""; } return $theOperator;}?>
