2048是一款非常經典的數字游戲,它的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三種技術,其中HTML代碼負責頁面結構的搭建,CSS代碼負責頁面樣式的設計,JavaScript代碼負責游戲邏輯的實現。