WeChat public platform development and implementation of 2048 game methods _php Tutorial

Source: Internet
Author: User
Tags cdata

Public platform development method to realize 2048 game


Specific as follows:

One, 2048 games overview

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

Then 2048 will appear various versions, take the big platform. The version that was transplanted to iOS by Ketchapp is the hottest, and now has about 10 million downloads, the same name as the original. The best-known version of the derivative version is the 20,486-edged edition, which ranked the top 200 in the board game in 81 countries around the world. Android version is very popular with the "Challenge 2048", its 2.0.0 version has joined the two-man battle. Secondly, there are 2048 Chinese dynasties editions that are more special. There are more than 2048 custom versions, you can define your own text and pictures. "2048" is one of the popular iOS models.

How to Play:use yourarrow keysto move the tiles. When both 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 is derivatives or fakes, and should is used with caution.
Created by Gabriele cirulli.based on 1024x768 by Veewo Studioand conceptually similar to threes by Ashe Vollmer.

The rules of the game is very simple, each time you can choose to swipe up and down in one direction, each slide once, all the digital blocks will move toward the direction of the slide, the system will be in the blank place a number of random squares, the same number of squares in close, collision will be added. The system gives the number box is not 2 is 4, the player should find a way in this small 16-block range of "2048" this number block.

The game screen is very simple, at the beginning of the whole 16 squares are mostly gray, when the player puzzles appear after the number will change the color, the overall style is very simple.

In the rules of play is very simple, the beginning of the box will appear 2 or 4 of these two small numbers, the player only need to move up and down one of the directions to the movement of the numbers, all the numbers will be moving toward the direction of sliding, and the slide out of the blank square will randomly appear a number, the same number will overlap when the collision And then all the time, the constant overlay that finally pieced together the number 2048 was successful.

If you're a digital enthusiast, or a gifted math genius, you'll be fascinated by how you get started. Even if not a mathematical genius, the average player can also play this game, interested in the download experience.

The game is open source, so there's no need to re-develop it.

Second, the public platform

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

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

When the user replies 2048, reply to the text message, the text with 2048 game links.

The complete code is shown below.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

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

/*

Square Double Studio

CopyRight All Rights Reserved

*/

Define ("TOKEN", "Weixin");

$WECHATOBJ = new Wechatcallbackapitest ();

if (!isset ($_get[' echostr ')) {

$WECHATOBJ->responsemsg ();

}else{

$WECHATOBJ->valid ();

}

Class Wechatcallbackapitest

{

Verifying signatures

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->receivetext ($POSTOBJ);

Break

}

echo $result;

}else {

echo "";

Exit

}

}

Receiving event Messages

Private Function Receiveevent ($object)

{

$content = "";

Switch ($object->event)

{

Case "Subscribe":

$content = "Welcome to double 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;

}

Receive text messages

Private Function Receivetext ($object)

{

$keyword = Trim ($object->content);

if (Strstr ($keyword, "2048")) {

$content = Array ();

$content [] = Array ("Title" = "2048 Game", "Description" and "=" game rule is very simple, each can choose to swipe up and down in one direction, each slide once, all the digital blocks will move in the direction of sliding, The system will also appear in the blank place a number of random squares, the same number of squares in close, collision will be added. The system gives the number box is not 2 is 4, the player should find a way in this small 16-block range of "2048" this number block. "," 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 double 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 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 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;

}

}

?>

http://www.bkjia.com/PHPjc/984501.html www.bkjia.com true http://www.bkjia.com/PHPjc/984501.html techarticle public platform development of the implementation of the 2048 game method is as follows: One, 2048 game overview "2048" is a more popular digital game. Original 2048 first published 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.