Get started with the FireWire Quick Start PHP Object-oriented _php tutorial

Source: Internet
Author: User
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;//If purchase *
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!
?>

http://www.bkjia.com/PHPjc/325139.html www.bkjia.com true http://www.bkjia.com/PHPjc/325139.html techarticle Copy the code code as follows: PHP/* * Use the Quick Start PHP object-oriented! *php has become the mainstream web developer in the country's preferred development language, its powerful object-oriented easy ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.