Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
黛琳ghz
2048
提交
02b66ccb
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看板
提交
02b66ccb
编写于
3月 10, 2014
作者:
G
Gabriele Cirulli
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add retry button
上级
2c066a55
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
111 addition
and
48 deletion
+111
-48
index.html
index.html
+5
-0
js/game_manager.js
js/game_manager.js
+14
-5
js/html_actuator.js
js/html_actuator.js
+19
-6
js/keyboard_input_manager.js
js/keyboard_input_manager.js
+6
-0
style/main.css
style/main.css
+26
-14
style/main.scss
style/main.scss
+41
-23
未找到文件。
index.html
浏览文件 @
02b66ccb
...
@@ -22,6 +22,11 @@
...
@@ -22,6 +22,11 @@
<p
class=
"game-intro"
>
Join the numbers and get to the
<strong>
2048 tile!
</strong></p>
<p
class=
"game-intro"
>
Join the numbers and get to the
<strong>
2048 tile!
</strong></p>
<div
class=
"game-container"
>
<div
class=
"game-container"
>
<div
class=
"game-message"
>
<p></p>
<a
class=
"retry-button"
>
Try again
</a>
</div>
<div
class=
"grid-container"
>
<div
class=
"grid-container"
>
<div
class=
"grid-row"
>
<div
class=
"grid-row"
>
<div
class=
"grid-cell"
></div>
<div
class=
"grid-cell"
></div>
...
...
js/game_manager.js
浏览文件 @
02b66ccb
...
@@ -4,19 +4,28 @@ function GameManager(size, InputManager, Actuator) {
...
@@ -4,19 +4,28 @@ function GameManager(size, InputManager, Actuator) {
this
.
actuator
=
new
Actuator
;
this
.
actuator
=
new
Actuator
;
this
.
startTiles
=
2
;
this
.
startTiles
=
2
;
this
.
grid
=
new
Grid
(
this
.
size
);
this
.
score
=
0
;
this
.
over
=
false
;
this
.
won
=
false
;
this
.
inputManager
.
on
(
"
move
"
,
this
.
move
.
bind
(
this
));
this
.
inputManager
.
on
(
"
move
"
,
this
.
move
.
bind
(
this
));
this
.
inputManager
.
on
(
"
restart
"
,
this
.
restart
.
bind
(
this
));
this
.
setup
();
this
.
setup
();
}
}
// Restart the game
GameManager
.
prototype
.
restart
=
function
()
{
this
.
actuator
.
restart
();
this
.
setup
();
};
// Set up the game
// Set up the game
GameManager
.
prototype
.
setup
=
function
()
{
GameManager
.
prototype
.
setup
=
function
()
{
this
.
grid
=
new
Grid
(
this
.
size
);
this
.
score
=
0
;
this
.
over
=
false
;
this
.
won
=
false
;
// Add the initial tiles
this
.
addStartTiles
();
this
.
addStartTiles
();
// Update the actuator
// Update the actuator
...
...
js/html_actuator.js
浏览文件 @
02b66ccb
function
HTMLActuator
()
{
function
HTMLActuator
()
{
this
.
tileContainer
=
document
.
getElementsByClassName
(
"
tile-container
"
)[
0
];
this
.
tileContainer
=
document
.
getElementsByClassName
(
"
tile-container
"
)[
0
];
this
.
gameContainer
=
document
.
getElementsByClassName
(
"
gam
e-container
"
)[
0
];
this
.
scoreContainer
=
document
.
getElementsByClassName
(
"
scor
e-container
"
)[
0
];
this
.
scoreContainer
=
document
.
getElementsByClassName
(
"
score-container
"
)[
0
];
this
.
messageContainer
=
document
.
getElementsByClassName
(
"
game-message
"
)[
0
];
this
.
score
=
0
;
this
.
score
=
0
;
}
}
...
@@ -27,6 +27,10 @@ HTMLActuator.prototype.actuate = function (grid, metadata) {
...
@@ -27,6 +27,10 @@ HTMLActuator.prototype.actuate = function (grid, metadata) {
});
});
};
};
HTMLActuator
.
prototype
.
restart
=
function
()
{
this
.
clearMessage
();
};
HTMLActuator
.
prototype
.
clearContainer
=
function
(
container
)
{
HTMLActuator
.
prototype
.
clearContainer
=
function
(
container
)
{
while
(
container
.
firstChild
)
{
while
(
container
.
firstChild
)
{
container
.
removeChild
(
container
.
firstChild
);
container
.
removeChild
(
container
.
firstChild
);
...
@@ -77,7 +81,7 @@ HTMLActuator.prototype.updateScore = function (score) {
...
@@ -77,7 +81,7 @@ HTMLActuator.prototype.updateScore = function (score) {
this
.
scoreContainer
.
textContent
=
this
.
score
;
this
.
scoreContainer
.
textContent
=
this
.
score
;
if
(
difference
)
{
if
(
difference
>
0
)
{
var
addition
=
document
.
createElement
(
"
div
"
);
var
addition
=
document
.
createElement
(
"
div
"
);
addition
.
classList
.
add
(
"
score-addition
"
);
addition
.
classList
.
add
(
"
score-addition
"
);
addition
.
textContent
=
"
+
"
+
difference
;
addition
.
textContent
=
"
+
"
+
difference
;
...
@@ -87,6 +91,15 @@ HTMLActuator.prototype.updateScore = function (score) {
...
@@ -87,6 +91,15 @@ HTMLActuator.prototype.updateScore = function (score) {
};
};
HTMLActuator
.
prototype
.
message
=
function
(
won
)
{
HTMLActuator
.
prototype
.
message
=
function
(
won
)
{
var
type
=
won
?
"
game-won
"
:
"
game-over
"
;
if
(
ga
)
ga
(
"
send
"
,
"
event
"
,
"
game
"
,
"
end
"
,
type
,
this
.
score
);
this
.
gameContainer
.
classList
.
add
(
type
);
var
type
=
won
?
"
game-won
"
:
"
game-over
"
;
var
message
=
won
?
"
You win!
"
:
"
Game over!
"
this
.
messageContainer
.
classList
.
add
(
type
);
this
.
messageContainer
.
getElementsByTagName
(
"
p
"
)[
0
].
textContent
=
message
;
};
HTMLActuator
.
prototype
.
clearMessage
=
function
()
{
this
.
messageContainer
.
classList
.
remove
(
"
game-won
"
,
"
game-over
"
);
};
};
js/keyboard_input_manager.js
浏览文件 @
02b66ccb
...
@@ -40,4 +40,10 @@ KeyboardInputManager.prototype.listen = function () {
...
@@ -40,4 +40,10 @@ KeyboardInputManager.prototype.listen = function () {
self
.
emit
(
"
move
"
,
mapped
);
self
.
emit
(
"
move
"
,
mapped
);
}
}
});
});
var
retry
=
document
.
getElementsByClassName
(
"
retry-button
"
)[
0
];
retry
.
addEventListener
(
"
click
"
,
function
(
event
)
{
event
.
preventDefault
();
self
.
emit
(
"
restart
"
);
});
};
};
style/main.css
浏览文件 @
02b66ccb
...
@@ -94,7 +94,8 @@ p {
...
@@ -94,7 +94,8 @@ p {
a
{
a
{
color
:
#776e65
;
color
:
#776e65
;
font-weight
:
bold
;
font-weight
:
bold
;
text-decoration
:
underline
;
}
text-decoration
:
underline
;
cursor
:
pointer
;
}
strong
.important
{
strong
.important
{
text-transform
:
uppercase
;
}
text-transform
:
uppercase
;
}
...
@@ -143,30 +144,41 @@ hr {
...
@@ -143,30 +144,41 @@ hr {
width
:
500px
;
width
:
500px
;
height
:
500px
;
height
:
500px
;
box-sizing
:
border-box
;
}
box-sizing
:
border-box
;
}
.game-container.game-over
:after
,
.game-container.game-won
:after
{
.game-container
.game-message
{
display
:
none
;
position
:
absolute
;
position
:
absolute
;
top
:
0
;
top
:
0
;
right
:
0
;
right
:
0
;
bottom
:
0
;
bottom
:
0
;
left
:
0
;
left
:
0
;
display
:
block
;
background
:
rgba
(
238
,
228
,
218
,
0.5
);
background
:
rgba
(
238
,
228
,
218
,
0.5
);
text-align
:
center
;
height
:
500px
;
line-height
:
500px
;
z-index
:
100
;
z-index
:
100
;
font-size
:
60px
;
text-align
:
center
;
font-weight
:
bold
;
-webkit-animation
:
fade-in
800ms
ease
1200ms
;
-webkit-animation
:
fade-in
800ms
ease
1200ms
;
-moz-animation
:
fade-in
800ms
ease
1200ms
;
-moz-animation
:
fade-in
800ms
ease
1200ms
;
-webkit-animation-fill-mode
:
both
;
-webkit-animation-fill-mode
:
both
;
-moz-animation-fill-mode
:
both
;
}
-moz-animation-fill-mode
:
both
;
}
.game-container.game-over
:after
{
.game-container
.game-message
p
{
content
:
"Game over!"
;
}
font-size
:
60px
;
.game-container.game-won
:after
{
font-weight
:
bold
;
content
:
"You win!"
;
height
:
60px
;
background
:
rgba
(
237
,
194
,
46
,
0.5
);
line-height
:
60px
;
color
:
#f9f6f2
;
}
margin-top
:
222px
;
}
.game-container
.game-message
a
{
display
:
inline-block
;
background
:
#a69382
;
border-radius
:
3px
;
padding
:
0
20px
;
text-decoration
:
none
;
color
:
#f9f6f2
;
height
:
40px
;
line-height
:
42px
;
margin-top
:
59px
;
}
.game-container
.game-message.game-won
{
background
:
rgba
(
237
,
194
,
46
,
0.5
);
color
:
#f9f6f2
;
}
.game-container
.game-message.game-won
,
.game-container
.game-message.game-over
{
display
:
block
;
}
.grid-container
{
.grid-container
{
position
:
absolute
;
position
:
absolute
;
...
...
style/main.scss
浏览文件 @
02b66ccb
...
@@ -110,6 +110,7 @@ a {
...
@@ -110,6 +110,7 @@ a {
color
:
$text-color
;
color
:
$text-color
;
font-weight
:
bold
;
font-weight
:
bold
;
text-decoration
:
underline
;
text-decoration
:
underline
;
cursor
:
pointer
;
}
}
strong
{
strong
{
...
@@ -156,35 +157,52 @@ hr {
...
@@ -156,35 +157,52 @@ hr {
height
:
$field-width
;
height
:
$field-width
;
box-sizing
:
border-box
;
box-sizing
:
border-box
;
&
.game-over
,
&
.game-won
{
.game-message
{
&
:after
{
display
:
none
;
position
:
absolute
;
top
:
0
;
position
:
absolute
;
right
:
0
;
top
:
0
;
bottom
:
0
;
right
:
0
;
left
:
0
;
bottom
:
0
;
display
:
block
;
left
:
0
;
background
:
rgba
(
$tile-color
,
.5
);
background
:
rgba
(
$tile-color
,
.5
);
text-align
:
center
;
z-index
:
100
;
height
:
$field-width
;
line-height
:
$field-width
;
text-align
:
center
;
z-index
:
100
;
p
{
font-size
:
60px
;
font-size
:
60px
;
font-weight
:
bold
;
font-weight
:
bold
;
height
:
60px
;
line-height
:
60px
;
margin-top
:
222px
;
// height: $field-width;
// line-height: $field-width;
}
@include
animation
(
fade-in
800ms
ease
$transition-speed
*
12
);
a
{
@include
animation-fill-mode
(
both
);
display
:
inline-block
;
background
:
darken
(
$game-container-background
,
10%
);
border-radius
:
3px
;
padding
:
0
20px
;
text-decoration
:
none
;
color
:
$bright-text-color
;
height
:
40px
;
line-height
:
42px
;
margin-top
:
59px
;
}
}
}
&
.game-over
:after
{
@include
animation
(
fade-in
800ms
ease
$transition-speed
*
12
);
content
:
"Game over!"
;
@include
animation-fill-mode
(
both
);
}
&
.game-won
:after
{
&
.game-won
{
content
:
"You win!"
;
background
:
rgba
(
$tile-gold-color
,
.5
);
background
:
rgba
(
$tile-gold-color
,
.5
);
color
:
$bright-text-color
;
color
:
$bright-text-color
;
}
&
.game-won
,
&
.game-over
{
display
:
block
;
}
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录