WeChat public platform development and implementation of 2048 game methods, public 2048_PHP tutorial-php Tutorial

Source: Internet
Author: User
Tags cdata
The public platform developed 2048 game methods, and 2048 public. This article describes how to develop and implement 2048 games on the public platform. Share it with you for your reference. The details are as follows: the public platform developed a method to implement 2048 games, and the public 2048

This article describes how to develop and implement 2048 games on the public platform. Share it with you for your reference. The details are as follows:

I. 2048 game overview

2048 is a popular digital game. The original version 2048 was first released on github, and the original author was Gabriel Cirulli. It is a new digital game developed based on "1024" and "Little 3 Legend.

Later, various versions were available in 2048, using various platforms. The versions transplanted from Ketchapp to IOS are the most popular, with about 10 million downloads. Their names are exactly the same as those of the original version. The most famous derivative version is the 2048 hexagonal version, which ranked among the top 200 board games in 81 countries around the world. The Android version is very popular with challenge 2048, and its version 2.0.0 has also joined the dual-player competition. The second most special version is the 2048 Chinese dynasty version. The 2048 custom version allows you to customize text and images. 2048 is a popular version in IOS.

How to play: Use yourarrow keysto move the tiles. When two tiles with the same number touch, theymerge into one!
NOTE: This site is the official version of 2048. You can play it on your phone via. All other apps or sites are derivatives or fakes, and shoshould be used with caution.
Created by Gabriel Cirulli. Based on 1024 by Veewo Studioand conceptually similar to Threes by Ashe Vollmer.

The game rule is simple. you can choose to slide in one of the top, bottom, and left directions. every time you slide, all the digital squares will move closer to the sliding direction, the system will also display a number square in a random number in the blank area. the blocks with the same number will be added when they move closer and collide. The number square given by the system is either 2 or 4. players must find a way to generate the "2048" number square in this small 16-frame range.

The screen of the game is very simple. in the first place, most of the 16 squares were gray. when the number of players appeared in the puzzle, the color changed and the overall style was very simple.

The gameplay rules are also very simple. at the beginning, there will be two or four numbers in the square. players only need to move the numbers in one of the top, bottom, and left directions, all the numbers will move closer to the sliding direction, and a random number will appear in the sliding blank square. when the same number is collided, it will move closer together and keep doing this, the continuous superposition of the final piece of the number 2048 is successful.

If you are a digital enthusiast or a talented mathematical genius, you will be fascinated when you get started. Even if it is not a mathematical genius, a general player can also play this game. if you are interested, download and experience it.

Currently, this game is open-source, so it does not need to be re-developed,

Click here to download the complete instance code.

II. public platform

Put the 2048 source code on your server to get the game url.

When a user pays attention to the game, he or she is prompted to reply to "2048" to play the game,

When a user replies 2048, the user replies to the text message, which contains a 2048 game link.

The complete code is as follows.

<? Php/* Fang times studio CopyRight 2014 All Rights Reserved */define ("TOKEN", "weixin"); $ wechatObj = new wechatCallbackapiTest (); if (! Isset ($ _ GET ['echostr']) {$ wechatObj-> responseMsg ();} else {$ wechatObj-> valid ();} class wechatCallbackapiTest {// verify the public function valid () {$ echoStr =$ _ GET ["echostr"]; $ signature =$ _ GET ["signature"]; $ timestamp = $ _ GET ["timestamp"]; $ nonce = $ _ GET ["nonce"]; $ token = TOKEN; $ tmpArr = array ($ token, $ timestamp, $ nonce); sort ($ tmpArr); $ tmpStr = implode ($ tmpArr); $ tmpStr = sha1 ($ tmpStr); if ($ tmpSt R ==$ signature) {echo $ echoStr; exit ;}// response message public function responseMsg () {$ postStr = $ GLOBALS ["HTTP_RAW_POST_DATA"]; if (! Empty ($ postStr) {$ postObj = simplexml_load_string ($ postStr, 'simplexmlelement', LIBXML_NOCDATA); $ RX_TYPE = trim ($ postObj-> MsgType ); // switch ($ RX_TYPE) {case "event": $ result = $ this-> receiveEvent ($ postObj); break; case "text ": $ result = $ this-> deleetext ($ postObj); break;} echo $ result;} else {echo ""; exit ;}} // receive event message private function receiveEvent ($ object) {$ content = ""; switch ($ Object-> Event) {case "subscribe": $ content = "Welcome to fantimes studio \ n reply 2048 start game"; break;} if (is_array ($ content )) {if (isset ($ content [0]) {$ result = $ this-> transmitNews ($ object, $ content );} else if (isset ($ content ['musicurl']) {$ result = $ this-> transmitMusic ($ object, $ content );}} else {$ result = $ this-> transmitText ($ object, $ content);} return $ result;} // receives the text message private function receiveText ($ object ){ $ Keyword = trim ($ object-> Content); if (strstr ($ keyword, "2048") {$ content = array (); $ content [] = array ("Title" => "2048 games", "Description" => "The game rule is simple. you can choose one of the top, bottom, and left to slide each time, every time you slide, all the digital blocks will move closer to the sliding direction, and the system will also display a number block in the blank space, blocks with the same number are added when they are close together and collided. The number square given by the system is either 2 or 4. players must find a way to generate the "2048" number square in this small 16-frame range. "," PicUrl "=>" http://img.laohu.com/www/201403/27/1395908994962.png "," Url "=>" http://gabrielecirulli.github.io/2048/ ");} Else {$ content = date (" Y-m-d H: I: s ", time ()). "\ n technical support Fang times studio";} if (is_array ($ content) {if (isset ($ content [0] ['picurl']) {$ result = $ this-> transmitNews ($ object, $ content);} else if (isset ($ content ['musicurl']) {$ result = $ this-> transmitMusic ($ object, $ content) ;}} else {$ result = $ this-> transmitText ($ object, $ content );}} // reply to the text message private function transmitText ($ object, $ content) {$ xmlTpl ="
 
  %s
  
  %s
  
  
   
% S
  
  text
  
  %s
  
 "; $ Result = sprintf ($ xmlTpl, $ object-> FromUserName, $ object-> ToUserName, time (), $ content); return $ result ;} // reply to the text message private function transmitNews ($ object, $ newsArray) {if (! Is_array ($ newsArray) {return;} $ itemTpl ="
   
  <! [CDATA [% s]>  
  %s
    
  %s
    
  %s
   
 "; $ Item_str =" "; foreach ($ newsArray as $ item) {$ item_str. = sprintf ($ itemTpl, $ item ['title'], $ item ['description'], $ item ['picurl'], $ item ['URL']);} $ xmlTpl ="
 
  %s
  
  %s
  
  
   
% S
  
  news
  % S$ Item_str
 "; $ Result = sprintf ($ xmlTpl, $ object-> FromUserName, $ object-> ToUserName, time (), count ($ newsArray )); return $ result ;}?>

I hope this article will help you develop php-based public platforms.

The example in this article describes how to develop and implement 2048 games on the public platform. Share it with you for your reference. Details :...

Related Article

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.