鸿蒙HarmonyOS项目实战开发:井字过三关小游戏_基于harmonyos的井字棋游戏开发(1)

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数HarmonyOS鸿蒙开发工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年HarmonyOS鸿蒙开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img

img
img
外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上HarmonyOS鸿蒙开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新

如果你觉得这些内容对你有帮助,可以添加VX:vip204888 (备注鸿蒙获取)
img

一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

      }
    }
  }.height('50%')
  Row({ useAlign: HorizontalAlign.Center }) {
    Button('重新开始').width(200).height(50).fontSize(30).backgroundColor('#8E6B23').onClick(() => {
        this.initGame()
      })
  }.height('20%')
}

}


##### 3.设备认证


设备认证是依赖[DeviceManager]( )组件来实现的,详细代码参考源码RemoteDeviceModel.ets


1.创建DeviceManager实例



registerDeviceListCallback(callback) {
if (typeof (this.#deviceManager) === ‘undefined’) {
deviceManager.createDeviceManager(‘com.example.tictactoegame’, (error, value) => {
if (error) return
this.#deviceManager = value;
this.registerDeviceListCallback_(callback);
});
} else {
this.registerDeviceListCallback_(callback);
}
}


2.查询可信设备列表



var list = this.#deviceManager.getTrustedDeviceListSync();
if (typeof (list) != ‘undefined’ && typeof (list.length) != ‘undefined’) {
this.deviceList = list;
}


3.注册设备上下线监听



this.#deviceManager.on(‘deviceStateChange’, (data) => {
switch (data.action) {
case 0:
this.deviceList[this.deviceList.length] = data.device;
this.callback();
if (this.authCallback != null) {
this.authCallback();
this.authCallback = null;
}
break;
case 2:
if (this.deviceList.length > 0) {
for (var i = 0; i < this.deviceList.length; i++) {
if (this.deviceList[i].deviceId === data.device.deviceId) {
this.deviceList[i] = data.device;
break;
}
}
}
this.callback();
break;
case 1:
if (this.deviceList.length > 0) {
var list = [];
for (var i = 0; i < this.deviceList.length; i++) {
if (this.deviceList[i].deviceId != data.device.deviceId) {
list[i] = data.device;
}
}
this.deviceList = list;
}
this.callback();
break;
default:
break;
}
});


4.设备发现



this.#deviceManager.on(‘deviceFound’, (data) => {
for (let i = 0; i < this.discoverList.length; i++) {
if (that.discoverList[i].deviceId === data.device.deviceId) {
return;
}
}
this.discoverList[this.discoverList.length] = data.device;
this.callback();
});


5.设备认证



authDevice(deviceInfo, callback){
let extraInfo = {
“targetPkgName”: ‘com.example.tictactoegame’,
“appName”: ‘com.example.tictactoegame’,
“appDescription”: ‘com.example.tictactoegame’,
“business”: ‘0’
};
let authParam = {
“authType”: 1,
“appIcon”: ‘’,
“appThumbnail”: ‘’,
“extraInfo”: extraInfo
};
this.#deviceManager.authenticateDevice(deviceInfo, authParam, (err, data) => {
if (err) {
this.authCallback = null;
} else {
this.authCallback = callback;
}
});
}


##### 4.数据管理


[分布式数据管理]( )依赖@ohos.data.distributedData模块实现,详细参考源码RemoteDataManager.ets


1.导入该模块



import factory from ‘@ohos.data.distributedData’;


2.创建KVManager实例,用于管理数据库对象



registerDataListCallback(callback) {
let that = this
if (this.kvManager == null) {
try {
const config = {
userInfo: {
userId: ‘0’,
userType: 0
},
bundleName: ‘com.example.tictactoegame’
}
factory.createKVManager(config).then((manager) => {
that.kvManager = manager
that.registerDataListCallback_(callback)
}).catch((err) => {
})
} catch (e) {
}
} else {
this.registerDataListCallback_(callback)
}
}


3.创建并获取KVStore数据库



registerDataListCallback_(callback) {
let that = this
if (that.kvManager == null) {
callback()
return
}
if (that.kvStore == null) {
try {
let options =
{
createIfMissing: true,
encrypt: false,
backup: false,
autoSync: true,
kvStoreType: 1,
securityLevel: 3
}
this.kvManager.getKVStore(this.STORE_ID, options).then((store) => {
that.kvStore = store
that.registerDataListCallback(callback)
}).catch((err) => {
})
} catch (e) {
}
} else {
this.registerDataListCallback(callback)
}
}


4.订阅指定类型的数据变更通知



registerDataListCallback(callback) {
let that = this
if (that.kvManager == null) {
callback()
return
}
this.kvStore.on(‘dataChange’, 1, function(data) {
if (data) {
that.arr = data.updateEntries
callback()
}
})
}


5.添加指定类型键值对到数据库



dataChange(key, value) {
let that = this
try {
that.kvStore.put(JSON.stringify(key), JSON.stringify(value)).then((data) => {
}).catch((err) => {
prompt.showToast({message:‘put err:’+JSON.stringify(value)})
})

  } catch (e) {
  }

}


##### 5.远程拉起设备app


使用[FeatureAbility]( )模块的startAbility接口拉起远程设备app



startAbilityContinuation(deviceId) {
let wantValue = {
bundleName: ‘com.example.tictactoegame’,
abilityName: ‘com.example.tictactoegame.MainAbility’,
deviceId: deviceId,
parameters: {
uri: ‘pages/Fight’
}
};
featureAbility.startAbility({ want: wantValue }).then(() => {
router.replace({ uri: ‘pages/Fight’ })
});
}


##### 6.棋局胜负判定


对于棋盘中的任一个格子只存在已落子和未落子两种状态,我们把这两种状态定义为1和0,则九宫格可以看成是一个只有9位的二进制数,胜利状态有八种情况如下,详细代码参考源码Chess.ets:



0b111000000
0b100100100
0b100010001
0b010010010
0b001001001
0b000111000
0b000000111
0b001010100


胜负判定实现如下



isWin() {
let x = this.result_X
let o = this.result_O
if (448 == (x & 448) || 292 == (x & 292) || 273 == (x & 273) || 146 == (x & 146) || 73 == (x & 73) || 56 == (x & 56) || 7 == (x & 7) || 84 == (x & 84)){
this.allIsTrue()
return FORK
}
if (448 == (o & 448) || 292 == (o & 292) || 273 == (o & 273) || 146 == (o & 146) || 73 == (o & 73) || 56 == (o & 56) || 7 == (o & 7) || 84 == (o & 84)) {
this.allIsTrue()
return CIRCLE
}
let res = 0;
for (let i = 0; i < 9; i++) {
if (this.used[i] == false) {
res = 1
break
}
}
if (res === 1) {
return CONTINUE
}
return EMPTY
}


最后,有很多小伙伴不知道学习哪些鸿蒙开发技术?不知道需要重点掌握哪些鸿蒙应用开发知识点?而且学习时频繁踩坑,最终浪费大量时间。所以有一份实用的**鸿蒙(Harmony NEXT)资料**用来跟着学习是非常有必要的。 


为了能够帮助大家快速掌握**鸿蒙(Harmony NEXT)**应用开发技术知识。**在此给大家分享一下我结合鸿蒙最新资料整理出来的鸿蒙南北向开发学习路线以及整理的最新版鸿蒙学习文档资料。**


**这份鸿蒙(Harmony NEXT)资料包含了鸿蒙开发必掌握的核心知识要点,内容包含了**(**ArkTS、ArkUI开发组件、Stage模型、多端部署、分布式应用开发、音频、视频、WebGL、OpenHarmony****多媒体技术、Napi组件、OpenHarmony内核、Harmony南向开发、鸿蒙项目实战等等)鸿蒙(Harmony NEXT)**技术知识点。


希望这一份鸿蒙学习资料能够给大家带来帮助,有需要的小伙伴自行领取,**限时开源,先到先得~无套路领取!!**


**如果你是一名有经验的资深Android移动开发、Java开发、前端开发、对鸿蒙感兴趣以及转行人员,可以直接领取这份资料**


**获取这份完整版高清学习路线,请点击→**[纯血版全套鸿蒙HarmonyOS学习资料]( )****


### **鸿蒙(Harmony NEXT)最新学习路线**


**![](https://img-blog.csdnimg.cn/direct/309a2ac95b5d40aa8c0f79885edb295a.png)**


* **HarmonOS基础技能**


![](https://img-blog.csdnimg.cn/direct/72fd2509a44e4bf98bbe1f983b5a4ff6.png)


* **HarmonOS就业必备技能** ![](https://img-blog.csdnimg.cn/direct/18f024bc5f0a4353912996010ed6cc81.png)
* **HarmonOS多媒体技术**


![](https://img-blog.csdnimg.cn/direct/b9ead66dadc245fdadce4d77feb47a28.png)


* **鸿蒙NaPi组件进阶**


![](https://img-blog.csdnimg.cn/direct/0744fbd1454f41b0a3f605fb4a51f5f3.png)


* **HarmonOS高级技能**


![](https://img-blog.csdnimg.cn/direct/743b668910224b259a5ffe804fa6d0db.png)


* **初识HarmonOS内核**![](https://img-blog.csdnimg.cn/direct/9e79fbdc4bb74f179584c5552aa547d5.png)
* **实战就业级设备开发**


![](https://img-blog.csdnimg.cn/direct/d2012fa9c57a400da25a2182a38cbdcb.png)


 有了路线图,怎么能没有学习资料呢,小编也准备了一份联合鸿蒙官方发布笔记整理收纳的一套系统性的**鸿蒙(OpenHarmony )学习手册(共计1236页)**与**鸿蒙(OpenHarmony )开发入门教学视频**,内容包含:**ArkTS、ArkUI、Web开发、应用模型、资源分类…等知识点。**


**获取以上完整版高清学习路线,请点击→[纯血版全套鸿蒙HarmonyOS学习资料]( )**


#### **《鸿蒙 (OpenHarmony)开发入门教学视频》**


![](https://img-blog.csdnimg.cn/direct/ad3cb3acb77e470fa93ac0471d4e7f0f.png)


#### 《鸿蒙生态应用开发V2.0白皮书》


![图片](https://img-blog.csdnimg.cn/img_convert/bf439a395d3ce8e8cf3dee8e8b75e3a9.jpeg)


#### **《鸿蒙 (OpenHarmony)开发基础到实战手册》**


OpenHarmony北向、南向开发环境搭建


![图片](https://img-blog.csdnimg.cn/img_convert/aff76dc1c3c84c360a9ff825908b2e98.png)


#### **《鸿蒙开发基础》**


**


#### **《鸿蒙 (OpenHarmony)开发入门教学视频》**


![](https://img-blog.csdnimg.cn/direct/ad3cb3acb77e470fa93ac0471d4e7f0f.png)


#### 《鸿蒙生态应用开发V2.0白皮书》


![图片](https://img-blog.csdnimg.cn/img_convert/bf439a395d3ce8e8cf3dee8e8b75e3a9.jpeg)


#### **《鸿蒙 (OpenHarmony)开发基础到实战手册》**


OpenHarmony北向、南向开发环境搭建


![图片](https://img-blog.csdnimg.cn/img_convert/aff76dc1c3c84c360a9ff825908b2e98.png)


#### **《鸿蒙开发基础》**


  • 8
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值