WeChat public platform development and implementation of 2048 game method _ PHP Tutorial

Source: Internet
Author: User
The public platform develops a method to implement 2048 games. The following describes how to develop and implement 2048 games on the public platform: 1. 2048 game overview 2048 is a popular digital game. The original version 2048 was first released on github. The author's public platform developed a 2048 game method.

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.

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.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

/*

Fang times Studio

Copyrights 2014 All Rights Reserved

*/

Define ("TOKEN", "weixin ");

$ WechatObj = new wechatCallbackapiTest ();

If (! Isset ($ _ GET ['echostr']) {

$ WechatObj-> responseMsg ();

} Else {

$ WechatObj-> valid ();

}

Class wechatCallbackapiTest

{

// Verify the signature

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;

}

}

// 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 separation

Switch ($ RX_TYPE)

{

Case "event ":

$ Result = $ this-> receiveEvent ($ postObj );

Break;

Case "text ":

$ Result = $ this-> deleetext ($ postObj );

Break;

}

Echo $ result;

} Else {

Echo "";

Exit;

}

}

// Receives event messages

Private function receiveEvent ($ object)

{

$ Content = "";

Switch ($ object-> Event)

{

Case "subscribe ":

$ Content = "Welcome to fantimes studio \ n reply 2048 to start the 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 text messages

Private function deleetext ($ 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 ";

}

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 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 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;

}

}

?>

Tips: 1. 2048 game overview 2048 is a popular digital game. The original version 2048 was first released on github. the original author...

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.