To get through the FireWire Quick start php object-oriented _php Tips

Source: Internet
Author: User
Tags inheritance
Copy Code code as follows:

<?php
/*
* Use through the FireWire Quick start PHP object-oriented!
*php has become the mainstream web Developer's preferred development language, its powerful object-oriented easy to make beginners can not find the thoughts, confused!
*, with this article hope to help beginners, assuming crossfire with PHP to develop.
* 1 Classes and objects
*/
Class Crossfire
{
Public $Category = ' 1,2,3 '; Types of firearms, 3 categories of weapons of choice
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 on the same condition can't buy grenades again
Function Attack ()
{
Attack code $this->weapon; use the weapon.
}
function Repair ()
{
Code to repair the weapon
}
function Destroy ()
{
Weapons are broken. Automatic Destroy Code
}
/*
* We think of CF as a class with the main weapon, the weapon, the gun, the knife, the projectile, the bulletproof vest, the spray picture, etc.
* The above are the members of the class attribute, if the weapon is broken, then we have to repair, maintenance is the members of the class Method!
* Each gun has a different power, a different number of bullets, the size of different but is a weapon class, this is the relationship between the class and object (the class of the instantiation result is the object).
*
*/
function __construct ()
{
Weapon Maintenance $this->repair ();
}
function __destruct ()
{
The weapon exceeds the durable automatic disappearance $this->destroy ();
}
Private Function Buy ()
{
Buy Weapons private Property code
}
Private Function __get ()
{
Call the purchased Weapon code
}
Private Function __set ()
{
Buy the weapon to buy the bullet quantity code
}
Private Function __isset ()
{
Check the money is enough to buy the number of bullets
}
Private Function __unset ()
{
If you die, you automatically drop your weapon.
}
}
Class role extends Crossfire
{
Personal roles inherit CF properties, roles can be purchased, destroyed above items
Function Attack ()
{
Crossfire::attack ();
$this->weapon= ' awm-a ';
If you change the gun in midstream, add the amount of ammunition to change the gun, hurt!
}
Final function VIP ()
{
Purchase vip,final keyword is prohibited method and property inheritance!vip is required money to buy, 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. Overload of the method
}
Public Function __tostring ()
{
return $this->repair (); Cost of automatic return of weapon repairs
}
}
Interface map
{
Map code, a subclass can only inherit a parent class, the map is for each player to use, the obvious and the idea of 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 the member shows the member map, inherit interface general map
function _vipmap ()
{
VIP Map Color First red
}
function _vipmap1 ()
{
}
}
$CF =new Crossfire ();
echo $CF->weapon;//output weapons!
/*
* $ Object name = new class name ();
Create a new class we use new, we created a CF class, $CB is Crossfire Object!
&nb
Sp Polymorphic applications, abstract classes do not speak, of course, a complete game is not possible from the simple, just to make a metaphor!

*/
$CF 2=clone $CF; Cloning operations means that all players use this class!
?>

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.