Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
黛琳ghz
2048
提交
d6da8d99
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看板
提交
d6da8d99
编写于
3月 11, 2014
作者:
T
Tim Petricola
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
localStorage fallback
上级
fda0e840
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
23 addition
and
23 deletion
+23
-23
js/game_manager.js
js/game_manager.js
+1
-1
js/html_actuator.js
js/html_actuator.js
+2
-9
js/local_score_manager.js
js/local_score_manager.js
+20
-13
未找到文件。
js/game_manager.js
浏览文件 @
d6da8d99
...
@@ -2,7 +2,7 @@ function GameManager(size, InputManager, Actuator, ScoreManager) {
...
@@ -2,7 +2,7 @@ function GameManager(size, InputManager, Actuator, ScoreManager) {
this
.
size
=
size
;
// Size of the grid
this
.
size
=
size
;
// Size of the grid
this
.
inputManager
=
new
InputManager
;
this
.
inputManager
=
new
InputManager
;
this
.
scoreManager
=
new
ScoreManager
;
this
.
scoreManager
=
new
ScoreManager
;
this
.
actuator
=
new
Actuator
(
this
.
scoreManager
.
isSupported
())
;
this
.
actuator
=
new
Actuator
;
this
.
startTiles
=
2
;
this
.
startTiles
=
2
;
...
...
js/html_actuator.js
浏览文件 @
d6da8d99
function
HTMLActuator
(
bestScoreSupported
)
{
function
HTMLActuator
()
{
this
.
tileContainer
=
document
.
getElementsByClassName
(
"
tile-container
"
)[
0
];
this
.
tileContainer
=
document
.
getElementsByClassName
(
"
tile-container
"
)[
0
];
this
.
scoreContainer
=
document
.
getElementsByClassName
(
"
score-container
"
)[
0
];
this
.
scoreContainer
=
document
.
getElementsByClassName
(
"
score-container
"
)[
0
];
this
.
bestContainer
=
document
.
getElementsByClassName
(
"
best-container
"
)[
0
];
this
.
bestContainer
=
document
.
getElementsByClassName
(
"
best-container
"
)[
0
];
this
.
messageContainer
=
document
.
getElementsByClassName
(
"
game-message
"
)[
0
];
this
.
messageContainer
=
document
.
getElementsByClassName
(
"
game-message
"
)[
0
];
this
.
score
=
0
;
this
.
score
=
0
;
this
.
bestScoreSupported
=
bestScoreSupported
;
if
(
!
this
.
bestScoreSupported
)
{
this
.
bestContainer
.
style
.
display
=
"
none
"
;
}
}
}
HTMLActuator
.
prototype
.
actuate
=
function
(
grid
,
metadata
)
{
HTMLActuator
.
prototype
.
actuate
=
function
(
grid
,
metadata
)
{
...
@@ -111,9 +106,7 @@ HTMLActuator.prototype.updateScore = function (score) {
...
@@ -111,9 +106,7 @@ HTMLActuator.prototype.updateScore = function (score) {
};
};
HTMLActuator
.
prototype
.
updateBestScore
=
function
(
bestScore
)
{
HTMLActuator
.
prototype
.
updateBestScore
=
function
(
bestScore
)
{
if
(
this
.
bestScoreSupported
)
{
this
.
bestContainer
.
textContent
=
bestScore
;
this
.
bestContainer
.
textContent
=
bestScore
;
}
};
};
HTMLActuator
.
prototype
.
message
=
function
(
won
)
{
HTMLActuator
.
prototype
.
message
=
function
(
won
)
{
...
...
js/local_score_manager.js
浏览文件 @
d6da8d99
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
()
{
function
LocalScoreManager
()
{
var
localSupported
=
!!
window
.
localStorage
;
this
.
key
=
'
bestScore
'
;
this
.
key
=
'
bestScore
'
;
this
.
storage
=
localSupported
?
window
.
localStorage
:
window
.
fakeStorage
;
}
}
LocalScoreManager
.
prototype
.
get
=
function
()
{
LocalScoreManager
.
prototype
.
get
=
function
()
{
if
(
!
this
.
isSupported
())
{
var
score
=
this
.
storage
.
getItem
(
this
.
key
);
return
0
;
if
(
typeof
score
===
"
undefined
"
||
score
===
null
)
{
score
=
0
;
}
}
return
score
;
return
localStorage
.
getItem
(
this
.
key
);
};
};
LocalScoreManager
.
prototype
.
set
=
function
(
score
)
{
LocalScoreManager
.
prototype
.
set
=
function
(
score
)
{
if
(
!
this
.
isSupported
())
{
this
.
storage
.
setItem
(
this
.
key
,
score
);
return
false
;
}
localStorage
.
setItem
(
this
.
key
,
score
);
};
LocalScoreManager
.
prototype
.
isSupported
=
function
()
{
return
!!
window
.
localStorage
;
};
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录