user.class.php
<?php
//RNG constants
define(MIN_STAT, 10);
define(MIN_STAT, 20);
//Character creation constants
define(STARTING_LEVEL, 1);
define(STARTING_XP, 0);
define(STARTING_MAX_XP, 200);
class User
{
private $charLevel,
$charName,
$charRace,
$charClass,
$curXP,
$maxXP,
$curHP,
$maxHP,
$curMana,
$maxMana,
$curStam,
$maxStam,
$strength,
$intelligence,
$dexterity,
$endurance,
$wisdom;
public function __construct($charName, $charRace, $charClass)
{
$this->create_char($charName, $charRace, $charClass);
}
public function set($value, $property)
{
$this->set_value($value, $property);
}
public function get($property)
{
return $this->get_value($property);
}
public function stats()
{
$stats = $this->get_stats();
return $stats;
}
private function create_char($charName, $charRace, $charClass)
{
$this->charLevel = STARTING_LEVEL;
$this->charName = $charName;
$this->charRace = $charRace;
$this->charClass = $charClass;
$this->curXP = STARTING_XP;
$this->maxXP = STARTING_MAX_XP;
$this->strength = mt_rand(MIN_STAT, MAX_STAT);
$this->intelligence = mt_rand(MIN_STAT, MAX_STAT);
$this->dexterity = mt_rand(MIN_STAT, MAX_STAT);
$this->endurance = mt_rand(MIN_STAT, MAX_STAT);
$this->wisdom = mt_rand(MIN_STAT, MAX_STAT);
echo $this->strength;
echo $this->intelligence;
echo $this->dexterity;
echo $this->endurance;
echo $this->wisdom;
$this->maxHP = (($this->endurance * $this->strength)*(10^2)/2);
$this->curHP = $this->maxHP;
$this->maxMana = (($this->intelligence * $this->wisdom)*(6^2)/2);
$this->curMana = $this->maxMana;
$this->maxStam = (($this->endurance * $this->dexterity)*(4^2)/2);
$this->curStam = $this->maxStam;
}
private function set_value($value, $property)
{
switch($property)
{
case 'charLevel': $this->charLevel = $value; break;
case 'charRace': $this->charRace = $value; break;
case 'charClass': $this->charClass = $value; break;
case 'curXP': $this->curXP = $value; break;
case 'maxXP': $this->maxXP = $value; break;
case 'curHP': $this->curHP = $value; break;
case 'maxHP': $this->maxHP = $value; break;
case 'curMana': $this->curMana = $value; break;
case 'maxMana': $this->maxMana = $value; break;
case 'curStam': $this->curStam = $value; break;
case 'maxStam': $this->maxStam = $value; break;
case 'strength': $this->strength = $value; break;
case 'intelligence': $this->intelligence = $value; break;
case 'dexterity': $this->dexterity = $value; break;
case 'endurance': $this->endurance = $value; break;
case 'wisdom': $this->wisdom = $value; break;
case 'level_up': $this->charLevel += $value; break;
}
$this->register();
}
private function get_value($property)
{
switch($property)
{
case 'charLevel': return isset($this->charLevel) ? $this->charLevel: null; break;
case 'charRace': return isset($this->charRace) ? $this->charRace: null; break;
case 'charClass': return isset($this->charClass) ? $this->charClass: null; break;
case 'curXP': return isset($this->curXP) ? $this->curXP: null; break;
case 'maxXP': return isset($this->maxXP) ? $this->maxXP: null; break;
case 'curHP': return isset($this->curHP) ? $this->curHP: null; break;
case 'maxHP': return isset($this->maxHP) ? $this->maxHP: null; break;
case 'curMana': return isset($this->curMana) ? $this->curMana: null; break;
case 'maxMana': return isset($this->maxMana) ? $this->maxMana: null; break;
case 'curStam': return isset($this->curStam) ? $this->curStam: null; break;
case 'maxStam': return isset($this->maxStam) ? $this->maxStam: null; break;
case 'strength': return isset($this->strength) ? $this->strength : null; break;
case 'intelligence': return isset($this->intelligence) ? $this->intelligence : null; break;
case 'dexterity': return isset($this->dexterity) ? $this->dexterity : null; break;
case 'endurance': return isset($this->endurance) ? $this->endurance : null; break;
case 'wisdom': return isset($this->wisdom) ? $this->wisdom : null; break;
}
}
private function calculate_xp($curXP, $maxXP, $charLevel)
{
$multiplier = STARTING_MAX_XP;
for ( ;$curXP > $maxXP; )
{
set_value(1, 'level_up');
$charLevel = get_value('charLevel');
$maxXP = (($multiplier*$charLevel) + (2^$charLevel));
set_value($maxXP, 'maxXP');
}
}
private function get_stats()
{
echo '<br> Level: ',$this->charLevel;
echo '<br> Name: ',$this->charName;
echo '<br> Race: ',$this->charRace;
echo '<br> Class: ',$this->charClass;
echo '<br> HP: ',$this->maxHP;
echo '/',$this->curHP;
echo '<br> Mana: ',$this->maxMana;
echo '/',$this->curMana;
echo '<br> Stamina: ',$this->maxStam;
echo '/',$this->curStam;
echo '<br> XP: ',$this->curXP;
echo '/',$this->maxXP;
echo '<br> Strength: ',$this->strength;
echo '<br> Intelligence: ',$this->intelligence;
echo '<br> Dexterity: ',$this->dexterity;
echo '<br> Endurance: ',$this->endurance;
echo '<br> Wisdom: ',$this->wisdom;
}
private function register_info()
{
//DB Info goes here
}
}
?>
create_character.php
<?php require 'user.class.php'; $user = new User($_POST['charName'], $_POST['charRace'], $_POST['charClass']); $user->stats(); ?>
index.php
<html>
<body>
<form name="character_creation" action="create_character.php" method="post">
Character Name: <input type="text" name="charName" />
Race: <input type="text" name="charRace" />
Class: <input type="text" name="charClass" />
<input type="submit" value="Create Character" />
</form>
</body>
</html>
<?php
//insert code here
?>
Everything else seems to be working BUT the mt_rand function. I really don't see why it would not be working. Any suggestions?

New Topic/Question
Reply



MultiQuote





|