当前位置:网站首页>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
边栏推荐
- Use of content provider
- Esp32 (UART ecoh) - serial port echo worm learning (2)
- 实战业务优化方案总结---主目录---持续更新
- Nacos as service registry
- CANopen STM32 transplantation
- Summary of actual business optimization scheme - main directory - continuous update
- ESP32 LVGL8. 1 - img picture (IMG 20)
- The type initializer for ‘Gdip‘ threw an exception
- 【历史上的今天】4 月 23 日:YouTube 上传第一个视频;网易云音乐正式上线;数字音频播放器的发明者出生
- Advanced transfer learning
猜你喜欢
iptables -L执行缓慢
Practice of Druid SQL and security in meituan review
Use bitnami / PostgreSQL repmgr image to quickly set up PostgreSQL ha
iptables初探
简化路径(力扣71)
玻璃体中的硫酸软骨素
[popular science] CRC verification (I) what is CRC verification?
PyGame tank battle
使用晨曦记账本,分析某个时间段每个账户收支结余
Download xshell 6 and xftp6 official websites
随机推荐
os_ authent_ Prefix
ESP32 LVGL8. 1. Detailed migration tutorial of m5stack + lvgl + IDF (27)
The first leg of the national tour of shengteng AI developer creation and enjoyment day was successfully held in Xi'an
Sentinel服务熔断实战(sentinel整合ribbon+openFeign+fallback)
机器学习理论基础篇--关于机器学习的一些术语
After opening the original normal project, the dependency package displays red and does not exist.
Nacos集群搭建和mysql持久化配置
[mathematical modeling] - analytic hierarchy process (AHP)
Click the input box to pop up the keyboard layout and move up
Tangle
Iptables - L executes slowly
Nacos作为服务配置中心实战
Download xshell 6 and xftp6 official websites
ESP32 LVGL8. 1 - slider slider (slider 22)
Nacos作为服务注册中心
Practice of Druid SQL and security in meituan review
教你用简单几个步骤快速重命名文件夹名
Promote QT default control to custom control
#yyds干货盘点#stringprep --- 因特网字符串预备
Yyds dry goods inventory stringprep --- Internet string preparation