2016.8.07 a self-deceiving code (easy to understand functions and objects)

Source: Internet
Author: User

Before the object Foundation, I said the object is like a game character, this character has the blood bar, the Magic Bar, the physical attack and so on basic attribute, also has the attack and so on basic method.

Here, I will write a small example, is to deceive oneself. Really, casual play is good, if you want to seriously do a turn-based game, you can refer to my code.

Do not say, directly on the code:

     functionPerson (o) { This. name= O.name;//name             This. profession= O.profession;//Career             This. rank= O.rank;//level             This. blood= O.blood;//Blood Strips             This. margic= O.margic;//Blue Bar             This. physics_attack= O.physics_attack;//Physical Attack             This. margic_attack= O.margic_attack;//Magical Attack             This. physics_defense= O.physics_defense;//Physical Defense Force             This. margic_defense= O.margic_defense;//Magical Defensive Power             This. speed= O.speed;//Speed             This. attribute=function() {Console.log ( This. name+ "Basic properties:"); Console.log ("Occupation:" + This. profession+ "Level:" + This. rank+ "Blood bar:" + This. blood+ "Blue bar:" + This. margic+ "Physical attack:" + This. physics_attack+ "Magical attack:" + This. margic_attack+ "Physical Defense:" + This. physics_defense+ "Magical Defense:" + This. margic_defense+ "Speed:" + This. speed);}//Basic Properties Display             This. physics_attack_two=function(both) {varhurt= This. physics_attack-two.physics_defense>0? This. physics_attack-two.physics_defense:0; Two.blood-=hurt; Console.log ( This. name+ "Fist attacked" +two.name); Console.log ( ThisThe physical attack of the. name+ "is" + ThisThe physical defense of the. physics_attack+ "," +two.name+ "is" +two.physics_defense); Console.log ("So," +two.name+ "suffered" +hurt+ "damage");}//physical Attack (WHO)             This. margic_attack_two=function(both) {varhurt=two.margic_attack- This. margic_defense>0?two.margic_attack- This. margic_defense:0; Two.blood-=hurt; Console.log ( This. name+ "Magical attack" +two.name) Console.log ( ThisThe physical attack of the. name+ "is" + ThisThe physical defense of the. margic_attack+ "," +two.name+ "is" +two.margic_defense); Console.log ("So," +two.name+ "suffered" +hurt+ "damage");}//Magical Attack (WHO)        }         varlizhiyang=NewPerson ({name:"Zhang San", Profession:"God stick", rank:1, Blood:50, Margic:200, Physics_attack:100, Margic_attack:20, Physics_defense:0, Margic_defense:10, Speed:1        }); varchenan=NewPerson ({name:"Harry", Profession:"Peace Person", rank:1, Blood:5000, Margic:200, Physics_attack:10, Margic_attack:20, Physics_defense:10, Margic_defense:10, Speed:1        });        Lizhiyang.attribute ();        Chenan.attribute ();        Lizhiyang.physics_attack_two (Chenan);        Lizhiyang.margic_attack_two (Chenan);        Lizhiyang.attribute (); Chenan.attribute ();

If you think the code is too messy, you can not see, but I suggest or look at it, after all, I personally think that this code is useful for understanding functions and objects.

If you want to expand into a turn-based game, I can only give a suggestion: the character object can have the skill object (the skill object has the bloody battle Happo, the Phoenix dance nine days and so on skill object, the bloody battle Octagon has the attack, magical attack and so on property).

If you really want to do, please talk about me privately, we grow together, and by the way to explore life.

2016.8.07 a self-deceiving code (easy to understand functions and objects)

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.