Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
黛琳ghz
2048
提交
39ebf51c
2048
项目概览
黛琳ghz
/
2048
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
2048
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
39ebf51c
编写于
3月 12, 2014
作者:
G
Gabriele Cirulli
浏览文件
操作
浏览文件
下载
差异文件
fix merge conflict
上级
3dd8f3e5
77654452
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
88 addition
and
17 deletion
+88
-17
index.html
index.html
+5
-1
js/application.js
js/application.js
+1
-1
js/game_manager.js
js/game_manager.js
+11
-4
js/html_actuator.js
js/html_actuator.js
+10
-2
js/local_score_manager.js
js/local_score_manager.js
+31
-0
style/main.css
style/main.css
+15
-6
style/main.scss
style/main.scss
+15
-3
未找到文件。
index.html
浏览文件 @
39ebf51c
...
...
@@ -15,7 +15,10 @@
<div
class=
"container"
>
<div
class=
"heading"
>
<h1
class=
"title"
>
2048
</h1>
<div
class=
"score-container"
>
0
</div>
<div
class=
"scores-container"
>
<div
class=
"score-container"
>
0
</div>
<div
class=
"best-container"
>
0
</div>
</div>
</div>
<p
class=
"game-intro"
>
Join the numbers and get to the
<strong>
2048 tile!
</strong></p>
...
...
@@ -73,6 +76,7 @@
<script
src=
"js/html_actuator.js"
></script>
<script
src=
"js/grid.js"
></script>
<script
src=
"js/tile.js"
></script>
<script
src=
"js/local_score_manager.js"
></script>
<script
src=
"js/game_manager.js"
></script>
<script
src=
"js/application.js"
></script>
</body>
...
...
js/application.js
浏览文件 @
39ebf51c
// Wait till the browser is ready to render the game (avoids glitches)
window
.
requestAnimationFrame
(
function
()
{
var
manager
=
new
GameManager
(
4
,
KeyboardInputManager
,
HTMLActuato
r
);
new
GameManager
(
4
,
KeyboardInputManager
,
HTMLActuator
,
LocalScoreManage
r
);
});
js/game_manager.js
浏览文件 @
39ebf51c
function
GameManager
(
size
,
InputManager
,
Actuator
)
{
function
GameManager
(
size
,
InputManager
,
Actuator
,
ScoreManager
)
{
this
.
size
=
size
;
// Size of the grid
this
.
inputManager
=
new
InputManager
;
this
.
scoreManager
=
new
ScoreManager
;
this
.
actuator
=
new
Actuator
;
this
.
startTiles
=
2
;
...
...
@@ -51,11 +52,17 @@ GameManager.prototype.addRandomTile = function () {
// Sends the updated grid to the actuator
GameManager
.
prototype
.
actuate
=
function
()
{
if
(
this
.
scoreManager
.
get
()
<
this
.
score
)
{
this
.
scoreManager
.
set
(
this
.
score
);
}
this
.
actuator
.
actuate
(
this
.
grid
,
{
score
:
this
.
score
,
over
:
this
.
over
,
won
:
this
.
won
score
:
this
.
score
,
over
:
this
.
over
,
won
:
this
.
won
,
bestScore
:
this
.
scoreManager
.
get
()
});
};
// Save all tile positions and remove merger info
...
...
js/html_actuator.js
浏览文件 @
39ebf51c
function
HTMLActuator
()
{
this
.
tileContainer
=
document
.
querySelector
(
"
.tile-container
"
);
this
.
scoreContainer
=
document
.
querySelector
(
"
.score-container
"
);
this
.
bestContainer
=
document
.
querySelector
(
"
.best-container
"
);
this
.
messageContainer
=
document
.
querySelector
(
"
.game-message
"
);
this
.
score
=
0
;
...
...
@@ -21,6 +22,7 @@ HTMLActuator.prototype.actuate = function (grid, metadata) {
});
self
.
updateScore
(
metadata
.
score
);
self
.
updateBestScore
(
metadata
.
bestScore
);
if
(
metadata
.
over
)
self
.
message
(
false
);
// You lose
if
(
metadata
.
won
)
self
.
message
(
true
);
// You win!
...
...
@@ -103,11 +105,17 @@ HTMLActuator.prototype.updateScore = function (score) {
}
};
HTMLActuator
.
prototype
.
updateBestScore
=
function
(
bestScore
)
{
this
.
bestContainer
.
textContent
=
bestScore
;
};
HTMLActuator
.
prototype
.
message
=
function
(
won
)
{
var
type
=
won
?
"
game-won
"
:
"
game-over
"
;
var
message
=
won
?
"
You win!
"
:
"
Game over!
"
var
message
=
won
?
"
You win!
"
:
"
Game over!
"
;
// if (ga) ga("send", "event", "game", "end", type, this.score);
if
(
typeof
ga
!==
"
undefined
"
)
{
ga
(
"
send
"
,
"
event
"
,
"
game
"
,
"
end
"
,
type
,
this
.
score
);
}
this
.
messageContainer
.
classList
.
add
(
type
);
this
.
messageContainer
.
getElementsByTagName
(
"
p
"
)[
0
].
textContent
=
message
;
...
...
js/local_score_manager.js
0 → 100644
浏览文件 @
39ebf51c
window
.
fakeStorage
=
{
_data
:
{},
setItem
:
function
(
id
,
val
)
{
console
.
log
(
'
set
'
);
return
this
.
_data
[
id
]
=
String
(
val
);
},
getItem
:
function
(
id
)
{
return
this
.
_data
.
hasOwnProperty
(
id
)
?
this
.
_data
[
id
]
:
undefined
;
},
removeItem
:
function
(
id
)
{
return
delete
this
.
_data
[
id
];
},
clear
:
function
()
{
return
this
.
_data
=
{};
}
};
function
LocalScoreManager
()
{
var
localSupported
=
!!
window
.
localStorage
;
this
.
key
=
'
bestScore
'
;
this
.
storage
=
localSupported
?
window
.
localStorage
:
window
.
fakeStorage
;
}
LocalScoreManager
.
prototype
.
get
=
function
()
{
var
score
=
this
.
storage
.
getItem
(
this
.
key
);
if
(
typeof
score
===
"
undefined
"
||
score
===
null
)
{
score
=
0
;
}
return
score
;
};
LocalScoreManager
.
prototype
.
set
=
function
(
score
)
{
this
.
storage
.
setItem
(
this
.
key
,
score
);
};
style/main.css
浏览文件 @
39ebf51c
...
...
@@ -49,9 +49,12 @@ h1.title {
top
:
-50px
;
opacity
:
0
;
}
}
.score-container
{
.scores-container
{
float
:
right
;
}
.score-container
,
.best-container
{
position
:
relative
;
float
:
right
;
display
:
inline-block
;
background
:
#bbada0
;
padding
:
15px
25px
;
font-size
:
25px
;
...
...
@@ -60,19 +63,19 @@ h1.title {
font-weight
:
bold
;
border-radius
:
3px
;
color
:
white
;
margin-top
:
8px
;
}
.score-container
:after
{
margin-top
:
8px
;
text-align
:
center
;
}
.score-container
:after
,
.best-container
:after
{
position
:
absolute
;
width
:
100%
;
top
:
10px
;
left
:
0
;
content
:
"Score"
;
text-transform
:
uppercase
;
font-size
:
13px
;
line-height
:
13px
;
text-align
:
center
;
color
:
#eee4da
;
}
.score-container
.score-addition
{
.score-container
.score-addition
,
.best-container
.score-addition
{
position
:
absolute
;
right
:
30px
;
color
:
red
;
...
...
@@ -86,6 +89,12 @@ h1.title {
-webkit-animation-fill-mode
:
both
;
-moz-animation-fill-mode
:
both
;
}
.score-container
:after
{
content
:
"Score"
;
}
.best-container
:after
{
content
:
"Best"
;
}
p
{
margin-top
:
0
;
margin-bottom
:
10px
;
...
...
style/main.scss
浏览文件 @
39ebf51c
...
...
@@ -58,11 +58,15 @@ h1.title {
}
}
.score-container
{
.scores-container
{
float
:
right
;
}
.score-container
,
.best-container
{
$height
:
25px
;
position
:
relative
;
float
:
right
;
display
:
inline-block
;
background
:
$game-container-background
;
padding
:
15px
25px
;
font-size
:
$height
;
...
...
@@ -72,13 +76,13 @@ h1.title {
border-radius
:
3px
;
color
:
white
;
margin-top
:
8px
;
text-align
:
center
;
&
:after
{
position
:
absolute
;
width
:
100%
;
top
:
10px
;
left
:
0
;
content
:
"Score"
;
text-transform
:
uppercase
;
font-size
:
13px
;
line-height
:
13px
;
...
...
@@ -100,6 +104,14 @@ h1.title {
}
}
.score-container
:after
{
content
:
"Score"
;
}
.best-container
:after
{
content
:
"Best"
}
p
{
margin-top
:
0
;
margin-bottom
:
10px
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录