Web版<2048>ゲーム
5092 ワード
ウェブ版<2048>ゲーム、2048ゲームに興味があります.そこで一日かけて、自分で<2048>のようなゲームを書きました.
上源コード:htmlページコード:game.htmlはルートディレクトリにあります
cssコード、styles.css(cssディレクトリの )
jsコード:new 2048.js(jsディレクトリの )
↑(W)/↓(S)/←(A)/→(D)
上源コード:htmlページコード:game.htmlはルートディレクトリにあります
html>
2048
↑(W)/↓(S)/←(A)/→(D)
:00
:
: 0s。
cssコード、styles.css(cssディレクトリの )
.div-round {
display: inline-block;
margin-bottom: 0;
font-size: 14px;
font-weight: normal;
line-height: 1.428571429;
font-family: " ";
text-align: left;
white-space: nowrap;
vertical-align: middle;
background-p_w_picpath: none;
border: 1px solid transparent;
border-radius: 4px;
margin-bottom: 0;
}
#box-main {
width: 420px;
height: 420px;
padding: 5px;
border: 2px solid red;
}
#box0,#box1,#box2,#box3,#box4,#box5,#box6,#box7,#box8,#box9,#boxa,#boxb,#boxc,#boxd,#boxe,#boxf{
height: 68px;
width: 93px;
border: 1px solid red;
float: left;
margin: 5px;
padding-top: 25px;
font-size: 30px;
text-align: center;
background: pink;
font-size: 30px;
}
#game-panel,#score,#max {
width: 630px;
position: relative;
left: 550px;
top: 20px;
}
#keys,#tips,#time,#danger {
width: 200px;
margin: 20px auto;
}
#tips{
width:420px;
float:left;
padding:10px;
border:1px solid red;
background: pink;
}
#keys {
font-size: 84px;
color: #bbbbbb;
}
#danger {
color: #440044;
}
.btn {
display: inline-block;
padding: 6px 12px;
margin-bottom: 0;
font-size: 14px;
font-weight: normal;
line-height: 1.428571429;
text-align: center;
white-space: nowrap;
vertical-align: middle;
cursor: pointer;
background-p_w_picpath: none;
border: 1px solid transparent;
border-radius: 6px;
}
.btn:hover,.btn:focus {
color: #333333;
text-decoration: none;
}
.btn-primary {
color: #ffffff;
background-color: #428bca;
border-color: #357ebd;
z-index: 99;
}
.btn-primary:hover,.btn-primary:focus,.btn-primary:active,.btn-primary.active,.open .dropdown-toggle.btn-primary
{
color: #ffffff;
background-color: #3276b1;
border-color: #285e8e;
}
.btn-primary:active,.btn-primary.active,.open .dropdown-toggle.btn-primary
{
background-p_w_picpath: none;
}
jsコード:new 2048.js(jsディレクトリの )
var locations;
var keys = [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c",
"d", "e", "f" ];
// ,
// colors
var colors = [ "#FFF", "PINK", "GRAY", "#ABCDEF", "#0FF0FF", "#FF0", "#CDF0AB",
"#FEDCBA", "#F0F", "#BBBBBB", "#00F", "#00FF00" ];
var score;//
var max;//
var time;//
var t;
//
// $(function() {
// init();
// });
//
function init() {
t = setInterval(showtime, 1000);
score = 0;
max = 0;
time = 0;
locations = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];
locations[createLocation()] = createFixedNum();
locations[createLocation()] = createFixedNum();
paint();
//
window.onkeydown = function(e) {
var keyCode;
if (!e)
e = window.event;
if (document.all) {
keyCode = e.keyCode;
} else {
keyCode = e.which;
}
// ← A
if (keyCode == 37 || keyCode == 65) {
$("#keys").text("←");
toLeft();
isEnd();
}
// ↑ W
if (keyCode == 38 || keyCode == 87) {
$("#keys").text("↑");
toUp();
isEnd();
}
// → D
if (keyCode == 39 || keyCode == 68) {
$("#keys").text("→");
toRight();
isEnd();
}
// ↓ S
if (keyCode == 40 || keyCode == 83) {
$("#keys").text("↓");
toDown();
isEnd();
}
};
}
function isEnd() {
var f = false;
//
if (locations.indexOf(0) == -1) {// 0
//
// alert(" ~");
$("#danger").text(" ~");
// if(isEndX()){
if (isEndX() && isEndY()) {
clearTimeout(t);
if (window.confirm(" !
: " + score + ";
: " + time
+ "S;
: " + max + "。
?")) {
init();
} else {
window.close();
}
}
} else {
$("#danger").text("");
}
return f;
}
function isEndX() {
//
// ,
var f = false;
var w = new Array();
for (var j = 0; j max) {
max = locations[i];
}
}
$("#score").text(" : " + score);
$("#max").text(" : " + max);
}
//
function createFixedNum() {
// 2/4;
// 2 0.8
return Math.random()
, , , , ! :[email protected]( )