2048是一款非常經(jīng)典的數(shù)字游戲,它的HTML代碼如下:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>2048</title> <link rel="stylesheet" href="style.css"> </head> <body> <div class="container"> <div class="game"> <div class="heading"> <h1>2048</h1> <ul> <li><a href="#">New Game</a></li> <li><a href="#">Undo</a></li> </ul> </div> <div class="grid"> <div class="cell"> </div> <div class="cell"> </div> <div class="cell"> </div> <div class="cell"> </div> </div> <div class="grid"> <div class="cell"> </div> <div class="cell"> </div> <div class="cell"> </div> <div class="cell"> </div> </div> <div class="grid"> <div class="cell"> </div> <div class="cell"> </div> <div class="cell"> </div> <div class="cell"> </div> </div> <div class="grid"> <div class="cell"> </div> <div class="cell"> </div> <div class="cell"> </div> <div class="cell"> </div> </div> </div> <div class="game-over"> <p>Game over!</p> <p><a href="#">Try again</a></p> </div> </div> <script src="game.js"></script> </body> </html>
可以看到,2048游戲使用了HTML、CSS和JavaScript三種技術(shù),其中HTML代碼負(fù)責(zé)頁面結(jié)構(gòu)的搭建,CSS代碼負(fù)責(zé)頁面樣式的設(shè)計(jì),JavaScript代碼負(fù)責(zé)游戲邏輯的實(shí)現(xiàn)。