欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信公眾平臺(tái)開(kāi)發(fā)實(shí)現(xiàn)2048游戲的方法

 更新時(shí)間:2015年04月15日 16:22:44   作者:zbtree  
這篇文章主要介紹了微信公眾平臺(tái)開(kāi)發(fā)實(shí)現(xiàn)2048游戲的方法,較為詳細(xì)的講述的2048游戲的原理以及微信公眾平臺(tái)開(kāi)發(fā)2048游戲的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了微信公眾平臺(tái)開(kāi)發(fā)實(shí)現(xiàn)2048游戲的方法。分享給大家供大家參考。具體如下:

一、2048游戲概述

《2048》是比較流行的一款數(shù)字游戲。原版2048首先在github上發(fā)布,原作者是Gabriele Cirulli。它是基于《1024》和《小3傳奇》的玩法開(kāi)發(fā)而成的新型數(shù)字游戲 。

隨后2048便出現(xiàn)各種版本,走各大平臺(tái)。由Ketchapp公司移植到IOS的版本最為火熱,現(xiàn)在約有1000萬(wàn)下載,其名字跟原版一模一樣。衍生版中最出名的是《2048六邊形》版本,先后在全球81個(gè)國(guó)家中的board game中排進(jìn)了前200。安卓版非?;鸨挠小短魬?zhàn)2048》,其2.0.0版以后還加入了雙人對(duì)戰(zhàn)。其次比較特別的有2048中國(guó)朝代版。更有2048自定義版,可以自己定義文字和圖片?!?048》是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 should be used with caution.
Created by Gabriele Cirulli.Based on 1024 by Veewo Studioand conceptually similar to Threes by Ashe Vollmer.

游戲規(guī)則很簡(jiǎn)單,每次可以選擇上下左右其中一個(gè)方向去滑動(dòng),每滑動(dòng)一次,所有的數(shù)字方塊都會(huì)往滑動(dòng)的方向靠攏外,系統(tǒng)也會(huì)在空白的地方亂數(shù)出現(xiàn)一個(gè)數(shù)字方塊,相同數(shù)字的方塊在靠攏、相撞時(shí)會(huì)相加。系統(tǒng)給予的數(shù)字方塊不是2就是4,玩家要想辦法在這小小的16格范圍中湊出“2048”這個(gè)數(shù)字方塊。

游戲的畫(huà)面很簡(jiǎn)單,一開(kāi)始整體16個(gè)方格大部分都是灰色的,當(dāng)玩家拼圖出現(xiàn)數(shù)字之后就會(huì)改變顏色,整體格調(diào)很是簡(jiǎn)單。

在玩法規(guī)則也非常的簡(jiǎn)單,一開(kāi)始方格內(nèi)會(huì)出現(xiàn)2或者4等這兩個(gè)小數(shù)字,玩家只需要上下左右其中一個(gè)方向來(lái)移動(dòng)出現(xiàn)的數(shù)字,所有的數(shù)字就會(huì)向滑動(dòng)的方向靠攏,而滑出的空白方塊就會(huì)隨機(jī)出現(xiàn)一個(gè)數(shù)字,相同的數(shù)字相撞時(shí)會(huì)疊加靠攏,然后一直這樣,不斷的疊加最終拼湊出2048這個(gè)數(shù)字就算成功。

如果你是一個(gè)數(shù)字愛(ài)好者,或者是比較有天賦的數(shù)學(xué)天才,一上手便會(huì)為之著迷。就算不是數(shù)學(xué)天才,一般的玩家也能夠玩轉(zhuǎn)這款游戲,感興趣的話就去下載體驗(yàn)一番。

目前這個(gè)游戲是開(kāi)源的,所以不需要再來(lái)重新開(kāi)發(fā),

完整實(shí)例代碼點(diǎn)擊此處本站下載。

二、微信公眾平臺(tái)

把2048源碼放到自己的服務(wù)器上,得到游戲url。

當(dāng)用戶關(guān)注時(shí),提示回復(fù)2048可玩這個(gè)游戲,

當(dāng)用戶回復(fù)2048時(shí),回復(fù)圖文消息,圖文中帶2048游戲鏈接。

完整代碼如下所示。

<?php
/*
 方倍工作室
 CopyRight 2014 All Rights Reserved
*/
define("TOKEN", "weixin");
$wechatObj = new wechatCallbackapiTest();
if (!isset($_GET['echostr'])) {
 $wechatObj->responseMsg();
}else{
 $wechatObj->valid();
}
class wechatCallbackapiTest
{
 //驗(yàn)證簽名
 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($tmpStr == $signature){
   echo $echoStr;
   exit;
  }
 }
 //響應(yīng)消息
 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);
    
   //消息類(lèi)型分離
   switch ($RX_TYPE)
   {
    case "event":
     $result = $this->receiveEvent($postObj);
     break;
    case "text":
     $result = $this->receiveText($postObj);
     break;
   }
   echo $result;
  }else {
   echo "";
   exit;
  }
 }
 //接收事件消息
 private function receiveEvent($object)
 {
  $content = "";
  switch ($object->Event)
  {
   case "subscribe":
    $content = "歡迎關(guān)注方倍工作室\n回復(fù) 2048 開(kāi)始游戲";
    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;
 }
 //接收文本消息
 private function receiveText($object)
 {
  $keyword = trim($object->Content);
  
  if (strstr($keyword, "2048")){
   $content = array();
   $content[] = array("Title"=>"2048游戲", "Description"=>"游戲規(guī)則很簡(jiǎn)單,每次可以選擇上下左右其中一個(gè)方向去滑動(dòng),每滑動(dòng)一次,所有的數(shù)字方塊都會(huì)往滑動(dòng)的方向靠攏外,系統(tǒng)也會(huì)在空白的地方亂數(shù)出現(xiàn)一個(gè)數(shù)字方塊,相同數(shù)字的方塊在靠攏、相撞時(shí)會(huì)相加。系統(tǒng)給予的數(shù)字方塊不是2就是4,玩家要想辦法在這小小的16格范圍中湊出“2048”這個(gè)數(shù)字方塊。", "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技術(shù)支持 方倍工作室";
  }
  
  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);
  }
 }

 //回復(fù)文本消息
 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;
 }

 //回復(fù)圖文消息
 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'], $item['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;
 }
}
?>

希望本文所述對(duì)大家基于php的微信公眾平臺(tái)開(kāi)發(fā)有所幫助。

相關(guān)文章

最新評(píng)論