javascript實現貪吃蛇小遊戲

來源:互聯網
上載者:User

標籤:reset   bsp   out   resolve   pac   require   html   ref   結構   

源碼地址:https://github.com/qmdx00/Snake ,請不要吝嗇star。

首先畫出UML類圖:

用es6的文法,建立項目結構:

配置webpack:

const path = require(‘path‘)const HtmlWebpackPlugin = require(‘html-webpack-plugin‘)module.exports = {    entry: ‘./src/index.js‘,    output: {        path: path.resolve(__dirname, ‘dist‘),        filename: ‘bundle.js‘    },    module: {        rules: [{            test: /\.js?$/,            exclude: /node_modules/,            loader: ‘babel-loader‘        }]    },    plugins: [        new HtmlWebpackPlugin({            template: ‘./index.html‘        })    ],    devServer: {        contentBase: path.join(__dirname, ‘./release‘),        open: true,        port: 4000    }}

入口檔案為index.js,構建組建目錄為dist

配置啟動指令碼:package.json

{  "name": "snake",  "version": "1.0.0",  "description": "",  "main": "index.js",  "scripts": {    "dev": "webpack-dev-server --config ./webpack.dev.config.js --mode development",    "build": "webpack --config ./webpack.dev.config.js --mode production"  },  "author": "yuanweimin",  "license": "ISC",  "devDependencies": {    "babel-core": "^6.26.3",    "babel-loader": "^7.1.5",    "babel-polyfill": "^6.26.0",    "babel-preset-es2015": "^6.24.1",    "babel-preset-latest": "^6.24.1",    "html-webpack-plugin": "^3.2.0",    "webpack": "^4.16.5",    "webpack-cli": "^3.1.0",    "webpack-dev-server": "^3.1.5"  }}

安裝依賴後執行 npm run build

即可產生最終代碼。具體代碼請見github,喜歡的給個star哦。

 

javascript實現貪吃蛇小遊戲

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.