当前位置:网站首页>[Kapok] #Summer Challenge# Hongmeng mini game project - Sudoku (3)
[Kapok] #Summer Challenge# Hongmeng mini game project - Sudoku (3)
2022-08-01 18:52:00 【51CTO】
前言
in the previous sharing,The author describes in detail how to use code layout to create grid areasUI.And in this issue of sharing,The author will add corresponding game functions around the grid area.
上期的内容回顾——>> https://ost.51cto.com/posts/14446

正文
本期,The author will detail an important feature of the game——数字填入的制作方法.
The production of this function is divided into two parts.The first part is to make it whiteButton组件(That is, the white squares in the grid area)Gain focus when clicked by the user,效果图如下:

The orange grid in the figure represents thisButtonThe component is in focus(This square is the last one clicked by the userButton组件),Allows the user to enter numbers.显然,The benefit of this is to locate the grid the user wants to interact with,In order to facilitate the user to perform the operation of filling in the numbers.
The second part provides buttons for filling in numbers and logic codes for adding numbers,效果图如下:

图中,The author first clicked on the white grid in the second row and first column of the grid area,Then click the number marked with it5的圆形按钮,So numbers are generated in the grids of the second row and the first column5.If other circular buttons are clicked,Then other numbers will be generated in the square.
The following author will introduce the specific steps.
Make the white square get focus by clicking
首先,Let's define a new one firstShapeElement对象,Something white in the grid areaButtonAfter the component gets focus,这个ButtonComponents will use thisShapeElementObject defines the background element(It turns orange):
接着,我们先在GameAbilitySlice中找到上期写入的二重for循环的代码:
This code is very important code in this project,He is equivalent to the basic framework of the entire game.in post-production,The author will be based on this二重for循环The framework adds a lot of logic code.
这里,Let's add some code to this code:
在上述代码中,笔者首先将for循环中的ButtonThe object is set to be focusable by touch,接着在ifa judgment branch(number==0)中加入Component state aware listener:when something is satisfiednumber=0的Button组件(That is, the white squares in the grid area)获得焦点时,它将改用element1作为背景元素;when it loses focus,它重新将element0as its background element.
打开模拟机,You can see the corresponding effect:

Provide buttons to fill in numbers and add logic codes to fill in numbers
首先,我们先创建两个Button对象:
之后,我们还需要在二重for循环The corresponding code is written inside:
in this revision,We added two listeners for the white grid and the blue grid in the grid area,Makes both types of grids when clicked,button_temp或者button_emptyis assigned what was clickedButton对象.
接着,我们需要在GameAbilitySlice的UI界面加入6round buttons:
先创建这6button background element:
然后,We use code layout to create6个button对象,代码如下:
Although this code looks long,但实际上每个ButtonThe code templates for objects are all the same.在这段代码中,每个Button对象都定义了6properties and a listener,这6properties include——组件显示的文本(Text),The color of the displayed text of the component(TextColor),The size of the displayed text of the component(TextSize),The component's background element(Background),组件的尺寸(ComponentSize),组件的坐标(Position),And the listener is set执行事件则是为button_temp定义文本内容(i.e. generate numbers on white squares).可以看出,The instructions in the click listener for each circular button are orientedbutton_temp的,而button_tempAgain, it depends on which grid area the user clicks onbutton组件.So the author is creatingbutton_temp与button_empty时,Their properties are not defined,button_tempThe role is as a bridge for digital input,而button_emptyThe role is to preventWhen the user clicks on the blue grid in the grid area,The previous focused white grid can still be entered这么一个BUG.
Let's re-evaluate the logic of digital input:
首先,We randomly click on a white one in the grid areaButton对象(That is, the white square),this whiteButtonThe object gains focus and turns orange,And this whiteButtonobject is assignedbutton_temp(即button_temp=button);之后,We click on the numbers marked with them5的圆形按钮,则button_tempThe display text content of is set to “5”,又因为:button_temp=button,So the previous operation is equivalent to will获得焦点的Button对象(That is the orange square)The display text content is set to “5”,So we can see it on the simulator,Orange grids generate numbers5.When we click on other white squares or blue squares,The orange square that was in focus has lost focus,Color returns to white.

结尾
本期的内容就先分享到这里,更多关于数独小游戏项目精彩的内容我将在下期继续为大家揭晓.
边栏推荐
- University of California | Inverse Reinforcement Learning from Different Third-Person Videos via Graph Abstraction
- 明尼苏达大学团队结合高通量实验与机器学习,实现有效可预测的特定位点重组过程,可调节基因编辑速度
- B005 - STC8 based single chip microcomputer intelligent street light control system
- Prometheus的Recording rules实践
- LeetCode 0152. Product Maximum Subarray: dp + Roll in Place
- Break the performance ceiling!AsiaInfo database supports more than 1 billion users, with a peak of one million transactions per second
- 重保特辑|筑牢第一道防线,云防火墙攻防演练最佳实践
- 【翻译】CNCF培养的OpenMetrics成为一个孵化项目
- 突破性能天花板!亚信数据库支撑 10 多亿用户,峰值每秒百万交易
- 基于flowable的upp(统一流程平台)运行性能优化
猜你喜欢
随机推荐
log factory (detail)
顺序表的简单描述及代码的简单实现
Golang协程调度器scheduler怎么使用
以消费场景为驱动的CMDB要怎么建?
Leetcode75. Color Classification
How to solve the dynamic binding of el-form-item prop attribute does not take effect
在全志V853开发板试编译QT测试
Live chat system technology (8) : vivo live IM message module architecture practice in the system
explain 各字段介绍
No need to crack, install Visual Studio 2013 Community Edition on the official website
Redis的内存淘汰策略和过期删除策略的区别是什么
How to use the Golang coroutine scheduler scheduler
#yyds干货盘点# 面试必刷TOP101: 链表中倒数最后k个结点
屏:全贴合工艺之GFF、OGS、Oncell、Incell
483-82(23、239、450、113)
安徽建筑大学&杭州电子科技大学|基于机器学习方法的建筑可再生能源优化控制
Go GORM transaction instance analysis
Clip-on multimeter use method, how to measure the voltage, current, resistance?
el-form-item prop属性动态绑定不生效如何解决
Use of message template placeholders








