鍊熷姪瀹炴椂鏁版嵁鎺ㄩ€佸揩閫熷埗浣滃湪绾垮鎴樹簲瀛愭灏忔父鎴忎辅瀹炴垬
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了鍊熷姪瀹炴椂鏁版嵁鎺ㄩ€佸揩閫熷埗浣滃湪绾垮鎴樹簲瀛愭灏忔父鎴忎辅瀹炴垬相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e6%9c%89%e7%94%a8' title='鏈夌敤'>鏈夌敤 瀛樺湪 鑱旂郴 鏃犳晥 rom 浣嶇疆 hang 澶氫釜 涓嬭浇
1 椤圭洰姒傝堪
娓告垙寮€鍙戯紝灏ゅ叾鏄井淇″皬娓告垙寮€鍙戯紝鏄渶杩戝嚑骞存瘮杈冪儹闂ㄧ殑璇濋銆?/p>
鏈銆屼簯寮€鍙戙€嶅叕寮€璇撅紝灏嗛€氳繃瀹炴垬銆屽湪绾垮鎴樹簲瀛愭銆嶏紝涓€姝ユ甯﹂澶у锛屽湪涓嶅€熷姪鍚庣鐨勬儏鍐典笅锛屽埄鐢ㄣ€屽皬绋嬪簭 ? 浜戝紑鍙戙€嶏紝鐙珛瀹屾垚涓€娆惧井淇″皬娓告垙鐨勫紑鍙戜笌涓婄嚎銆?/p>
2 浠诲姟鐩爣
鏍规嵁椤圭洰鍒濆妗嗘灦锛岄槄璇绘暀绋嬬殑鍚屾椂锛岄€愭瀹屾垚妫嬬洏缁樺埗銆侀煶涔愭挱鏀俱€佺帺瀹跺鎴樸€佽緭璧㈠垽瀹氱瓑鍔熻兘锛屾渶缁堝疄鐜颁竴涓彲浠ュ揩涔愮帺鑰嶇殑鍦ㄧ嚎瀵规垬浜斿瓙妫嬨€?/p>
鍦ㄨ繖涓繃绋嬩腑锛屼細浜嗚В鍒?Serverless 鐨勪竴浜涙蹇碉紝骞朵笖瀹為檯搴旂敤瀹冧滑锛屾瘮濡傦細浜戞暟鎹簱銆?strong>浜戝瓨鍌?/strong>銆?strong>浜戝嚱鏁?/strong>銆?strong>澧炲€艰兘鍔?/strong>銆傞櫎浜嗚繖浜涘熀鏈姛鑳斤紝杩樺噯澶囦簡鏇村鐨勭‖鏍告蹇典笌钀藉湴瀹炶返锛屾瘮濡傦細瀹炴椂鏁版嵁搴?/strong>銆?strong>鑱氬悎鎼滅储銆?strong>鏉冮檺鎺у埗銆?/p>
瀹屾垚寮€鍙戝悗锛屼笂浼犲苟涓旇缃负浣撻獙鐗堬紝娆㈣繋閭€璇锋洿澶氫汉鏉ヤ綋楠屻€?/p>
3 鍑嗗宸ヤ綔
浠?TencentCloudBase/tcb-game-gomoku 涓笅杞戒唬鐮佸埌鏈湴锛?/p>
git clone https://github.com/TencentCloudBase/tcb-game-gomoku.git
cd tcb-game-gomoku/
鍒囨崲璇剧▼涓撶敤鐨?minigame-study
鍒嗘敮锛?/p>
git checkout minigame-study
4 瀹炴垬浠诲姟
2銆佽繘鍏ュ悗锛岀偣鍑讳笂鏂圭殑浜戝紑鍙戞寜閽€傚鏋滀箣鍓嶆病鏈夊紑閫氳繃浜戝紑鍙戯紝闇€瑕佸紑閫氫簯寮€鍙戯紝鏂板紑閫氱殑璇濋渶瑕佺瓑寰?10 锝?20 鍒嗛挓銆?/p>
3銆佽繘鍏ャ€屼簯寮€鍙?鏁版嵁搴撱€嶏紝鍒涘缓鏂扮殑闆嗗悎锛屾柊闆嗗悎鐨勫悕绉版槸rooms
銆?/p>
4銆佽繘鍏ャ€屼簯寮€鍙?瀛樺偍銆嶏紝鐐瑰嚮鈥滀笂浼犳枃浠垛€濄€備笂浼犵殑鍐呭鏄?code>/static/涓嬬殑 鍒涘缓閰嶇疆鏂囦欢锛?/p>
灏嗗叧閿瓧娈电殑淇℃伅锛屾崲鎴愯嚜宸辫处鍙风殑淇℃伅鍗冲彲锛?/p>
bgm.mp3
鍜?fall.mp3
銆備箣鍚庣殑浠g爜涓細閫氳繃浜戝瓨鍌ㄧ殑鎺ュ彛锛岃姹傛枃浠剁殑涓存椂 url锛岃繖鏍峰仛鐨勭洰鐨勬槸鍑忓皯鐢ㄦ埛棣栨杩涘叆娓告垙鍔犺浇鐨勯潤鎬佽祫婧?/strong>銆?/p>
4.2 鍑嗗閰嶇疆鏂囦欢
cp miniprogram/shared/config.example.js miniprogram/shared/config.js
4.4 鑾峰彇浜戝瓨鍌ㄨ祫婧愮殑閾炬帴
涓轰簡鍑忓皯鐢ㄦ埛棣栧睆鍔犺浇鐨勯潤鎬佽祫婧愶紝闊充箰璧勬簮骞舵病鏈夋斁鍦?code>miniprogram鐩綍涓嬶紝鑰屾槸鏀惧湪浜嗕簯瀛樺偍涓紝閫氳繃璋冪敤浜戝瓨鍌ㄧ殑 api 鎺ュ彛锛屾潵杩斿洖闈欐€佽祫婧愮殑涓存椂閾炬帴銆?/p>
鍦?miniprogram/modules/music.js
涓紝浼氳皟鐢ㄨ祫婧愭帴鍙o紝鑾峰彇璧勬簮閾炬帴锛?/p>
getTempFileURL
鍑芥暟灞炰簬浜戝紑鍙戠浉鍏筹紝鍥犳鏀惧湪浜?miniprogram/shared/cloud.js
涓€傝繖閲屽彧闇€瑕佷复鏃堕摼鎺?code>tempFileURL灞炴€э紝鍏跺畠杩斿洖鍊肩洿鎺ヨ繃婊よ皟鍗冲彲銆?/p>
涓轰簡鏂逛究澶栭潰璋冪敤锛宲romise 鍐呴儴涓嶅啀鐢?reject 鎶涢敊銆傚浜庨敊璇紓甯革紝杩斿洖绌哄瓧绗︿覆銆傝繖鏍凤紝鍔犺浇澶辫触鐨勮祫婧愪笉浼氬奖鍝嶆甯歌祫婧愮殑鍔犺浇鍜?Promise.all 涓€昏緫杩涜銆?/p>
4.7 鐩戝惉鐜╁杩涘叆
瀵逛簬 owner 韬唤鏉ヨ锛岄櫎浜嗚鍒涘缓鏂版埧闂达紝杩橀渶瑕佸湪鍒涘缓鍚庣洃鍚?player 韬唤鐨勭帺瀹惰繘鍏ユ父鎴忋€?/p>
瀵逛簬 player 韬唤鐨勭帺瀹惰繘鍏ユ父鎴忓悗锛屼細鏇存柊璁板綍涓殑 people 瀛楁锛? => 2锛夈€傝繖鏃跺€欏氨闇€瑕佸埄鐢ㄣ€屽疄鏃舵暟鎹簱銆嶇殑鍔熻兘锛岀洃鍚繙绋嬭褰曠殑 people 瀛楁鍙樺寲銆?/p>
浠g爜瀹炵幇涓婏紝璋冪敤watch
鏂规硶锛屽苟涓斾紶閫?code>onChange鍑芥暟鍙傛暟銆備竴鏃︽湁浠讳綍椋庡惞鑽夊姩锛岄兘鍙互鍦?code>onChange鍥炶皟鍑芥暟涓幏寰椼€傚浜庝紶閫掔粰鍥炶皟鍑芥暟鐨勫弬鏁帮紝鏈変袱涓瘮杈冮噸瑕侊細
- docChanges<
Array
>: 鏁扮粍涓殑姣忎竴椤瑰搴旀瘡鏉¤褰曠殑鍙樺寲绫诲瀷锛屽彉鍖栫被鍨嬫湁 init銆乽pdate銆乨elete 绛夈€?/li> - docs<
Array
>: 鏁扮粍涓殑姣忎竴椤瑰搴旀瘡鏉¤褰曠殑褰撳墠鏁版嵁銆?/li>
4.8 瓒婃潈鏇存柊瀛楁
瀵逛簬 player 韬唤鏉ヨ锛岃繘鍏ユ埧闂村悗锛屾棦涓嶉渶瑕併€屽垱寤烘柊鎴块棿銆嶏紝涔熶笉闇€瑕併€岀洃鍚帺瀹惰繘鍏ャ€嶃€備絾闇€瑕佹洿鏂拌褰曠殑 people 瀛楁銆傜敱浜庤褰曟槸鐢?owner 韬唤鐨勭帺瀹跺垱寤虹殑锛岃€屼簯鏁版嵁搴撳彧鏈変互涓?4 绉嶆潈闄愶細
- 鎵€鏈夌敤鎴峰彲璇伙紝浠呭垱寤鸿€呭彲璇诲啓
- 浠呭垱寤鸿€呭彲璇诲啓
- 鎵€鏈夌敤鎴峰彲璇?/li>
- 鎵€鏈夌敤鎴蜂笉鍙鍐?/li>
浠ヤ笂 4 绉嶆潈闄愶紝骞舵病鏈夈€屾墍鏈夌敤鎴峰彲璇诲啓銆嶃€傚洜姝わ紝瀵逛簬瓒婃潈璇诲啓鐨勬儏鍐碉紝闇€瑕侀€氳繃璋冪敤浜戝嚱鏁版潵浠モ€滅鐞嗗憳鈥濈殑鏉冮檺瀹炵幇銆傚湪 cloudfunction
涓垱寤?updateDoc
浜戝嚱鏁帮紝鎺ユ敹鍓嶇浼犳潵鐨?collection銆乨ocid銆乨ata 瀛楁銆傚浜?data 瀛楁鏉ヨ锛屽氨鏄暟鎹褰曠殑鏈€鏂版洿鏂版暟鎹€?/p>
鍦ㄥ皬娓告垙涓紝閫氳繃wx.cloud.callFunction
鏉ヨ皟鐢ㄤ簯鍑芥暟銆備紶鍏ョ殑 data 瀛楁鎸囨槑琚皟鐢ㄧ殑浜戝嚱鏁帮紝浼犲叆鐨?data 瀛楁鍙互鍦ㄤ簯鍑芥暟鐨勫洖璋冨嚱鏁扮殑 event 鍙傛暟涓闂埌锛堝涓婂浘鎵€绀猴級銆?/p>
4.9 钀藉瓙鏇存柊閫昏緫
涓嶈瀵逛簬 player 杩樻槸 owner 韬唤锛岄兘闇€瑕佸鐞嗚惤瀛愮殑閫昏緫銆傝惤瀛愰€昏緫涓紝涓嬮潰鐨勪袱绉嶆儏鍐垫槸灞炰簬鏃犳晥钀藉瓙锛?/p>
- 鐐瑰嚮浣嶇疆宸茬粡鏈夋瀛?/li>
- 瀵规柟杩樻湭钀藉瓙锛岀洰鍓嶄緷鐒跺浜庣瓑寰呮儏鍐?/li>
瀵逛簬浠ヤ笂涓ょ鎯呭喌锛屽鐞嗙殑閫昏緫鍒嗗埆鏄細
- 妫嬬洏鐘舵€佷繚瀛樺湪鍐呴儴绫讳腑锛岃皟鐢ㄨ惤瀛愮殑鍑芥暟锛屼細杩斿洖鏄惁鎴愬姛鐨勫瓧娈垫爣璇?/li>
- 鍙湁鐩戝惉鍒拌繙绋嬫鐩樻洿鏂板悗锛屾墠浼氭墦寮€鏈湴鐨勯攣锛屽厑璁歌惤瀛愶紱钀藉瓙鍚庯紝浼氶噸鏂颁笂閿?/li>
钀藉瓙鎴愬姛鍚庯紝瑕佸湪鏈湴鍒ゆ柇鏄惁鑳滃埄銆傚鏋滆儨鍒╋紝闇€瑕佽皟鐢ㄩ€€鍑虹殑閫昏緫銆備絾鏃犺鏄惁鑳滃埄锛岄兘瑕佸皢鏈湴鐨勬渶鏂扮姸鎬佹洿鏂板埌浜戠銆?/p>
4.10 鐩戝惉杩滅▼妫嬬洏鏇存柊
涓嶈瀵逛簬 player 杩樻槸 owner 韬唤鐨勭帺瀹讹紝閮介渶瑕佺洃鍚繙绋嬫鐩樼殑鏇存柊閫昏緫銆傚綋杩滅▼妫嬬洏瀛楁鏇存柊鏃讹紝鏈湴鏍规嵁鏈€鏂扮殑妫嬬洏鐘舵€侊紝閲嶇粯鏁翠釜妫嬬洏銆傚苟涓旇繘琛岃緭璧㈠垽瀹氾紝濡傛灉鍙互鍒ゅ畾杈撹耽锛屽垯閫€鍑烘父鎴忥紱鍚﹀垯锛屾墦寮€鏈湴鐨勯攣锛岀帺瀹跺彲浠ヨ惤瀛愩€?/p>
鍥犱负涓嶅悓韬唤鍧囬渶瑕佺洃鍚紝鍥犳杩欎竴鍧楃殑鐩戝惉閫昏緫鍙互澶嶇敤銆?strong>涓嶅悓鐨勬槸锛屼袱绉嶈韩浠界殑鐩戝惉鍚姩鏃堕棿涓嶄竴鏍?/strong>銆俹wner 韬唤闇€瑕佺瓑寰?player 韬唤鐜╁杩涘叆娓告垙鍚庢墠寮€鍚鐩樼洃鍚紱player 韬唤鏄洿鏂颁簡 people 瀛楁鍚庯紝寮€鍚鐩樼洃鍚€?/p>
鍦ㄧ洃鍚€昏緫涓紝闇€瑕佸垽鏂繙绋嬫洿鏂扮殑瀛楁鏄惁鏄?chessmen锛岃繖鏄€氳繃鍓嶉潰鎻愬強鐨?dataType 鏉ュ疄鐜扮殑銆傝繕寰愬摕鍟婂垽鏂褰曚腑鐨?nextcolor 瀛楁鏄惁鍜屾湰鍦扮殑 color 涓€鏍凤紝鏉ュ喅瀹氭槸鍚︽墦寮€鏈湴鐨勯攣銆?/p>
濡傛灉涓婅堪鐨勪袱涓潯浠跺潎婊¤冻锛屽垯鎵ц鏇存柊鏈湴妫嬬洏銆佸垽瀹氳緭璧€佹墦寮€鏈湴閿佺殑閫昏緫銆?/p>
绗?2 涓€昏緫涓竻闄よ褰曠殑鍘熷洜鏄负浜嗘柟渚胯皟璇曪紝瀵逛簬鐪熸鐨勪笟鍔″満鏅紝涓€鑸笉浼氬垹闄ゅ巻鍙叉暟鎹紝鏂逛究闂瀹氫綅銆傚悓鏃讹紝杩欎篃鏄竴涓秺鏉冩搷浣滐紝闇€瑕佽皟鐢ㄤ簯鍑芥暟鏉ュ疄鐜般€?/p>
6. 璇剧▼瀹屾暣婧愮爜
https://github.com/TencentCloudBase/tcb-game-gomoku
7. 鑱旂郴鎴戜滑
鏇村浜戝紑鍙戜娇鐢ㄦ妧宸у強 Serverless 琛屼笟鍔ㄦ€侊紝鎵爜鍏虫敞鎴戜滑~
以上是关于鍊熷姪瀹炴椂鏁版嵁鎺ㄩ€佸揩閫熷埗浣滃湪绾垮鎴樹簲瀛愭灏忔父鎴忎辅瀹炴垬的主要内容,如果未能解决你的问题,请参考以下文章
鏈懆鐩存挱棰勫憡 | 涓棿浠?Kafka 浼佷笟搴旂敤瀹炴垬銆丏M8 鏁版嵁瀛樺偍绠$悊