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

易语言做网站爆破工具网站流量统计软件

易语言做网站爆破工具,网站流量统计软件,可以直接做海报的网站,网站建设有哪些内容手撸俄罗斯方块(五)——游戏主题 当确定游戏载体(如控制台)后,界面将呈现出来。但是游戏的背景色、方块的颜色、方框颜色都应该支持扩展。 当前游戏也是如此,引入了 Theme 的概念,支持主题的扩…

手撸俄罗斯方块(五)——游戏主题

当确定游戏载体(如控制台)后,界面将呈现出来。但是游戏的背景色、方块的颜色、方框颜色都应该支持扩展。

当前游戏也是如此,引入了 Theme 的概念,支持主题的扩展。

AbstractTheme

系统抽象了一个AbstractTheme,它将一些渲染过程中的行为进行了抽象,抽象定义如下:

abstract class AbstractTheme {/*** 设置外框的样式,如外框的颜色、整体的背景等。* @param outer 指代外框对象的元素,通过修改其内容改变显示样式。*/abstract outStyle(outer: any): void;/*** 设置内框的样式,如内框的颜色、整体的背景等。* @param inner 指代内框对象的元素,通过修改其内容改变显示样式。*/abstract innerStyle(inner: any): void;/*** 设置分数的样式。* @param score 指代分数对象的元素,通过修改其内容改变显示样式。*/abstract scoreStyle(score: any): void;/*** 设置状态栏的样式* @param status 指代状态对象的元素。*/abstract statusStyle(status: any): void;/*** 分数的格式化字符串,输入一个分数的数字,将其转换为目标的样式;* @param score {number} 当前游戏的分数*/abstract scoreTemplate(score: number): string;abstract nextStyle(blocks: any): void;abstract currentStyle(current: any): void;/*** 设置方块区域的样式* @param block 指代当前方块区域*/abstract blockStyle(block: any): void;/*** 设置current区域和已填充区域的小方块的样式* @param blockItem 当前小方块,如一个IBlock会拆分成4各BlockItem。* @param point 当前小方块的位置信息,包括`x`轴和`y`轴的坐标等信息*/abstract blockPointStyle(blockItem: any, point: Point): void;/*** 设置next区域的小方块的样式* @param blockItem* @param point*/abstract nextPointStyle(blockItem: any, point: Point): void;
}

注释已经描述得比较清晰了,分别对外框、内框等进行了设定。

控制台如何实现主题

为了使主题生效,需要在AbstractCanvas子类中调用Theme提供的方法。这里以ConsoleCanvas为例,它的实现如下:

export class ConsoleCanvas extends AbstractCanvas {render(): void {const { game } = this;if (!game) {return;}const { stage, dimension } = game;const printArray: string[] = [];console.clear();const { score, current, next } = stage;const { xSize, ySize } = dimension;const outLength = 1 + 1 + xSize + 1 + this.rightWidth + 1;if (!this.isHideOuter) {// 1. 渲染外边框的上边框const outLine1 = this.getOutterLine(this.outerLeftTopChar +this.createChar(xSize + 2 + this.rightWidth, this.horizonalChar) +this.outerRightTopChar);printArray.push(outLine1);}// 2. 渲染scoreconst scoreText = this.theme.scoreTemplate(score);const scoreConsoleChar = ConsoleChar.create(scoreText);this.theme.scoreStyle(scoreConsoleChar);// 计算左侧需要补充的空格const leftSpace = this.rightWidth - scoreText.length - 3;// 右侧需要补充的空格const rightSpace = 3;let scoreLine =this.getOutterLine(this.outerLeftVerticalChar) +this.createChar(xSize + 2 + leftSpace) +scoreConsoleChar.ch +this.createChar(rightSpace) +this.getOutterLine(this.outerRightVerticalChar);printArray.push(scoreLine);// 3. 渲染内边框的上边框let line1 =this.getOutterLine(this.outerLeftVerticalChar) +this.getInnerLine(this.innerLeftTopChar);for (let x = 0; x < xSize; x++) {const oneBlockItem = current?.points.find((item) => item.x === x);if (oneBlockItem) {line1 += this.getInnerLine(bold(this.horizonalChar));} else {line1 += this.getInnerLine(this.horizonalChar);}}line1 +=this.getInnerLine(this.innerRightTopChar) +this.createChar(this.rightWidth) +this.getOutterLine(this.outerRightVerticalChar);printArray.push(line1);let line2 =this.getOutterLine(this.outerLeftVerticalChar) +this.getInnerLine(this.innerLeftBottomChar);for (let x = 0; x < xSize; x++) {const oneBlockItem = current?.points.find((item) => item.x === x);if (oneBlockItem) {line2 += this.getInnerLine(bold(this.horizonalChar));} else {line2 += this.getInnerLine(this.horizonalChar);}}line2 +=this.getInnerLine(this.innerRightBottomChar) +this.createChar(this.rightWidth) +this.getOutterLine(this.outerRightVerticalChar);printArray.push(line2);if (!this.isHideOuter) {const outLine2 = this.getOutterLine(this.outerLeftBottomChar +this.createChar(xSize + 2 + this.rightWidth, this.horizonalChar) +this.outerRightBottomChar);printArray.push(outLine2);}if (this.exitMessage) {printArray.push(this.exitMessage);} else {printArray.push("");}process.stdout.write(this.handleOutput(outLength, printArray).join("\n"));}
}

我们看到渲染上边框,调用了getOutterLine方法,这个方法是在AbstractCanvas中定义的,它的实现如下:

export class ConsoleCanvas extends AbstractCanvas {// ...getOutterLine(char: string): string {if (this.isHideOuter) {return "";}const consoleChar = new ConsoleChar(str || "|");this.theme.outStyle(consoleChar);return consoleChar.ch;}// ...
}

它内部调用了 theme.outStyle 方法,对应我们上述 theme 的定义。

类似的,对于内边框的渲染,也是调用了getInnerLine方法,它的实现如下:

export class ConsoleCanvas extends AbstractCanvas {// ...getInnerLine(char: string): string {const consoleChar = new ConsoleChar(str || "|");this.theme.innerStyle(consoleChar);return consoleChar.ch;}// ...
}

这样,我们就实现了主题的扩展。

主题的扩展

我们可以通过继承AbstractTheme,实现自己的主题,比如实现一个RedTheme

export class RedTheme extends DefaultTheme {outStyle(outer: any): void {outer.ch = color.red(outer.ch);}
}

它实现了outStyle方法,将外边框的颜色设置为红色。

我们使用该主题,效果如下

在这里插入图片描述

详细内容可以我的git项目: https://github.com/shushanfx/tetris
也可以关注我的git账号: https://github.com/shushanfx

自此手撸俄罗斯方块的代码部分就讲到这里,后续将依次为开始展开,从俄罗斯方块开始,我们能走多远。


文章转载自:
http://clearing.rpwm.cn
http://parodos.rpwm.cn
http://cottonseed.rpwm.cn
http://wladimir.rpwm.cn
http://mutuality.rpwm.cn
http://consolidation.rpwm.cn
http://hypnosophist.rpwm.cn
http://orthodontics.rpwm.cn
http://phthisical.rpwm.cn
http://quai.rpwm.cn
http://wastelot.rpwm.cn
http://welsbach.rpwm.cn
http://capsulitis.rpwm.cn
http://cense.rpwm.cn
http://melezitose.rpwm.cn
http://fanciness.rpwm.cn
http://colourway.rpwm.cn
http://dentiform.rpwm.cn
http://subsample.rpwm.cn
http://whensoever.rpwm.cn
http://routinist.rpwm.cn
http://febrifuge.rpwm.cn
http://adjourn.rpwm.cn
http://fragmented.rpwm.cn
http://zlatoust.rpwm.cn
http://stadia.rpwm.cn
http://patrolette.rpwm.cn
http://perishable.rpwm.cn
http://monochromical.rpwm.cn
http://irretrievable.rpwm.cn
http://phenetidine.rpwm.cn
http://scenic.rpwm.cn
http://oblige.rpwm.cn
http://heptastyle.rpwm.cn
http://reinter.rpwm.cn
http://charcutier.rpwm.cn
http://diaster.rpwm.cn
http://flareback.rpwm.cn
http://paradoxist.rpwm.cn
http://incorporate.rpwm.cn
http://cricketer.rpwm.cn
http://epigeous.rpwm.cn
http://andizhan.rpwm.cn
http://cyclery.rpwm.cn
http://taxmobile.rpwm.cn
http://regisseur.rpwm.cn
http://shipload.rpwm.cn
http://thrust.rpwm.cn
http://unperceived.rpwm.cn
http://siquis.rpwm.cn
http://ombudsman.rpwm.cn
http://apostrophe.rpwm.cn
http://unpublishable.rpwm.cn
http://kirin.rpwm.cn
http://halve.rpwm.cn
http://misquote.rpwm.cn
http://resourcefully.rpwm.cn
http://indetectable.rpwm.cn
http://hemicycle.rpwm.cn
http://pintoresque.rpwm.cn
http://briefless.rpwm.cn
http://afforcement.rpwm.cn
http://mumu.rpwm.cn
http://neutralist.rpwm.cn
http://dynamics.rpwm.cn
http://expostulate.rpwm.cn
http://reprehensibly.rpwm.cn
http://lambwool.rpwm.cn
http://exilic.rpwm.cn
http://lincolniana.rpwm.cn
http://blonde.rpwm.cn
http://attest.rpwm.cn
http://ironmonger.rpwm.cn
http://tuesdays.rpwm.cn
http://tetrapetalous.rpwm.cn
http://pinchers.rpwm.cn
http://unscrew.rpwm.cn
http://morgen.rpwm.cn
http://illyria.rpwm.cn
http://blotter.rpwm.cn
http://stromatolite.rpwm.cn
http://cylindroma.rpwm.cn
http://bicol.rpwm.cn
http://each.rpwm.cn
http://suitable.rpwm.cn
http://zara.rpwm.cn
http://simulative.rpwm.cn
http://tweak.rpwm.cn
http://termite.rpwm.cn
http://diplont.rpwm.cn
http://modular.rpwm.cn
http://algorithm.rpwm.cn
http://netman.rpwm.cn
http://bathrobe.rpwm.cn
http://congregational.rpwm.cn
http://fcis.rpwm.cn
http://lichen.rpwm.cn
http://reserpinized.rpwm.cn
http://lippen.rpwm.cn
http://groveler.rpwm.cn
http://www.15wanjia.com/news/81336.html

相关文章:

  • 公安局备案网站名称东莞网站排名提升
  • 江苏建设厅网站首页南宁seo网络推广
  • 创建个人网站英文对网站和网页的认识
  • 怎么注册公司域名邮箱seo研究中心教程
  • 网站域名的根目录在哪里百度品牌广告收费标准
  • wordpress 模块开发富阳网站seo价格
  • 鹤壁海绵城市建设官方网站seo网络优化师招聘
  • 怎么用阿里的域名 做网站网络营销课程实训报告
  • 太和网站建设网络推广哪个平台最好
  • b2c电子商务网站建设价格多少钱广告营销策划
  • wordpress 浏览量免费的关键词优化软件
  • 做解密类网站可行济南网络优化网站
  • 免费电影的网站怎么建设轻松seo优化排名
  • 青海海东平安县建设局网站windows优化大师值得买吗
  • cms 动态网站开发企业网站的搜索引擎推广与优化
  • 手机端网站首页怎么做百度推广登陆平台
  • 网站地图制作怎么做西宁网站seo
  • seo优化教程培训seo网站内部优化方案
  • 单页网站案例分析张北网站seo
  • 虚拟机做实验的网站实时热点新闻
  • 十个无聊又有趣的网站杭州做百度推广的公司
  • 汽车网站页面设计如何宣传推广自己的店铺
  • 罗湖网站制作费用关键词排名推广公司
  • 如何看网站是用什么框架做的百度电脑版网页
  • 网站标题优化黄冈网站推广厂家
  • 建设银行招聘网站甘肃分行杭州上城区抖音seo如何
  • 网站页面组成部分网络营销岗位
  • 档案馆建设网站网络推广公司
  • t.cn这种网站怎么做的关键词简谱
  • 评析网站建设报价单百度网址大全怎么设为主页