Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
黛琳ghz
2048
提交
e65111f1
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看板
提交
e65111f1
编写于
3月 09, 2014
作者:
G
Gabriele Cirulli
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add win condition
上级
4b3055fc
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
46 addition
and
27 deletion
+46
-27
js/game_manager.js
js/game_manager.js
+6
-3
js/html_actuator.js
js/html_actuator.js
+5
-5
style/main.css
style/main.css
+8
-3
style/main.scss
style/main.scss
+27
-16
未找到文件。
js/game_manager.js
浏览文件 @
e65111f1
...
...
@@ -8,6 +8,7 @@ function GameManager(size, InputManager, Actuator) {
this
.
score
=
0
;
this
.
over
=
false
;
this
.
won
=
false
;
this
.
inputManager
.
on
(
"
move
"
,
this
.
move
.
bind
(
this
));
...
...
@@ -43,7 +44,8 @@ GameManager.prototype.addRandomTile = function () {
GameManager
.
prototype
.
actuate
=
function
()
{
this
.
actuator
.
actuate
(
this
.
grid
,
{
score
:
this
.
score
,
over
:
this
.
over
over
:
this
.
over
,
won
:
this
.
won
});
};
...
...
@@ -69,7 +71,7 @@ GameManager.prototype.move = function (direction) {
// 0: up, 1: right, 2:down, 3: left
var
self
=
this
;
if
(
this
.
over
)
return
;
// Don't do anything if the game's over
if
(
this
.
over
||
this
.
won
)
return
;
// Don't do anything if the game's over
var
cell
,
tile
;
...
...
@@ -104,7 +106,8 @@ GameManager.prototype.move = function (direction) {
// Update the score
self
.
score
+=
merged
.
value
;
// Something's moved for sure
// The mighty 2048 tile
if
(
merged
.
value
===
2048
)
self
.
won
=
true
;
}
else
{
self
.
moveTile
(
tile
,
positions
.
farthest
);
}
...
...
js/html_actuator.js
浏览文件 @
e65111f1
...
...
@@ -22,9 +22,8 @@ HTMLActuator.prototype.actuate = function (grid, metadata) {
self
.
updateScore
(
metadata
.
score
);
if
(
metadata
.
over
)
{
self
.
gameOver
();
}
if
(
metadata
.
over
)
self
.
message
(
false
);
// You lose
if
(
metadata
.
won
)
self
.
message
(
true
);
// You win!
});
};
...
...
@@ -87,6 +86,7 @@ HTMLActuator.prototype.updateScore = function (score) {
}
};
HTMLActuator
.
prototype
.
gameOver
=
function
()
{
this
.
gameContainer
.
classList
.
add
(
"
game-over
"
);
HTMLActuator
.
prototype
.
message
=
function
(
won
)
{
var
type
=
won
?
"
game-won
"
:
"
game-over
"
;
this
.
gameContainer
.
classList
.
add
(
type
);
};
style/main.css
浏览文件 @
e65111f1
...
...
@@ -53,7 +53,7 @@ h1.title {
position
:
relative
;
float
:
right
;
background
:
#bbada0
;
padding
:
15px
3
0px
;
padding
:
15px
2
0px
;
font-size
:
25px
;
height
:
25px
;
line-height
:
47px
;
...
...
@@ -143,13 +143,12 @@ hr {
width
:
500px
;
height
:
500px
;
box-sizing
:
border-box
;
}
.game-container.game-over
:after
{
.game-container.game-over
:after
,
.game-container.game-won
:after
{
position
:
absolute
;
top
:
0
;
right
:
0
;
bottom
:
0
;
left
:
0
;
content
:
"Game over!"
;
display
:
block
;
background
:
rgba
(
238
,
228
,
218
,
0.5
);
text-align
:
center
;
...
...
@@ -162,6 +161,12 @@ hr {
-moz-animation
:
fade-in
800ms
ease
1200ms
;
-webkit-animation-fill-mode
:
both
;
-moz-animation-fill-mode
:
both
;
}
.game-container.game-over
:after
{
content
:
"Game over!"
;
}
.game-container.game-won
:after
{
content
:
"You win!"
;
background
:
rgba
(
237
,
194
,
46
,
0.5
);
color
:
#f9f6f2
;
}
.grid-container
{
position
:
absolute
;
...
...
style/main.scss
浏览文件 @
e65111f1
...
...
@@ -64,7 +64,7 @@ h1.title {
position
:
relative
;
float
:
right
;
background
:
$game-container-background
;
padding
:
15px
3
0px
;
padding
:
15px
2
0px
;
font-size
:
$height
;
height
:
$height
;
line-height
:
$height
+
22px
;
...
...
@@ -156,24 +156,35 @@ hr {
height
:
$field-width
;
box-sizing
:
border-box
;
&
.game-over
,
&
.game-won
{
&
:after
{
position
:
absolute
;
top
:
0
;
right
:
0
;
bottom
:
0
;
left
:
0
;
display
:
block
;
background
:
rgba
(
$tile-color
,
.5
);
text-align
:
center
;
height
:
$field-width
;
line-height
:
$field-width
;
z-index
:
100
;
font-size
:
60px
;
font-weight
:
bold
;
@include
animation
(
fade-in
800ms
ease
$transition-speed
*
12
);
@include
animation-fill-mode
(
both
);
}
}
&
.game-over
:after
{
position
:
absolute
;
top
:
0
;
right
:
0
;
bottom
:
0
;
left
:
0
;
content
:
"Game over!"
;
display
:
block
;
background
:
rgba
(
$tile-color
,
.5
);
text-align
:
center
;
height
:
$field-width
;
line-height
:
$field-width
;
z-index
:
100
;
font-size
:
60px
;
font-weight
:
bold
;
}
@include
animation
(
fade-in
800ms
ease
$transition-speed
*
12
);
@include
animation-fill-mode
(
both
);
&
.game-won
:after
{
content
:
"You win!"
;
background
:
rgba
(
$tile-gold-color
,
.5
);
color
:
$bright-text-color
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录