JS as farm Series 2: Implementation of tool bar and seed package

Source: Internet
Author: User

Click the seed package in the toolbar, select the appropriate seed (cabbage or radish), and add a click seeding event to the Land (not completely implemented yet)

Here, the seed object uses the constructor prototype:

 Constructor prototype

// Seed object
Function Seed (event, seedname ){
This . Mousedownevent = Event | Window. event; // Mouse press event
This . Seedname = Seedname; // Seed name
This . Divseed =   Null ; // Created Seeds
This . Iscanmove =   False ; // Movable or not
This . Iscansow =   False ; // Can I click to sow?
}

// Create seed according to different types
Seed. Prototype. createseed =   Function (){
VaR E =   This . Mousedownevent;
VaR Oseed = Document. createelement ( " Div " );

Oseed. style. Width=   " 51px " ;
Oseed. style. Height =   " 58px " ;
Oseed. style. Position =   " Absolute " ;
Oseed. style. Top = Document.doc umentelement. scrolltop + E. clienty -   25   +   " Px " ; // Note that the scroll bar must be taken into account when the mouse coordinates are obtained.
Oseed. style. Left = Document.doc umentelement. scrollleft + E. clientx -   0   +   " Px " ;
Oseed. style. Background =   " URL ('HTTP: // images.cnblogs.com/cnblogs_com/meiqunfeng/farm/seed "   +   This . Seedname +   " . PNG ') No-repeat " ;

Document. getelementbyid ("Map"). Appendchild (oseed );

This . Divseed = Oseed;
This . Iscanmove =   True ;
This . Iscansow =   True ;
}
// Move the mouse to move the seed
Seed. Prototype. seedmove =   Function (E ){
E = E | Window. event;
This . Divseed. style. Top = Document.doc umentelement. scrolltop + E. clienty -   25 ;
This . Divseed. style. Left = Document.doc umentelement. scrollleft + E. clientx -   0 ;

}
// Seeding
Seed. Prototype. sowseed =   Function (ID ){
// Obtains the left and top of the seeds held by the mouse.
// VaR left = This. divseed. style. Left. substring (0, this. divseed. style. Left. Length-2 );
// VaR Top = This. divseed. style. Top. substring (0, this. divseed. style. Top. Length-2 );
Alert ( " Seeding successful! " );
This . Iscanmove =   False ;
This . Iscansow =   False ;

}

 

 

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.