当前位置:网站首页>[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.
结尾
本期的内容就先分享到这里,更多关于数独小游戏项目精彩的内容我将在下期继续为大家揭晓.
边栏推荐
- COS User Practice Call for Papers
- 2022年 PHP面试问题记录
- How opencv implements image skew correction
- Summer vacation second week wrap-up blog
- 云原生全景图详解
- 塔防海岸线用户协议
- University of California | Inverse Reinforcement Learning from Different Third-Person Videos via Graph Abstraction
- A simple Flask PIN
- Leetcode75. 颜色分类
- Review实战经典:2 种封装风格,你偏爱哪种?
猜你喜欢
How to build a CMDB driven by consumption scenarios?
基于flowable的upp(统一流程平台)运行性能优化
Redis的内存淘汰策略和过期删除策略的区别是什么
Become a Contributor in 30 minutes | How to participate in OpenHarmony's open source contributions in multiple ways?
B001 - Intelligent ecological fish tank based on STM32
How many steps does it take to convert an ENS domain name into music?
explain each field introduction
[Neural Network] This article will take you to easily analyze the neural network (with an example of spoofing your girlfriend)
shell脚本专题(07):文件由cfs到bos
阿里云的域名和ip绑定
随机推荐
MySQL 45 Talk | 09 How to choose common index and unique index?
AntDB database appeared in the 24th high-speed exhibition, helping smart high-speed innovative applications
No need to crack, install Visual Studio 2013 Community Edition on the official website
Leetcode73. 矩阵置零
MySQL数据库————流程控制
WinRAR | Generate multiple installers into one installer
金鱼哥RHCA回忆录:CL210管理OPENSTACK网络--章节实验
MLX90640 红外热成像仪测温模块开发笔记(完整篇)
在Map传值与对象传值中模糊查询
C#/VB.NET:从 PDF 文档中提取所有表格
【LeetCode】Day109-最长回文串
MySQL数据库————存储过程和函数
Keras深度学习实战——交通标志识别
Live chat system technology (8) : vivo live IM message module architecture practice in the system
C language theory--a solid foundation for the written test and interview
国标GB28181协议EasyGBS平台兼容老版本收流端口的功能实现
Become a Contributor in 30 minutes | How to participate in OpenHarmony's open source contributions in multiple ways?
重保特辑|拦截99%恶意流量,揭秘WAF攻防演练最佳实践
Selenium在远程中的截图
University of California | Inverse Reinforcement Learning from Different Third-Person Videos via Graph Abstraction