open harmony 项目实战诗词配对小游戏的实现思路语文学习不一定只能靠阅读和背诵。适当加入轻量小游戏可以让用户更愿意反复练习。“语文视界”中的诗词配对功能就是一个很适合碎片时间的练习系统给出上句用户选择对应下句回答后立即反馈。一、功能玩法诗词配对页面的规则很简单每组有若干道题。每道题展示诗名、作者、提示句。用户从多个选项中选择正确下句。答对后锁定本题。全部完成后显示成绩总结。这个玩法很轻不需要用户输入大量文字非常适合手机端。二、页面状态StateprivateroundIndex:number0;Stateprivateitems:MatchItem[] [];StateprivateselectedPerRow: (string|null)[] [];StateprivatecorrectPerRow: (boolean|null)[] [];StateprivatewrongPerRow: (boolean|null)[] [];StateprivaterightCount:number0;StateprivatewrongCount:number0;StateprivateallDone:booleanfalse;这些状态分别记录当前轮次、题目、每题选择、每题正确状态、错误状态和总成绩。三、打乱选项为了避免用户记住固定顺序项目会打乱选项privateshuffleStringArray(src:string[]):string[]{constout:string[] [];lets 0;while(s src.length) {out.push(src[s]); s; }letj out.length -1;while(j 0) {constk Math.floor(Math.random() * (j 1));consttmp out[j];out[j] out[k];out[k] tmp; j--; }returnout; }这里先复制数组再洗牌避免修改原始题库。四、开始一轮练习privatestartRound(idx: number): void {this.roundIndex idx % MATCH_ROUNDS_COUNT;constsrc: MatchItem[] []; let i 0;while(i MATCH_ROUNDS[this.roundIndex].length) {constraw MATCH_ROUNDS[this.roundIndex][i]; src.push({ poemTitle: raw.poemTitle, author: raw.author, clue: raw.clue, correctLine: raw.correctLine, options:this.shuffleStringArray(raw.options), explanation: raw.explanation }); i; }this.items src; }每一轮都会重新生成题目和选项保证练习有变化。五、选择答案用户点击选项后页面判断是否正确privatepickOption(rowIdx: number, line: string): void {if(this.allDone ||this.correctPerRow[rowIdx] !null) {return; }this.selectedPerRow[rowIdx] line;constitem this.items[rowIdx];if(line item.correctLine) {this.correctPerRow[rowIdx] true;this.rightCount this.rightCount 1; promptAction.showToast({ message:回答正确 ♡, duration:1200}); }else{this.wrongPerRow[rowIdx] true;this.wrongCount this.wrongCount 1; promptAction.showToast({ message:再想想看, duration:1200}); } }这里有一个关键判断如果题目已经答对就不允许重复选择。六、完成检测每次选择后都会检查所有题是否完成let done true; let i 0;while(i this.correctPerRow.length) {if(this.correctPerRow[i] null) { done false;break; } i; }if(done) {this.allDone true; }完成后可以展示总结和下一组按钮。七、成绩反馈项目根据正确率给出不同文案consttotal this.rightCount this.wrongCount;constpct Math.round((this.rightCount / total) *100); let msg ;if(pct 100) { msg 太棒了满分; }elseif(pct 75) { msg 很棒继续加油; }else{ msg 多背诗再来一次吧; }这种即时反馈会比单纯显示分数更有温度。八、为什么适合学习 App诗词配对的优点是操作简单。反馈及时。题目短适合碎片时间。能训练诗句记忆。可以自然扩展更多题库。九、后续优化方向可以继续加入答错后展示解析。每道题记录耗时。统计正确率。加入错题本。支持分享成绩。支持更多轮次题库。总结诗词配对功能的核心不是复杂技术而是把学习任务设计成一个短反馈循环看题、选择、反馈、总结、下一组。用 OpenHarmony 的状态管理和 ArkUI 组件就可以很自然地搭出这种轻量练习功能让学习过程更有参与感。
open harmony 项目实战:诗词配对小游戏的实现思路
发布时间:2026/7/1 1:24:46
open harmony 项目实战诗词配对小游戏的实现思路语文学习不一定只能靠阅读和背诵。适当加入轻量小游戏可以让用户更愿意反复练习。“语文视界”中的诗词配对功能就是一个很适合碎片时间的练习系统给出上句用户选择对应下句回答后立即反馈。一、功能玩法诗词配对页面的规则很简单每组有若干道题。每道题展示诗名、作者、提示句。用户从多个选项中选择正确下句。答对后锁定本题。全部完成后显示成绩总结。这个玩法很轻不需要用户输入大量文字非常适合手机端。二、页面状态StateprivateroundIndex:number0;Stateprivateitems:MatchItem[] [];StateprivateselectedPerRow: (string|null)[] [];StateprivatecorrectPerRow: (boolean|null)[] [];StateprivatewrongPerRow: (boolean|null)[] [];StateprivaterightCount:number0;StateprivatewrongCount:number0;StateprivateallDone:booleanfalse;这些状态分别记录当前轮次、题目、每题选择、每题正确状态、错误状态和总成绩。三、打乱选项为了避免用户记住固定顺序项目会打乱选项privateshuffleStringArray(src:string[]):string[]{constout:string[] [];lets 0;while(s src.length) {out.push(src[s]); s; }letj out.length -1;while(j 0) {constk Math.floor(Math.random() * (j 1));consttmp out[j];out[j] out[k];out[k] tmp; j--; }returnout; }这里先复制数组再洗牌避免修改原始题库。四、开始一轮练习privatestartRound(idx: number): void {this.roundIndex idx % MATCH_ROUNDS_COUNT;constsrc: MatchItem[] []; let i 0;while(i MATCH_ROUNDS[this.roundIndex].length) {constraw MATCH_ROUNDS[this.roundIndex][i]; src.push({ poemTitle: raw.poemTitle, author: raw.author, clue: raw.clue, correctLine: raw.correctLine, options:this.shuffleStringArray(raw.options), explanation: raw.explanation }); i; }this.items src; }每一轮都会重新生成题目和选项保证练习有变化。五、选择答案用户点击选项后页面判断是否正确privatepickOption(rowIdx: number, line: string): void {if(this.allDone ||this.correctPerRow[rowIdx] !null) {return; }this.selectedPerRow[rowIdx] line;constitem this.items[rowIdx];if(line item.correctLine) {this.correctPerRow[rowIdx] true;this.rightCount this.rightCount 1; promptAction.showToast({ message:回答正确 ♡, duration:1200}); }else{this.wrongPerRow[rowIdx] true;this.wrongCount this.wrongCount 1; promptAction.showToast({ message:再想想看, duration:1200}); } }这里有一个关键判断如果题目已经答对就不允许重复选择。六、完成检测每次选择后都会检查所有题是否完成let done true; let i 0;while(i this.correctPerRow.length) {if(this.correctPerRow[i] null) { done false;break; } i; }if(done) {this.allDone true; }完成后可以展示总结和下一组按钮。七、成绩反馈项目根据正确率给出不同文案consttotal this.rightCount this.wrongCount;constpct Math.round((this.rightCount / total) *100); let msg ;if(pct 100) { msg 太棒了满分; }elseif(pct 75) { msg 很棒继续加油; }else{ msg 多背诗再来一次吧; }这种即时反馈会比单纯显示分数更有温度。八、为什么适合学习 App诗词配对的优点是操作简单。反馈及时。题目短适合碎片时间。能训练诗句记忆。可以自然扩展更多题库。九、后续优化方向可以继续加入答错后展示解析。每道题记录耗时。统计正确率。加入错题本。支持分享成绩。支持更多轮次题库。总结诗词配对功能的核心不是复杂技术而是把学习任务设计成一个短反馈循环看题、选择、反馈、总结、下一组。用 OpenHarmony 的状态管理和 ArkUI 组件就可以很自然地搭出这种轻量练习功能让学习过程更有参与感。