The development of micro-credit public platform to realize the 2048 game method _php Instance

Source: Internet
Author: User
Tags cdata sprintf

This article describes the development of the micro-credit public platform to achieve the 2048 game method. Share to everyone for your reference. Specifically as follows:

First, 2048 game overview

"2048" is a more popular digital game. The original 2048 first published on the GitHub, the original author is Gabriele Cirulli. It is based on the "1024" and "Small 3 legends" of the play developed by the new digital game.

Then 2048 appeared various versions, take each big platform. The version of Ketchapp, which was ported to iOS by the company, is the hottest, with about 10 million downloads now, the same name as the original. The most notable of the derivative editions is the 20,486-side version, which has ranked the top 200 in board game in 81 countries around the world. Android version is very popular with the "Challenge 2048", its 2.0.0 version also joined the two-person battle. Second, there are more special 2048 Chinese dynasty edition. There are more than 2048 custom editions, you can define text and pictures yourself. "2048" is one of the popular models in iOS.

How to Play:use yourarrow keysto move the tiles. When two tiles and the same number touch, theymerge into one!
Note:this site is the official version of 2048. Can play it on your phone via. All other apps or sites are derivatives or fakes, and should is used with caution.
Created by Gabriele cirulli.based in 1024 by Veewo Studioand conceptually similar to threes by Ashe.

The rules of the game is very simple, each can choose to go up and down in one direction to slide, each slide once, all the number of squares will move towards the direction of the slide, the system will be in the blank place a number of Chaos Number box, the same number of squares in close, collision will add. The system gives the number box is not 2 is 4, the player wants to find a way in this small 16 lattice range to gather out "2048" this number square.

The screen of the game is very simple, the beginning of the whole 16 squares are mostly gray, when the number of players in the puzzle will change color, the overall style is very simple.

In the rules of play is also very simple, the first square will appear in 2 or 4 of these two small numbers, players only need to move up or down one of the direction of the number, all the numbers will be in the direction of the slide, and the slide out of the blank box will randomly appear a number, the same number of collisions will overlap, And then all the way, the constant superposition eventually pieced together 2048 of this number even if successful.

If you are a digital enthusiast, or a gifted mathematical genius, you will be fascinated by it. Even if not a mathematical genius, the average player can also play the game, interested in the download experience.

Now the game is open source, so there's no need for redevelopment,

Full instance code click here to download the site.

Second, micro-trust public platform

Put the 2048 source on your own server and get the game URL.

When the user is concerned, prompt reply 2048 can play this game,

When the user replies 2048, reply The text message, the picture and text with 2048 game links.

The complete code is shown below.

<?php/* Square 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 signature Public Function valid () {$echoStr = $_get["Ech
  Ostr "];
  $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 ($tmpStr = = $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);
     Message type detach switch ($RX _type) {case "event": $result = $this->receiveevent ($POSTOBJ);
    Break
   Case "Text":  $result = $this->receivetext ($POSTOBJ);
   Break
  echo $result;
   }else {echo "";
  Exit
  }///Receive event message Private function Receiveevent ($object) {$content = "";
    Switch ($object->event) {case "subscribe": $content = "Welcome to square Times Studio \ 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;
  
  //Receive text message Private function Receivetext ($object) {$keyword = Trim ($object->content);
   if (Strstr ($keyword, "2048")) {$content = array (); $content [] = Array ("Title" => "2048 games", "Description" => "game rule is very simple, each can choose to go up and down in one direction to slide, each slide once, all the number of squares will move towards the direction of sliding, The system will also be in the blank place a number of random number of squares, the same number of squares in close, collision will add. The system gives the number box is not 2 is 4, the player wants to find a way in this small 16 lattice range to gather out "2048" this number square. "," 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 square times Studio "; } if (Is_array ($content)) {if (Isset ($content [0][' Picurl ')) {$result = $this->transmitnews ($object, $conten
   T);
   }else if (isset ($content [' Musicurl '])) {$result = $this->transmitmusic ($object, $content);
  }else{$result = $this->transmittext ($object, $content); }//Reply text message private function Transmittext ($object, $content) {$xmlTpl = "<xml> <tousername><![ Cdata[%s]]></tousername> <fromusername><! [cdata[%s]]></fromusername> <CreateTime>%s</CreateTime> <msgtype><! [cdata[text]]></msgtype> <content><!
  [cdata[%s]]></content> </xml> ";
  $result = sprintf ($XMLTPL, $object->fromusername, $object->tousername, Time (), $content);
 return $result; //reply to Text message private function transmitnews ($object, $neWsarray) {if (!is_array ($newsArray)) {return; } $ITEMTPL = "<item> <title><! [cdata[%s]]></title> <description><! [cdata[%s]]></description> <picurl><! [cdata[%s]]></picurl> <url><!
  [cdata[%s]]></url> </item> ";
  $item _str = ""; foreach ($newsArray as $item) {$item _str. = sprintf ($ITEMTPL, $item [' Title '], $item [' Description '], $item [' Picurl '], $i
  tem[' URL ']); } $XMLTPL = "<xml> <tousername><! [cdata[%s]]></tousername> <fromusername><! [cdata[%s]]></fromusername> <CreateTime>%s</CreateTime> <msgtype><! [cdata[news]]></msgtype> <ArticleCount>%s</ArticleCount> <Articles> $item _str</
  Articles> </xml> ";
  $result = sprintf ($XMLTPL, $object->fromusername, $object->tousername, Time (), Count ($newsArray));
 return $result; }}?>

I hope this article will help you with the development of your PHP based micro-trust public platform.

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.