当前位置:网站首页>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
- 使用 bitnami/postgresql-repmgr 镜像快速设置 PostgreSQL HA
- Simple use of viewbinding
- : app: transformclasseswithrobustfordevrease meituan hot repair compilation error record
- Resolution: cnpm: unable to load file \cnpm. PS1, because running scripts is prohibited on this system
- ESP32 LVGL8. 1 - slider slider (slider 22)
- 实战业务优化方案总结---主目录---持续更新
- Daily CISSP certification common mistakes (April 19, 2022)
- 使用晨曦记账本,分析某个时间段每个账户收支结余
- Introduction to ROS learning notes (II)
猜你喜欢

CANopen STM32 transplantation

ctfshow-web361(SSTI)

Esp32 (UART ecoh) - serial port echo worm learning (2)

ESP32 LVGL8. 1 - msgbox message box (msgbox 28)

Esp32 drive encoder -- siq-02fvs3 (vscade + IDF)

MVVM model

七、DOM(下) - 章节课后练习题及答案

Esp32 (UART 485 communication) - 485 communication of serial port (3)

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

listener.log
随机推荐
MVVM model
ESP32 LVGL8. 1 - bar progress bar (bar 21)
特征选择feature_selection--SelectKBest
K210 serial communication
One of the reasons why the WebView web page cannot be opened (and some WebView problem records encountered by myself)
Seata handles distributed transactions
MySQL statement
QT error: no matching member function for call to ‘connect‘
The type initializer for ‘Gdip‘ threw an exception
SQL中函数 decode()与 replace()的用法
12个例子夯实promise基础
Practice of Druid SQL and security in meituan review
ESP32 LVGL8. 1 - BTN button (BTN 15)
Scrollto and scrollby
ESP32 LVGL8. 1 - anim animation (anim 16)
Simple use of navigation in jetpack
ctfshow-web362(SSTI)
Use stm32cube MX / stm32cube ide to generate FatFs code and operate SPI flash
深入理解 Golang 中的 new 和 make 是什么, 差异在哪?
Implementation of TCP UDP communication with golang language