女人自慰AV免费观看内涵网,日韩国产剧情在线观看网址,神马电影网特片网,最新一级电影欧美,在线观看亚洲欧美日韩,黄色视频在线播放免费观看,ABO涨奶期羡澄,第一导航fulione,美女主播操b

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線(xiàn)課程
  • 觀看技術(shù)視頻
  • 寫(xiě)文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

分享一個(gè)有趣的鴻蒙分布式小游戲

OpenHarmony技術(shù)社區(qū) ? 來(lái)源:鴻蒙技術(shù)社區(qū) ? 作者:維京戰(zhàn)斧 ? 2021-11-01 14:29 ? 次閱讀

今天給大家分享一個(gè)有趣的鴻蒙分布式小游戲:你畫(huà)我猜。

開(kāi)發(fā)心得(如有錯(cuò)誤還請(qǐng)大佬及時(shí)指正):

  • 分布式流轉(zhuǎn):一個(gè) APP 應(yīng)用在設(shè)備之間互相拉起遷移,只在一個(gè)終端上運(yùn)行。

  • 分布式協(xié)同:一個(gè) APP 同時(shí)在多個(gè)設(shè)備上運(yùn)行,畫(huà)面實(shí)時(shí)共享,數(shù)據(jù)實(shí)時(shí)傳輸。

在工程創(chuàng)立之后,首先有個(gè)很重要的事情那就是驗(yàn)權(quán)。

①這個(gè)分布式協(xié)同會(huì)用到一個(gè)權(quán)限接口,去 MainAbilitySlice 里面申請(qǐng)

分布式數(shù)據(jù)管理 ohos.permission.DISTRIBUTED_DATASYNC 允許不同設(shè)備間的數(shù)據(jù)交換。
voidgrantPermission(){//獲取驗(yàn)證權(quán)限數(shù)據(jù)交互允許不同設(shè)備間的數(shù)據(jù)交換。
if(verifySelfPermission(DISTRIBUTED_DATASYNC)!=IBundleManager.PERMISSION_GRANTED){
if(canRequestPermission(DISTRIBUTED_DATASYNC)){
requestPermissionsFromUser(newString[]{DISTRIBUTED_DATASYNC},PERMISSION_CODE);
}
}
}

權(quán)限接口文檔鏈接

https://developer.harmonyos.com/cn/docs/documentation/doc-guides/security-permissions-available-0000001051089272

②權(quán)限申請(qǐng)

開(kāi)發(fā)者需要在 config.json 文件中的“reqPermissions”字段中聲明所需要的權(quán)限。

{
"module":{
"reqPermissions":[
{
"name":"ohos.permission.CAMERA",
"reason":"$string:permreason_camera",
"usedScene":
{
"ability":["com.mycamera.Ability","com.mycamera.AbilityBackground"],
"when":"always"
}
},{
...
}
]
}
}
}

351c9594-3ac5-11ec-82a9-dac502259ad0.png
{
"name":"ohos.permission.DISTRIBUTED_DEVICE_STATE_CHANGE"//允許獲取分布式組網(wǎng)內(nèi)設(shè)備的狀態(tài)變化。
},
{
"name":"ohos.permission.GET_DISTRIBUTED_DEVICE_INFO"//允許獲取分布式組網(wǎng)內(nèi)的設(shè)備列表和設(shè)備信息。
},
{
"name":"ohos.permission.GRT_BUNDLE_INFO"//查詢(xún)其他應(yīng)用的信息。
},
{
"name":"ohos.permission.INTERNET"//允許使用網(wǎng)絡(luò)socket。
}

應(yīng)用權(quán)限列表文檔鏈接:

https://developer.harmonyos.com/cn/docs/documentation/doc-guides/security-permissions-guidelines-0000000000029886

再看頁(yè)面結(jié)構(gòu):

在 resources 下面的:
  • graphic:頁(yè)面樣式效果調(diào)配

  • layoput:此 demo 的 java UI 頁(yè)面布局結(jié)構(gòu)

主頁(yè)面入口布局代碼 ability_main:



<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:orientation="vertical"
ohos:background_element="$graphic:background_button">

<Text
ohos:height="match_content"
ohos:width="match_content"
ohos:top_margin="150px"
ohos:layout_alignment="horizontal_center"
ohos:text="你好鴻蒙_你畫(huà)我猜"
ohos:text_size="38fp"
/>

<Image
ohos:id="$+id:imageComponent"
ohos:height="200vp"
ohos:width="1080"
ohos:top_margin="150px"
ohos:image_src="$media:HM"
/>

<Button
ohos:id="$+id:help_btn"
ohos:height="100vp"
ohos:width="300vp"
ohos:background_element="$graphic:background_button"
ohos:layout_alignment="horizontal_center"
ohos:left_padding="15vp"
ohos:right_padding="15vp"
ohos:text="進(jìn)入游戲"
ohos:text_size="30vp"
ohos:top_margin="20vp">
Button>


DirectionalLayout>

游戲匹配頁(yè)面布局 math_game:



<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:orientation="vertical">

<Button
ohos:id="$+id:help_btn"
ohos:height="match_content"
ohos:width="500px"
ohos:background_element="$graphic:background_begin"
ohos:layout_alignment="horizontal_center"
ohos:left_padding="15vp"
ohos:right_padding="15vp"
ohos:text="匹配對(duì)手"
ohos:text_size="30vp"
ohos:top_margin="200vp">
Button>
<Image
ohos:id="$+id:imageComponent"
ohos:height="200vp"
ohos:width="1080"
ohos:top_margin="100px"
ohos:image_src="$media:NHWC"

/>

DirectionalLayout>

MainAbilitySlice:

packagecom.huawei.codelab.slice;

importstaticohos.security.SystemPermission.DISTRIBUTED_DATASYNC;

importcom.huawei.codelab.ResourceTable;
importcom.huawei.codelab.utils.CommonData;
importcom.huawei.codelab.utils.LogUtil;
importohos.aafwk.ability.AbilitySlice;
importohos.aafwk.content.Intent;
importohos.aafwk.content.Operation;
importohos.agp.components.Component;
importohos.bundle.IBundleManager;



publicclassMainAbilitySliceextendsAbilitySlice{
privatestaticfinalStringTAG=CommonData.TAG+MainAbilitySlice.class.getSimpleName();

privatestaticfinalintPERMISSION_CODE=10000000;

@Override
publicvoidonStart(Intentintent){
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_ability_main);
grantPermission();
initView();
}

voidgrantPermission(){//獲取驗(yàn)證權(quán)限數(shù)據(jù)交互允許不同設(shè)備間的數(shù)據(jù)交換。
if(verifySelfPermission(DISTRIBUTED_DATASYNC)!=IBundleManager.PERMISSION_GRANTED){
if(canRequestPermission(DISTRIBUTED_DATASYNC)){
requestPermissionsFromUser(newString[]{DISTRIBUTED_DATASYNC},PERMISSION_CODE);
}
}
}
//
privatevoidinitView(){
findComponentById(ResourceTable.Id_help_btn).setClickedListener(newButtonClick());

}

privatevoidmathGame(){//數(shù)學(xué)游戲
LogUtil.info(TAG,"ClickResourceTableId_math_game");
IntentmathGameIntent=newIntent();
OperationoperationMath=newIntent.OperationBuilder().withBundleName(getBundleName())
.withAbilityName(CommonData.ABILITY_MAIN)
.withAction(CommonData.MATH_PAGE)
.build();
mathGameIntent.setOperation(operationMath);
startAbility(mathGameIntent);
}

//進(jìn)入游戲
privateclassButtonClickimplementsComponent.ClickedListener{
@Override
publicvoidonClick(Componentcomponent){
mathGame();
}
}

}

MathGameAbilitySlice:

packagecom.huawei.codelab.slice;
importcom.huawei.codelab.ResourceTable;
importcom.huawei.codelab.devices.SelectDeviceDialog;
importcom.huawei.codelab.utils.CommonData;
importcom.huawei.codelab.utils.LogUtil;
importohos.aafwk.ability.AbilitySlice;
importohos.aafwk.content.Intent;
importohos.aafwk.content.Operation;
importohos.agp.components.Button;
importohos.agp.components.Component;
importohos.data.distributed.common.KvManagerConfig;
importohos.data.distributed.common.KvManagerFactory;
importohos.distributedschedule.interwork.DeviceInfo;
importohos.distributedschedule.interwork.DeviceManager;
importjava.util.ArrayList;
importjava.util.List;


publicclassMathGameAbilitySliceextendsAbilitySlice{
privatestaticfinalStringTAG=CommonData.TAG+MathGameAbilitySlice.class.getSimpleName();

privateButtonhelpBtn;

privateListdevices=newArrayList<>();

@Override
publicvoidonStart(Intentintent){
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_math_game);
initView();

}

privatevoidinitView(){

if(findComponentById(ResourceTable.Id_help_btn)instanceofButton){
helpBtn=(Button)findComponentById(ResourceTable.Id_help_btn);
}
helpBtn.setClickedListener(newButtonClick());
}


privatevoidgetDevices(){
if(devices.size()>0){
devices.clear();
}
ListdeviceInfos=
DeviceManager.getDeviceList(ohos.distributedschedule.interwork.DeviceInfo.FLAG_GET_ONLINE_DEVICE);
LogUtil.info(TAG,"MathGameAbilitySlicedeviceInfossizeis:"+deviceInfos.size());
devices.addAll(deviceInfos);
showDevicesDialog();
}

privatevoidshowDevicesDialog(){
newSelectDeviceDialog(this,devices,deviceInfo->{
startLocalFa(deviceInfo.getDeviceId());
startRemoteFa(deviceInfo.getDeviceId());
}).show();
}

privatevoidstartLocalFa(StringdeviceId){
LogUtil.info(TAG,"startLocalFa......");
Intentintent=newIntent();
intent.setParam(CommonData.KEY_REMOTE_DEVICEID,deviceId);
intent.setParam(CommonData.KEY_IS_LOCAL,true);
Operationoperation=newIntent.OperationBuilder().withBundleName(getBundleName())
.withAbilityName(CommonData.ABILITY_MAIN)
.withAction(CommonData.DRAW_PAGE)
.build();
intent.setOperation(operation);
startAbility(intent);
}

privatevoidstartRemoteFa(StringdeviceId){
LogUtil.info(TAG,"startRemoteFa......");
StringlocalDeviceId=
KvManagerFactory.getInstance().createKvManager(newKvManagerConfig(this)).getLocalDeviceInfo().getId();
Intentintent=newIntent();
intent.setParam(CommonData.KEY_REMOTE_DEVICEID,localDeviceId);
intent.setParam(CommonData.KEY_IS_LOCAL,false);
Operationoperation=newIntent.OperationBuilder().withDeviceId(deviceId)
.withBundleName(getBundleName())
.withAbilityName(CommonData.ABILITY_MAIN)
.withAction(CommonData.DRAW_PAGE)
.withFlags(Intent.FLAG_ABILITYSLICE_MULTI_DEVICE)
.build();
intent.setOperation(operation);
startAbility(intent);
}

privateclassButtonClickimplementsComponent.ClickedListener{
@Override
publicvoidonClick(Componentcomponent){
getDevices();//啟動(dòng)機(jī)器匹配
}
}
}

責(zé)任編輯:haq


聲明:本文內(nèi)容及配圖由入駐作者撰寫(xiě)或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問(wèn)題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • 鴻蒙系統(tǒng)
    +關(guān)注

    關(guān)注

    183

    文章

    2639

    瀏覽量

    67700
  • HarmonyOS
    +關(guān)注

    關(guān)注

    79

    文章

    2052

    瀏覽量

    32120

原文標(biāo)題:鴻蒙版你畫(huà)我猜,請(qǐng)接招!

文章出處:【微信號(hào):gh_834c4b3d87fe,微信公眾號(hào):OpenHarmony技術(shù)社區(qū)】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。

收藏 人收藏

    評(píng)論

    相關(guān)推薦
    熱點(diǎn)推薦

    鴻蒙5開(kāi)發(fā)寶藏案例分享---多開(kāi)發(fā)實(shí)例(游戲

    十年前藏的現(xiàn)金樣驚喜!)這些藏在文檔深處的\"武功秘籍\",能幫我們輕松實(shí)現(xiàn)分布式游戲、跨端協(xié)同這些聽(tīng)起來(lái)很酷的功能。快上車(chē),帶你解鎖鴻蒙開(kāi)發(fā)的正確姿勢(shì)!
    發(fā)表于 06-03 18:22

    使用VirtualLab Fusion中分布式計(jì)算的AR波導(dǎo)測(cè)試圖像模擬

    總計(jì)算時(shí)間超過(guò)31小時(shí)。通過(guò)使用個(gè)由8個(gè)多核PC組成的網(wǎng)絡(luò),提供35個(gè)客戶(hù)端分布式計(jì)算,將模擬時(shí)間減少到1小時(shí)5分鐘。基本模擬任務(wù)基本任務(wù)
    發(fā)表于 04-10 08:48

    分布式云化數(shù)據(jù)庫(kù)有哪些類(lèi)型

    分布式云化數(shù)據(jù)庫(kù)有哪些類(lèi)型?分布式云化數(shù)據(jù)庫(kù)主要類(lèi)型包括:關(guān)系型分布式數(shù)據(jù)庫(kù)、非關(guān)系型分布式數(shù)據(jù)庫(kù)、新SQL分布式數(shù)據(jù)庫(kù)、以列方式存儲(chǔ)數(shù)據(jù)、
    的頭像 發(fā)表于 01-15 09:43 ?386次閱讀

    基于ptp的分布式系統(tǒng)設(shè)計(jì)

    在現(xiàn)代分布式系統(tǒng)中,精確的時(shí)間同步對(duì)于確保數(shù)據(jù)致性、系統(tǒng)穩(wěn)定性和性能至關(guān)重要。PTP(Precision Time Protocol)是種網(wǎng)絡(luò)協(xié)議,用于在分布式系統(tǒng)中實(shí)現(xiàn)高精度的時(shí)
    的頭像 發(fā)表于 12-29 10:09 ?449次閱讀

    HarmonyOS Next 應(yīng)用元服務(wù)開(kāi)發(fā)-分布式數(shù)據(jù)對(duì)象遷移數(shù)據(jù)權(quán)限與基礎(chǔ)數(shù)據(jù)

    ) ?? \'\'); }); } } 在對(duì)端UIAbility的onCreate()/onNewWant()中,通過(guò)加入與源端致的分布式數(shù)據(jù)對(duì)象組網(wǎng)進(jìn)行數(shù)據(jù)恢復(fù)。 創(chuàng)建空的分布式數(shù)據(jù)對(duì)象,用于接收
    發(fā)表于 12-24 09:40

    FPGA打磚塊小游戲設(shè)計(jì)思路

    ? 交流問(wèn)題 ? Q :FPGA打磚塊小游戲,如何基于FPGA用verilog語(yǔ)言在Vivado平臺(tái)上寫(xiě)打磚塊小游戲,最好能用到PS2與VGA。 A :以下是個(gè)基于 FPGA? Ve
    的頭像 發(fā)表于 12-09 16:57 ?787次閱讀

    分布式通信的原理和實(shí)現(xiàn)高效分布式通信背后的技術(shù)NVLink的演進(jìn)

    大型模型的大小已經(jīng)超出了單個(gè) GPU 的范圍。所以就需要實(shí)現(xiàn)跨多個(gè) GPU 的模型訓(xùn)練,這種訓(xùn)練方式就涉及到了分布式通信和 NVLink。 當(dāng)談及分布式通信和 NVLink 時(shí),我們進(jìn)入了個(gè)
    的頭像 發(fā)表于 11-18 09:39 ?1125次閱讀
    <b class='flag-5'>分布式</b>通信的原理和實(shí)現(xiàn)高效<b class='flag-5'>分布式</b>通信背后的技術(shù)NVLink的演進(jìn)

    分布式光纖測(cè)溫解決方案

    分布式光纖測(cè)溫解決方案
    的頭像 發(fā)表于 11-12 01:02 ?479次閱讀
    <b class='flag-5'>分布式</b>光纖測(cè)溫解決方案

    分布式光纖測(cè)溫是什么?應(yīng)用領(lǐng)域是?

    分布式光纖測(cè)溫是種先進(jìn)的溫度測(cè)量技術(shù),它利用光纖的拉曼散射原理進(jìn)行溫度監(jiān)測(cè)。以下是對(duì)分布式光纖測(cè)溫的詳細(xì)介紹: 、基本原理 分布式光纖測(cè)
    的頭像 發(fā)表于 10-24 15:30 ?1085次閱讀
    <b class='flag-5'>分布式</b>光纖測(cè)溫是什么?應(yīng)用領(lǐng)域是?

    分布式光纖聲波傳感技術(shù)的工作原理

    分布式光纖聲波傳感技術(shù)(Distributed Acoustic Sensing,DAS)是種利用光纖作為傳感元件,實(shí)現(xiàn)對(duì)沿光纖路徑上的環(huán)境參數(shù)進(jìn)行連續(xù)分布式測(cè)量的技術(shù)。
    的頭像 發(fā)表于 10-18 14:50 ?2538次閱讀
    <b class='flag-5'>分布式</b>光纖聲波傳感技術(shù)的工作原理

    分布式輸電線(xiàn)路故障定位中的分布式是指什么

    所謂分布式指的是產(chǎn)品的部署方式,是相對(duì)于集中式而言的。 、部署方式 分散安裝:分布式輸電線(xiàn)路故障定位系統(tǒng)中的采集裝置需要安裝在輸電線(xiàn)路的多個(gè)位置,通常是每隔定距離設(shè)置
    的頭像 發(fā)表于 10-16 11:39 ?617次閱讀
    <b class='flag-5'>分布式</b>輸電線(xiàn)路故障定位中的<b class='flag-5'>分布式</b>是指什么

    分布式存儲(chǔ)費(fèi)用高嗎?大概需要多少錢(qián)

    分布式存儲(chǔ)的費(fèi)用是否高,取決于多個(gè)因素,包括存儲(chǔ)容量、性能要求、服務(wù)提供商、計(jì)費(fèi)模式等。因此,無(wú)法簡(jiǎn)單地給出個(gè)“高”或“不高”的答案。通常分布式存儲(chǔ)費(fèi)用通常包含存儲(chǔ)費(fèi)用、網(wǎng)絡(luò)費(fèi)用、增
    的頭像 發(fā)表于 09-24 10:41 ?526次閱讀

    鴻蒙開(kāi)發(fā)管理:ohos.account.distributedAccount 分布式帳號(hào)管理

    獲取分布式帳號(hào)單實(shí)例對(duì)象。
    的頭像 發(fā)表于 07-08 10:03 ?434次閱讀
    <b class='flag-5'>鴻蒙</b>開(kāi)發(fā)管理:ohos.account.distributedAccount <b class='flag-5'>分布式</b>帳號(hào)管理

    鴻蒙ArkTS聲明開(kāi)發(fā):跨平臺(tái)支持列表【分布式遷移標(biāo)識(shí)】 通用屬性

    組件的分布式遷移標(biāo)識(shí),指明了該組件在分布式遷移場(chǎng)景下可以將特定狀態(tài)恢復(fù)到對(duì)端設(shè)備。
    的頭像 發(fā)表于 06-07 21:15 ?585次閱讀

    鴻蒙開(kāi)發(fā)接口數(shù)據(jù)管理:【@ohos.data.distributedData (分布式數(shù)據(jù)管理)】

    分布式數(shù)據(jù)管理為應(yīng)用程序提供不同設(shè)備間數(shù)據(jù)庫(kù)的分布式協(xié)同能力。通過(guò)調(diào)用分布式數(shù)據(jù)各個(gè)接口,應(yīng)用程序可將數(shù)據(jù)保存到分布式數(shù)據(jù)庫(kù)中,并可對(duì)分布式
    的頭像 發(fā)表于 06-07 09:30 ?1421次閱讀
    <b class='flag-5'>鴻蒙</b>開(kāi)發(fā)接口數(shù)據(jù)管理:【@ohos.data.distributedData (<b class='flag-5'>分布式</b>數(shù)據(jù)管理)】