当前位置:网站首页>Minesweeping II of souI instance
Minesweeping II of souI instance
2022-04-23 18:52:00 【Brick Porter】
List of articles
Preface
Follow the above minesweeping game , A displayed minefield interface has been established above . This chapter realizes the right-click mark .
One 、 stay XX Find a picture or yourself on PS And define it as skin
1.1 copy Picture to uires\image My name here is flag.png
1.2 uires Add below
<IMG>
<file name="flag" path="image\flag.png"/>
</IMG>
1.3 skin.xml Define a skin
<imglist name="skin_flag" src="img:flag" states="2"/>
1.4 Give... In the defined template img Specify this skin
<?xml version="1.0" encoding="utf-8"?>
<template>
<mine>
<window skin="mine_bkskin" size="26,26" columnWeight="1" rowWeight="1">
<img name="flag" pos="|,|" skin="skin_flag" show="0" offset="-0.5,-0.5" size="-1,-1"/>
<text name="minecount" pos="|,|" show="0" offset="-0.5,-0.5" size="-1,-1" text="1"/>
</window>
</mine>
</template>
Two 、 Add processing functions
#pragma once
#include <core/SWnd.h>
#include <vector>
#include <layout/SGridLayout.h>
#include <sstream>
/// <summary>
/// Mark the grid status
/// </summary>
enum class MINE_STATE {
normal,// routine
flag,// Mark
open// open
};
#define ICON_MAX_INDEX 1
/// <summary>
/// A grid represents a minefield
/// </summary>
class CMine
{
MINE_STATE m_mineState = MINE_STATE::normal;
private:
SWindow* _pWnd = nullptr;
int _iiconIndex = 0;
size_t _uminecount = 0;
public:
CMine()
{
}
SWindow* getWnd()
{
return _pWnd;
}
void reset()
{
m_mineState = MINE_STATE::normal;
_iiconIndex = 0;
_pWnd->FindChildByName(L"flag")->SetVisible(FALSE);
_pWnd->FindChildByName(L"minecount")->SetVisible(FALSE);
_pWnd->EnableWindow(TRUE);
}
//EventLButtonUp
bool OnLButtonUp(EventLButtonUp* e)
{
//SWindow* _pWnd = sobj_cast<SWindow>(e->sender);
if (canLClick())
{
m_mineState = MINE_STATE::open;
}
return true;
}
// EventCtxMenu
bool OnRButtonDown(EventCtxMenu* e)
{
//SWindow* _pWnd = sobj_cast<SWindow>(e->sender);
if (canRClick())
{
if (m_mineState == MINE_STATE::flag)
if (++_iiconIndex > ICON_MAX_INDEX)
{
_iiconIndex = 0;
m_mineState = MINE_STATE::normal;
_pWnd->FindChildByName(L"flag")->SetVisible(FALSE, TRUE);
}
else
{
_pWnd->FindChildByName2<SImageWnd>(L"flag")->SetIcon(_iiconIndex);
}
else
{
m_mineState = MINE_STATE::flag;
_pWnd->FindChildByName2<SImageWnd>(L"flag")->SetIcon(_iiconIndex);
_pWnd->FindChildByName(L"flag")->SetVisible(TRUE,TRUE);
}
}
return true;
}
void attackWnd(SWindow* pWnd)
{
SASSERT(pWnd);
SASSERT(!_pWnd);
_pWnd = pWnd;
_pWnd->GetEventSet()->subscribeEvent(&CMine::OnLButtonUp, this);
_pWnd->GetEventSet()->subscribeEvent(&CMine::OnRButtonDown, this);
}
~CMine()
{
}
// To obtain state
MINE_STATE getState()const {
return m_mineState;
}
// Whether to click on
bool isOpen()const {
return m_mineState == MINE_STATE::open;
}
// Can I left click
bool canLClick()const {
return m_mineState == MINE_STATE::normal;
}
// Can I right-click
bool canRClick()const {
return m_mineState != MINE_STATE::open;
}
// Get icon drawing status
int getCurIndex()const {
return _iiconIndex;
}
// Get icon drawing status
int getNextIndex() {
++_iiconIndex;
SASSERT(_iiconIndex >= 0);
if (_iiconIndex >= ICON_MAX_INDEX)
_iiconIndex = 0;
return _iiconIndex;
}
public:
#define MAX_COL 16
#define MAX_ROW 30
#define MIN_COL 9
#define MIN_ROW 9
/// <summary>
/// Create a minefield
/// </summary>
/// <param name="parent"> Minefield window template </param>
/// <param name="strName"> Minefield window template </param>
/// <param name="mines"> Minefield data </param>
/// <param name="row"> That's ok </param>
/// <param name="col"> Column </param>
/// <returns></returns>
static std::vector<std::vector<CMine>>& createMine(
SWindow* parent,
const SStringT& strName,
std::vector<std::vector<CMine>>& mines,
const size_t col,
const size_t row)
{
SASSERT(parent);
if (!parent)
return mines;
{
SGridLayout* param = sobj_cast<SGridLayout>(parent->GetLayout());
SASSERT(param);
std::wstringstream os;
os << col;
param->SetAttribute(L"columnCount", os.str().c_str());
}
for (auto& ite1 : mines)
{
for (auto& ite2 : ite1)
{
SWindow* _pWnd = ite2.getWnd();
if (_pWnd)
{
SWindow* _Parent = _pWnd->GetParent();
if (_Parent)
{
_Parent->DestroyChild(_pWnd);
}
}
}
}
mines.clear();
mines.resize(row);
for (int r = 0; r < row; r++)
{
mines[r].resize(col);
}
SStringW strXml = GETTEMPLATEPOOLMR->GetTemplateString(strName);
SASSERT(!strXml.IsEmpty());
if (!strXml.IsEmpty())
{
pugi::xml_document xmlDoc;
if (xmlDoc.load_buffer_inplace(strXml.GetBuffer(strXml.GetLength()), strXml.GetLength() * sizeof(WCHAR), 116, pugi::encoding_utf16))
{
pugi::xml_node xmlTemp = xmlDoc.first_child();
SASSERT(xmlTemp);
for (int r = 0; r < row; r++)
for (int c = 0; c < col; c++)
{
SWindow* pChild = SApplication::getSingleton().CreateWindowByName(xmlTemp.name());
if (pChild)
{
parent->InsertChild(pChild);
pChild->InitFromXml(xmlTemp);
mines[r][c].attackWnd(pChild);
}
}
}
}
return mines;
}
};
summary
Tips : That's what we're going to talk about today .
版权声明
本文为[Brick Porter]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210603257720.html
边栏推荐
- 昇腾 AI 开发者创享日全国巡回首站在西安成功举行
- Fundamentals of machine learning theory -- some terms about machine learning
- C language simulates entering and leaving the stack, first in first out, first in first out, shared memory
- Introduction to ROS learning notes (I)
- Yyds dry goods inventory stringprep --- Internet string preparation
- About the operation of unit file reading (I)
- Tencent map and high logo removal method
- Ctfshow - web362 (ssti)
- Résolution: cnpm: impossible de charger le fichier... Cnpm. PS1 parce que l'exécution de scripts est désactivée sur ce système
- QT curve / oscilloscope customplot control
猜你喜欢
12 examples to consolidate promise Foundation
ESP32 LVGL8. 1 - slider slider (slider 22)
解决:cnpm : 无法加载文件 ...\cnpm.ps1,因为在此系统上禁止运行脚本
视频边框背景如何虚化,简单操作几步实现
Chondroitin sulfate in vitreous
ESP32 LVGL8. 1 - bar progress bar (bar 21)
微搭低代码零基础入门课(第三课)
简化路径(力扣71)
ctfshow-web362(SSTI)
Esp32 (UART event) - serial port event learning (1)
随机推荐
Coolweather is revised and connected to the wind weather interface to realize the broken line diagram of temperature
MVVM model
One of the reasons why the WebView web page cannot be opened (and some WebView problem records encountered by myself)
The corresponding permissions required to automatically open the app in the setting interface through accessibility service
解决:cnpm : 无法加载文件 ...\cnpm.ps1,因为在此系统上禁止运行脚本
#yyds干货盘点#stringprep --- 因特网字符串预备
ESP32 LVGL8. 1 - BTN button (BTN 15)
: app: transformclasseswithrobustfordevrease meituan hot repair compilation error record
ESP32 LVGL8. 1 - event (event 17)
About the operation of unit file reading (I)
Setting up keil environment of GD single chip microcomputer
QT curve / oscilloscope customplot control
Excel intercept text
ESP32 LVGL8. 1 - calendar (calendar 25)
Scrollto and scrollby
Iptables - L executes slowly
iptables -L执行缓慢
Fundamentals of machine learning theory -- some terms about machine learning
With the use of qchart, the final UI interface can be realized. The control of qweight can be added and promoted to a user-defined class. Only the class needs to be promoted to realize the coordinate
ESP32 LVGL8. 1 - msgbox message box (msgbox 28)