当前位置: 首页 > news >正文

怎样在文章后做网站链接专业的商城网站开发

怎样在文章后做网站链接,专业的商城网站开发,网上如何建网站卖量具,网店推广的重要性HTML5 JavaScript单词游戏 数据字典格式#xff1a;每行一个 单词 #xff0c;单词和解释用空格分隔#xff0c;如 a art.一(个)#xff1b;每一(个) ability n.能力#xff1b;能耐#xff0c;本领 able a.有能力的#xff1b;出色的 baby n.婴儿#xff1b;孩子…HTML5 JavaScript单词游戏 数据字典格式每行一个 单词 单词和解释用空格分隔如 a art.一(个)每一(个) ability n.能力能耐本领 able a.有能力的出色的 baby n.婴儿孩子气的人 back ad.在后回原处回 background n.背景后景经历 cable n.缆索电缆电报 cafe n.咖啡馆小餐厅 good a.好的有本事的 需要注意的是JavaScript 在浏览器环境中不能像python那样直接读取本地文本文件这是出于安全考虑可以将数据字典内容作为 JavaScript 数据直接嵌入到脚本中。 游戏规则 每次随机从文本中选取一个英语单词在界面上从左到右移动随机选出三个单词的解释和英语单词正确解释随机放到四个按钮中这四个按钮放到界面下方。 用户单击带有解释的按钮界面上英语单词消失再随机从文本中选取一个新英语单词进入下一个猜单词过程若英语单词移动出界面用户未能单击有正确解释的按钮表示失败也将随机从文本中选取一个新英语单词进入下一个猜单词过程。 有失败和成功计数。 使用HTML5来实现这个单词游戏 运行界面 使用面向过程方式实现游戏源码如下 !DOCTYPE html html langen headmeta charsetUTF-8meta nameviewport contentwidthdevice-width, initial-scale1.0title单词游戏/titlestylebody {font-family: Arial, sans-serif;display: flex;flex-direction: column;align-items: center;padding: 20px;}#gameCanvas {border: 1px solid black;}#score {align-self: flex-end;margin-bottom: 10px;}#buttons {display: grid;grid-template-columns: 1fr 1fr;gap: 10px;margin-top: 20px;}button {width: 180px;height: 40px;font-size: 14px;}/style /head bodydiv idscore成功: 0 失败: 0/divcanvas idgameCanvas width400 height200/canvasdiv idbuttons/divscript// 字典数据const dictionaryData a art.一(个)每一(个) ability n.能力能耐本领 able a.有能力的出色的 baby n.婴儿孩子气的人 back ad.在后回原处回 background n.背景后景经历 cable n.缆索电缆电报 cafe n.咖啡馆小餐厅 good a.好的有本事的;const canvas document.getElementById(gameCanvas);const ctx canvas.getContext(2d);const scoreElement document.getElementById(score);const buttonsContainer document.getElementById(buttons);let dictionary {};let currentWord ;let currentDefinition ;let options [];let successCount 0;let failCount 0;let wordX -100;let moveSpeed 1; // 新增移动速度控制let lastTime 0; // 新增用于控制动画帧率function loadDictionary() {const lines dictionaryData.trim().split(\n);lines.forEach(line {const [word, definition] line.trim().split( , 2);dictionary[word] definition;});}function chooseNewWord() {const words Object.keys(dictionary);currentWord words[Math.floor(Math.random() * words.length)];currentDefinition dictionary[currentWord];options [currentDefinition];while (options.length 4) {const randomDef dictionary[words[Math.floor(Math.random() * words.length)]];if (!options.includes(randomDef)) {options.push(randomDef);}}options.sort(() Math.random() - 0.5);updateButtons();wordX -100;}function updateButtons() {buttonsContainer.innerHTML ;options.forEach((option, index) {const button document.createElement(button);button.textContent option.substring(0, 20) ...;button.onclick () checkAnswer(index);buttonsContainer.appendChild(button);});}function moveWord(currentTime) {// 控制帧率每16ms约60fps更新一次if (currentTime - lastTime 16) {requestAnimationFrame(moveWord);return;}lastTime currentTime;ctx.clearRect(0, 0, canvas.width, canvas.height);ctx.font 24px Arial;ctx.fillText(currentWord, wordX, 100);if (wordX canvas.width) {failCount;updateScore();chooseNewWord();} else {wordX moveSpeed; // 使用moveSpeed控制移动速度}requestAnimationFrame(moveWord);}function checkAnswer(index) {if (options[index] currentDefinition) {successCount;} else {failCount;}updateScore();chooseNewWord();}function updateScore() {scoreElement.textContent 成功: ${successCount} 失败: ${failCount};}function init() {loadDictionary();chooseNewWord();requestAnimationFrame(moveWord);}init();/script /body /html你可以通过调整 moveSpeed 的值来改变单词移动的速度。例如 moveSpeed 0.5; 会使单词移动得更慢 moveSpeed 2; 会使单词移动得更快 上面的JavaScript代码是面向过程的下面使用面向对象方式实现。 使用面向对象方式实现游戏源码如下 !DOCTYPE html html langen headmeta charsetUTF-8meta nameviewport contentwidthdevice-width, initial-scale1.0title单词游戏/titlestylebody {font-family: Arial, sans-serif;display: flex;flex-direction: column;align-items: center;padding: 20px;}#gameCanvas {border: 1px solid black;}#score {align-self: flex-end;margin-bottom: 10px;}#buttons {display: grid;grid-template-columns: 1fr 1fr;gap: 10px;margin-top: 20px;}button {width: 180px;height: 40px;font-size: 14px;}/style /head bodydiv idscore成功: 0 失败: 0/divcanvas idgameCanvas width400 height200/canvasdiv idbuttons/divscript// 字典数据const dictionaryData a art.一(个)每一(个) ability n.能力能耐本领 able a.有能力的出色的 baby n.婴儿孩子气的人 back ad.在后回原处回 background n.背景后景经历 cable n.缆索电缆电报 cafe n.咖啡馆小餐厅 good a.好的有本事的;class WordGame {constructor() {this.canvas document.getElementById(gameCanvas);this.ctx this.canvas.getContext(2d);this.scoreElement document.getElementById(score);this.buttonsContainer document.getElementById(buttons);this.dictionary {};this.currentWord ;this.currentDefinition ;this.options [];this.successCount 0;this.failCount 0;this.wordX -100;this.moveSpeed 1;this.lastTime 0;this.loadDictionary();this.chooseNewWord();this.updateButtons();requestAnimationFrame(this.moveWord.bind(this));}loadDictionary() {const lines dictionaryData.trim().split(\n);lines.forEach(line {const [word, definition] line.trim().split( , 2);this.dictionary[word] definition;});}chooseNewWord() {const words Object.keys(this.dictionary);this.currentWord words[Math.floor(Math.random() * words.length)];this.currentDefinition this.dictionary[this.currentWord];this.options [this.currentDefinition];while (this.options.length 4) {const randomDef this.dictionary[words[Math.floor(Math.random() * words.length)]];if (!this.options.includes(randomDef)) {this.options.push(randomDef);}}this.options.sort(() Math.random() - 0.5);this.wordX -100;}updateButtons() {this.buttonsContainer.innerHTML ;this.options.forEach((option, index) {const button document.createElement(button);button.textContent option.substring(0, 20) ...;button.onclick () this.checkAnswer(index);this.buttonsContainer.appendChild(button);});}moveWord(currentTime) {if (currentTime - this.lastTime 16) {requestAnimationFrame(this.moveWord.bind(this));return;}this.lastTime currentTime;this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);this.ctx.font 24px Arial;this.ctx.fillText(this.currentWord, this.wordX, 100);if (this.wordX this.canvas.width) {this.failCount;this.updateScore();this.chooseNewWord();this.updateButtons();} else {this.wordX this.moveSpeed;}requestAnimationFrame(this.moveWord.bind(this));}checkAnswer(index) {if (this.options[index] this.currentDefinition) {this.successCount;} else {this.failCount;}this.updateScore();this.chooseNewWord();this.updateButtons();}updateScore() {this.scoreElement.textContent 成功: ${this.successCount} 失败: ${this.failCount};}}// 初始化游戏new WordGame();/script /body /html这个面向对象的实现有以下几个主要特点 所有游戏逻辑都封装在 WordGame 类中。 类的构造函数 constructor 初始化所有必要的属性和状态并开始游戏循环。 每个功能都变成了类的方法如 loadDictionary, chooseNewWord, updateButtons 等。
http://www.dnsts.com.cn/news/136894.html

相关文章:

  • wordpress禁用头像郑州网站优化推广培训
  • 阿里云服务器网站开发网络营销论文答辩提问
  • 东莞市网站建设制作设计平台宁波市房产交易信息服务网
  • 顺德网站建设报价管理系统oa
  • 上海做网站的小公司小小影视大全在线观看免费观看
  • 网站免费建站广告机做展示网站要恋用什么程序
  • 制作app的网站哪个好泰州制作公司网站
  • 网站推广的主题北京南站到北京西站地铁怎么走
  • 专业网站建设服务公司哪家好东莞推广系统怎么做
  • 酒泉市建设局网站招标办海外营销推广 平台
  • 旅游景区网站模板让家里的电脑做网站服务器
  • 网站建设验收网络培训远程教育平台
  • 网站建设及推广培训班服务器租用收费
  • 可信赖的购物网站建设网站设计一般多少钱一个页面
  • 网站服务器容量网站建设计划书300
  • 做网站视频网站上虞区住房和城乡建设局网站
  • 医药网站模板湖南住房和建设厅网站
  • 南昌企业网站开发湛江优化网站排名
  • 国外免费个人网站空间wordpress插件怎么做
  • 免费试用网站空间国内家居行业网站开发
  • 网络舆情分析的免费网站全国劳务分包工程信息
  • 做网站难吗_挣钱吗做视频网站要申请什么许可证
  • 南宁手机网站建设公司企业网站外包
  • 个人网站做淘宝客会怎样企业网站模板免费下载
  • 服务器搭建网站跑不满宽带企业安全文化建设导则
  • 绥化建设局网站南通seo网站价格
  • 赤峰网站建设哪个服务好网站建设要懂哪些技术
  • 建网站必备软件哈尔滨市建设工程交易
  • 常宁市城市建设规划管理局网站pantone色卡官网入口
  • 做网站 视频网络公司开发软件