Our Scripts Vault contains many game scripts that you can use to create your own game!
Evil begone! The amount of modern high level OOP modularity approach above is so overwhelming that I can only whisper in a faint voice: procedural
ruby on rails and it's overly OOP approach
I have a class set up for my pages and my user. The main benefit of this to me is variable management and time savings. Consider:make_header($somevar1, $somevar2,..... $somevarn);make_menu($somevar, $somevar2, .... $somevarn);..content..make_footer($somevar, $somevar2,..... $somevarn);vs.$Page = new Page;$Page->set_SomeVar1($somevar1);$Page->set_SomeVar2($somevar2);$Page->set_SomeVarn($somevarn);$Page->make_header();$Page->make_menu();..content..$Page->make_footer();You can see how much easier the latter is in terms of managing variables. If the functions, variables, etc change in the first example.... its hell to rework the code. In classes, its many many times easier.In addition, I usually have a class that loads all data for a user. Thus, if I need to see how much gold a user has, I typically do:$User = new User;$User->set_UserID($UserID);$User->load_Standard();$UserGold = $User->Gold;This, IMO, it much easier than having to type:$Result = mysql_query("Select * from Users where UserID = '$UserID' limit 0,1");if(mysql_num_rows($Result) == 0){ exit; }$Row = mysql_fetch_array($Result);$UserGold = $Row['Gold'];This is especially true if you're looking to obtain lots of information about the user on your form script. Imagine having to write individual querys to find Gold, NumUnits, NumWeapons, SkillPoints, etc, etc for multiple action="script.php" pages vs. just pulloing it all out of your class which can auto construct the data you require.PS. I'd be interested in seeing other critique of this approach. I am not a CS guru like many others here
You could just put this into a function file:function stuf(somevar1, some var2, sometf)make_header($somevar1, $somevar2,..... $somevarn);make_menu($somevar, $somevar2, .... $somevarn);make_footer($somevar, $somevar2,..... $somevarn);}then just dostuff(3434,3 343 , 343);
For example, when you use your OS do you have everything all running at once and have it so that if one thing fails it all dies? No, everything is separated up into various modules so that if one fails not everything goes down.
I have several objects, but the most important ones are the Page() class, the Character() class, and the Game() class that ties everything together.
In addition, I usually have a class that loads all data for a user. Thus, if I need to see how much gold a user has, I typically do:$User = new User;$User->set_UserID($UserID);$User->load_Standard();$UserGold = $User->Gold;This, IMO, it much easier than having to type:$Result = mysql_query("Select * from Users where UserID = '$UserID' limit 0,1");if(mysql_num_rows($Result) == 0){ exit; }$Row = mysql_fetch_array($Result);$UserGold = $Row['Gold'];
$Result = mysql_query("Select * from Users where UserID = '$UserID' limit 0,1");$User = mysql_fetch_array($Result,MYSQL_ASSOC);
If there's anything Chris would love it would be this https://github.com/Herzult/SimplePHPEasyPlus Smiley
Code: [Select]$Result = mysql_query("Select * from Users where UserID = '$UserID' limit 0,1");$User = mysql_fetch_array($Result,MYSQL_ASSOC);
$result = mysql_query(sprintf("SELECT * FROM users WHERE UserId = '%s' LIMIT 0,1", mysql_real_escape_string($UserId)));$User = mysql...
$User = Doctrine::getTable('Users')->findOneByUserId($UserId);
// SQLSELECT FROM User uLEFT JOIN Gold as g ON u.id = gold.user_idLEFT JOIN Stats as s ON u.id = stats.user_id...//DoctrineDoctrine_Query()->create() ->select('User u, u.Gold g, u.Stats s')...
$winner = Doctrine::getTable('User')->getOneByUsername('oop');$loser = Doctrine::getTable('User')->getOneByUsername('procedural');$winnings = min($loser->Gold->amount, 50);$winner->Gold->amount += $winnings;$loser->Gold->amount -= $winnings;$winner->save();$loser->save();
$winner->gold += 50;$loser->gold -= 50;