View Single Post
Old 01-02-2010, 03:32 AM   #4 (permalink)
Village Idiot
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

There are a number of ways to do this, objects are probably the most efficient. If you are not using objects anywhere else, don't bother with this. But here is how I would do it based off of what I know (this is not tested and is merely for methodical purposes)

Charicter Definitions:
Archer - speed: 10, attack: 15, range: 15, rateOfFire: 10, armor: 3
Swordsman - speed: 15, attack: 25, armor: 50

class.php
PHP Code:
class player
{
function 
_construct{
//pseudo code
foreach(name and value in $playerDefFile)
{
$playerSkills[name]=value;
}
 
public 
$playerName//String
private $playerDefFile;
private 
$playerSkills as array('n/a'=>"speed"'n/a'=>attack'n/a'=>"range"'n/a'=>"rateOfFire"'n/a'=>"armor"'n/a'=>");

archer.def
Code:
speed: 10
attack: 15
range: 15
rateOfFire: 10
armor: 3
swordsman.def
Code:
speed: 15
attack: 25
armor: 50
This will make any non-used attributes equal to 'n/a' so the program can later on see if that attribute can be used. This also gives you a generic base for all your types of players so you can have multiple ones in an game (thus being a generic aproach) and you can add/modify players without any code changes (thus being an explansible one).

ps. I do have some experience in C++ game development, so I've programmed generic players before.
__________________

Village Idiot is offline  
Reply With Quote
The Following User Says Thank You to Village Idiot For This Useful Post:
nefus (01-02-2010)