Copy CodeThe code is as follows:
/*
* Get started with the FireWire Quick Start PHP object-oriented!
*php has become the mainstream of the domestic web developer the preferred development language, its powerful object-oriented easy to make beginners can not find the thoughts, confused!
*, with this article I hope to help beginners, suppose Crossfire with PHP to develop.
* Class 1 and Object
*/
Class Crossfire
{
Public $Category = ' All-in-all '; Types of firearms, 3 select weapon categories
Public $Weapon = ' AK|AWP|M4A1 ';//purchase of weapons, possession of weapons
Public $Flashlight =true;//whether to buy flash bombs
Public $Bomb =false; Purchase a flash in the same condition cannot buy the grenade again
Function Attack ()
{
Attack code $this->weapon; use a weapon
}
function Repair ()
{
Code to repair weapons
}
function Destroy ()
{
The weapon's broken. Auto Destroy code
}
/*
* We think of CF as a class, CF contains the main weapon, secondary weapons, firearms, knives, projectiles, flak jackets, spray pictures and so on.
* Above is a member of the Class property, if the weapon is broken, then we have to repair, repair is the member of the class Method!
* Each firearm has a different power, a different number of bullets, different sizes but all weapons, this is the relationship between classes and objects (the instantiation of a class is the object).
*
*/
function __construct ()
{
Weapon Maintenance $this->repair ();
}
function __destruct ()
{
The weapon exceeds the durable automatic disappearance $this->destroy ();
}
Private Function Buy ()
{
Buy Weapon private Property code
}
Private Function __get ()
{
Call the purchased Weapon code
}
Private Function __set ()
{
Buy a weapon to buy a bullet quantity code
}
Private Function __isset ()
{
Check the amount of money is enough to buy bullets
}
Private Function __unset ()
{
If you die in the middle, automatically drop the weapon
}
}
Class role extends Crossfire
{
The individual role inherits the properties of CF, the role can use the purchase, destroy the above items
Function Attack ()
{
Crossfire::attack ();
$this->weapon= ' awm-a ';
If you change guns in the middle, add the amount of bullets, damage!
}
Final function VIP ()
{
Purchase vip,final keyword is forbidden method and property inheritance!vip is need money purchase, so cannot be inherited!
}
public static $AWM =100;//AWM damage is fixed, so use static
public static function AWM ()
{
Self:: $awm;//awm attack code, self calls static. Overloading of methods
}
Public Function __tostring ()
{
return $this->repair (); Automatic return of weapons maintenance costs
}
}
Interface map
{
Map code, a subclass can inherit only once the parent class, the map is for each player to use, explicit and opinion inheritance is not able to meet the needs of the interface for us to solve the bottleneck!
Public Function Map1 ()
{
Black Town
}
function Map2 ()
{
Transport
}
}
Interface Vipmap extends Map
{
If it is a member, show member map, inherit interface total map
function _vipmap ()
{
VIP Map Color First red
}
function _vipmap1 ()
{
}
}
$CF =new Crossfire ();
Echo $CF->weapon;//out the weapons you have!
/*
* $ Object name = new class name ();
Create a new class we use new, we have created a CF class, $CB is the object of Crossfire!
&nb
Sp Polymorphic applications, abstract classes do not speak, of course, a complete game is impossible from this simple, just to do a metaphor!
*/
$CF 2=clone $CF; Cloning operations means that all players use this class!
?>
The above describes the object-oriented programming with the cross-fire Quick Start PHP object-oriented, including the object-oriented program design aspects, I hope to be interested in PHP tutorial friends helpful.