Objective-C 學習曲線陡峭,記憶體管理、指標、委派模式讓 Web 開發者望而卻步。HTML5 + CSS + JavaScript 讓你以現有技能棧,直接構建具備「原生外觀、離線可用、可上架 App Store」的 iPhone 應用。同樣技術棧亦適用於 Android、Windows Phone 等所有支援 HTML5 的行動平台。
.appcache → text/cache-manifest(Apache: AddType text/cache-manifest .appcache)CACHE MANIFEST
# v1.0.3
index.html
css/app.css
js/game.js
js/tetromino.js
images/blocks.png
audio/move.mp3
audio/clear.mp3
NETWORK:
score.php
analytics.php
FALLBACK:
/ /offline.html
<html manifest="cache.manifest">// 主邏輯模組化
const Tetris = (() => {
const COLS = 10, ROWS = 20, BLOCK = 24;
let canvas, ctx, grid, currentPiece, nextPiece, score, timer;
function init() {
canvas = document.getElementById('game');
ctx = canvas.getContext('2d');
canvas.width = COLS * BLOCK;
canvas.height = ROWS * BLOCK;
resetGame();
bindControls();
requestAnimationFrame(loop);
}
function loop(ts) {
update(ts);
render();
requestAnimationFrame(loop);
}
// ... 完整程式碼見附件
return { init };
})();
document.addEventListener('DOMContentLoaded', Tetris.init);
以 cordova create tetris com.example.tetris Tetris 建立專案,將 Web 內容置於 www/,執行 cordova build ios 即產出 .ipa,可提交審核。同碼庫一鍵產出 Android APK、Windows Phone XAP。
HTML5 讓 Web 開發者以最低成本進軍行動應用市場,俄羅斯方塊只是開始。