This article mainly introduces the relevant information about JavaScript-based serialization games. For more information, see those who want to see them on a daily basis, don't I connect two identical images together? I can write one myself.
Write a file using Javascript and host it on github. view the Online DEMO address: Open
Final:
What should I consider before writing a link?
1: How can I determine whether two elements can be connected? I was wondering at the beginning. For details, refer to here: open;
2: How to choose the template engine? I used the template of the bottom-line library because the syntax is simple. I originally wanted to use Handlebars, but this is a bit big, and the bottom line Library also provides many common tool methods (• yunω • ́) y;
3, canvas has not been carefully studied;
4: How can we achieve the effect of line connection when two elements are connected? If dom is used for implementation, images need to be used. When the elements are connected, images are located in the connection path. You can also use canvas to directly draw the effect of the connection. I select the latter;
Because I did not consider low browsers, I used the zeptoJS library and referenced bootstrap based on my habits;
Three major constructor functions are used, including Data, View, and Score;
The View structure is as follows, which rarely includes event binding, interface generation, and drawing effect when two identical elements disappear:
View
/*** @ Desc generate map Based on Data **/renderHTML: function/*** @ desc Interface main event binding * @ return this; **/bindEvents: function/*** @ desc tool method, which is used for plotting on the canvas. * @ param [{x: 0, y: 0}, {x: 1, y: 1 }, {x: 2, y: 2}, {x: 3, y: 3}] An array, which is automatically repainted. **/showSparkLine: the template of the function tbody element is as follows: