当前位置:网站首页>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
边栏推荐
- Promote QT default control to custom control
- Advanced transfer learning
- 机器学习理论之(7):核函数 Kernels —— 一种帮助 SVM 实现非线性化决策边界的方式
- ESP32 LVGL8. 1 - anim animation (anim 16)
- QT error: no matching member function for call to ‘connect‘
- Machine learning theory (7): kernel function kernels -- a way to help SVM realize nonlinear decision boundary
- Eight bit binary multiplier VHDL
- 配置iptables
- 简化路径(力扣71)
- Esp32 (UART ecoh) - serial port echo worm learning (2)
猜你喜欢

从技术体系到商业洞察,中小研发团队架构实践之收尾篇

ESP32 LVGL8. 1 - checkbox (checkbox 23)

纠结

【科普】CRC校验(一)什么是CRC校验?

Resolution: cnpm: unable to load file \cnpm. PS1, because running scripts is prohibited on this system

Eight bit binary multiplier VHDL

ctfshow-web362(SSTI)

Promote QT default control to custom control

Introduction to ROS learning notes (II)

Solutions such as unknown or garbled code or certificate problem prompt in Charles's mobile phone packet capture, actual measurement.
随机推荐
ESP32 LVGL8. 1 - input devices (input devices 18)
Setting up keil environment of GD single chip microcomputer
微搭低代码零基础入门课(第三课)
STM32: LCD显示
ESP32 LVGL8. 1 - label (style 14)
Nacos作为服务注册中心
玻璃体中的硫酸软骨素
机器学习理论之(8):模型集成 Ensemble Learning
22 year flying Book manpower Kit
教你用简单几个步骤快速重命名文件夹名
Druid SQL和Security在美团点评的实践
Go language GUI framework Fyne Chinese garbled or not displayed
Recyclerview control list item layout match_ Fundamental principle of parent attribute invalidation
Feature selection feature_ selection--SelectKBest
SQL中函数 decode()与 replace()的用法
K210 serial communication
Golang 语言实现TCP UDP通信
解决:cnpm : 無法加載文件 ...\cnpm.ps1,因為在此系統上禁止運行脚本
Halo open source project learning (VII): caching mechanism
Kettle paoding jieniu Chapter 17 text file output