Getting started with crossing FireWire php object-oriented PHP Tutorial

Source: Internet
Author: User
Tags getting started with php
Get started with php object-oriented through FireWire. Copy the code as follows :? Php ** get started with php through FireWire! * Php has become the preferred development language for mainstream webdeveloper in China, and its powerful object-oriented approach is easy The code is as follows:


/*
* Getting started with php through FireWire!
* Php has become the preferred development language for mainstream web developers in China. its powerful object-oriented language makes it easy for beginners to find their thoughts and get confused!
* This article is helpful to beginners. suppose Crossfire is developed using php.
* Class 1 and objects
*/
Class Crossfire
{
Public $ Category = '1, 2, 3 '; // type of firearms. select three weapons.
Public $ Weapon = 'AK | awp | m4a1'; // purchased Weapon, owned Weapon
Public $ Flashlight = true; // whether to buy a Flashlight
Public $ Bomb = false; // you cannot buy another grenade if you have purchased a flashlight.
Function attack ()
{
// Attack code $ this-> Weapon; use weapons
}
Function repair ()
{
// Code for weapon repair
}
Function destroy ()
{
// Automatically destroy the code when the weapon is broken
}
/*
* We regard cf as a type. cf contains primary weapons, secondary weapons, firearms, knives, bullet objects, bulletproof vests, and spray diagrams ..
* The above are all member attributes in the class. if the weapon is broken, we have to repair it. maintenance is the member method of the class!
* Each type of firearms has different power. different bullets have different sizes but are weapons. this is the relationship between classes and objects (the instantiation result of classes is objects ).
*
*/
Function _ construct ()
{
// Weapon repair $ this-> repair ();
}
Function _ destruct ()
{
// The weapon automatically disappears after its durability $ this-> destroy ();
}
Private function buy ()
{
// Private property code for weapon purchase
}
Private function _ get ()
{
// Call the purchased weapon code
}
Private function _ set ()
{
// Code of the number of purchased bullets for purchased weapons
}
Private function _ isset ()
{
// Check whether the amount of money is enough to buy the number of bullets
}
Private function _ unset ()
{
// Automatically drops the weapon if it dies halfway
}
}
Class role extends Crossfire
{
// The personal role inherits the attributes of cf. The role can purchase and destroy the items above.
Function attack ()
{
Crossfire: attack ();
$ This-> Weapon = 'awm-';
// If you change the gun in the middle, add the number of shells to change the gun, damage!
}
Final function vip ()
{
// Purchase vip. The final keyword is to disable method and property inheritance! Vip needs to be purchased by money, so it cannot be inherited!
}
Public static $ awm = 100; // awm damage is fixed, so static
Public static function awm ()
{
Self: $ awm; // awm attack code. self calls static. Method overloading.
}
Public function _ toString ()
{
Return $ this-> repair (); // automatically returns the weapon repair fee
}
}
Interface map
{
// Map code. a subclass can only inherit the parent class once. maps are used by every player. explicit opinion inheritance cannot meet the requirements. the interface solves the bottleneck for us!
Public function map1 ()
{
// Black Town
}
Function map2 ()
{
// Transport ship
}
}
Interface vipmap extends map
{
// If the member is a member, the member map is displayed. the inherited interface map is displayed.
Function _ vipmap ()
{
// The color of the vip image is red first
}
Function _ vipmap1 ()
{
}
}
$ Cf = new Crossfire ();
Echo $ cf-> Weapon; // outputs the Weapon!
/*
* $ Object name = new class name ();
To create a new class, we use new. we have created a new cf class. $ cb is the Crossfire object!
& Nb
Sp; multi-state applications, abstract classes are not mentioned, of course, a complete game is not simple from then on, just a metaphor!

*/
$ Cf2 = clone $ cf; // This type is used by all players!
?>

The http://www.bkjia.com/PHPjc/325139.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/325139.htmlTechArticle code is as follows :? Php/** get started with php through FireWire! * Php has become the preferred development language for mainstream web developers in China, and its powerful object-oriented method is 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.