您现在的位置: 万盛学电脑网 >> 程序编程 >> 脚本专题 >> javascript >> 正文

javascript制作2048游戏

作者:佚名    责任编辑:admin    更新时间:2022-06-22

 这几天玩儿着2048这个游戏,突然心血来潮想练习下写程序的思路,于是乎就模仿做了一个,到目前位置还没有实现动态移动,不是很好看,不过玩儿着自己模仿的小游戏还是蛮爽的,哈哈

   

2048.html

? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 <!DOCTYPE> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>2048</title> <link rel="stylesheet" type="text/css" href="css/2048.css" /> <!-- <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> --> <script type="text/javascript" src="js/2048.js"></script> </head>   <body> <div id="div2048"> <a id="start">tap to start :-)</a> </div> </body> </html>

2048.css

? 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 @charset "utf-8";   #div2048 { width: 500px; height: 500px; background-color: #b8af9e; margin: 0 auto; position: relative; } #start { width: 500px; height: 500px; line-height: 500px; display: block; text-align: center; font-size: 30px; background: #f2b179; color: #FFFFFF; } #div2048 div.tile { margin: 20px 0px 0px 20px; width: 100px; height: 40px; padding: 30px 0; font-size: 40px; line-height: 40px; text-align: center; float: left; } #div2048 div.tile0{ background: #ccc0b2; } #div2048 div.tile2 { color: #7c736a; background: #eee4da; } #div2048 div.tile4 { color: #7c736a; background: #ece0c8; } #div2048 div.tile8 { color: #fff7eb; background: #f2b179; } #div2048 div.tile16 { color:#fff7eb; background:#f59563; } #div2048 div.tile32 { color:#fff7eb; background:#f57c5f; } #div2048 div.tile64 { color:#fff7eb; background:#f65d3b; } #div2048 div.tile128 { color:#fff7eb; background:#edce71; } #div2048 div.tile256 { color:#fff7eb; background:#edcc61; } #div2048 div.tile512 { color:#fff7eb; background:#ecc850; } #div2048 div.tile1024 { color:#fff7eb; background:#edc53f; } #div2048 div.tile2048 { color:#fff7eb; background:#eec22e; }

2048.js

? 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 145 146 147 148 149 150 151 152 153