当前位置:网站首页>[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.
结尾
本期的内容就先分享到这里,更多关于数独小游戏项目精彩的内容我将在下期继续为大家揭晓.
边栏推荐
- 文库网站建设源码分享
- 腾讯云主机安全 x 轻量应用服务器|强强联合主机安全普惠版重磅发布
- C language theory--a solid foundation for the written test and interview
- How to record and analyze your alchemy process - use notes of the visual artifact Wandb [1]
- Leetcode73. Matrix Zeroing
- Review实战经典:2 种封装风格,你偏爱哪种?
- SQL函数 TO_DATE(一)
- Redis的内存淘汰策略和过期删除策略的区别是什么
- 屏:全贴合工艺之GFF、OGS、Oncell、Incell
- kubernetes-部署nfs存储类
猜你喜欢
Summer vacation second week wrap-up blog
在全志V853开发板试编译QT测试
Leetcode75. Color Classification
MySQL 45 Talk | 09 How to choose common index and unique index?
How many steps does it take to convert an ENS domain name into music?
云原生全景图详解
XML配置
[pyqt5] Custom controls to achieve scaling sub-controls that maintain the aspect ratio
MySQL数据库————流程控制
将ENS域名转化为音乐需要几步?
随机推荐
opencv syntax Mat type summary
How to record and analyze your alchemy process - use notes of the visual artifact Wandb [1]
Multi-Party Threshold Private Set Intersection with Sublinear Communication-2021:解读
直播系统聊天技术(八):vivo直播系统中IM消息模块的架构实践
想随时、随地、随心使用数据库的朋友们,全体注意!
el-form-item prop属性动态绑定不生效如何解决
Tower Defense Shoreline User Agreement
Map by value
面试必问的HashCode技术内幕
Go GORM事务实例分析
7月30号|来一场手把手助您打造智能视觉新爆款的技术动手实验
用VS2013编译带boost库程序时提示 fatal error C1001: 编译器中发生内部错误
首篇 NLP 领域图神经网络综述:127 页,从图构建到实际应用面面观
暑假第二周总结博客
How to use the Golang coroutine scheduler scheduler
公用函数----mfc
A simple Flask PIN
The life cycle and scope
Live chat system technology (8) : vivo live IM message module architecture practice in the system
B005 - STC8 based single chip microcomputer intelligent street light control system