QQ游戏连连看外挂(VC)

大概的思路是这样的:首先1.找到游戏窗口->
                                                2.解析方块的位置、图案->
                                                3.遍历方块,找到可以消去的方块->
                                                4.计算方块在窗口中的位置,模拟鼠标点击。 

 



大家都知道连连看的规则是:如果两个方块的连线小于等于两个直角时,这对方块就可以消去。所以除了两个方块之间用直线连接外,还有另外这两种情况。

 

1.一个直角
连连看示意图-1

2.两个直角

连连看示意图-2

根据上述情况,就可以归纳出一种统一的算法。即:首先找出图案相同的两个方块,分别向他们的四个方向引出四条线段,线段的另一端终止于边缘,或者其它的方块处。分别判断水平与水平、竖直与竖直方向的线段的横坐标、纵坐标是否有交集。如果没有两个方向都没有交集,则这两个方块不能消去。如果有,再在任一条线段有交集的位置向另一条线段连线,如果连线成功(中间无无方块阻碍或者两线段相连),则两方块可以消去。 

至于方块图案的判断,是因为背景的图案颜色非常靠近(现在“角色版”索性为单色背景),分别取最亮处,与最暗处的RGB值。找出R,G,B值的最大、最小值。判断的时候是在方块上取出任意几个点的(程序中为4个点)RGB值,如果这四个点的R,G,B值都在背景色R,G,B的最大、最小值的范围内,则断定这个方格上没有方块。

其中比较重要的两个技巧就是这样。我把主要的代码贴出来:

class  CLLKer  
{
public:
    CLLKer();
    
virtual ~CLLKer();

    
// 设置窗口标题
    void SetWndCaption(CString strCaption){ m_strWndCaption = strCaption; }

    
// 设置方块个数
    void SetCellCount(UINT nHorCount, UINT nVerCount) 
        m_nHorCellCount 
= nHorCount;
        m_nVerCellCount 
= nVerCount;
    }


    
// 设置单元格大小
    void SetCellSize(UINT nWidth, UINT nHeight) {
        m_nCellWidth 
= nWidth;
        m_nCellHeight 
= nHeight;
    }

    
    
// 设置边界
    void SetMagin(UINT nLeft, UINT nTop) {
        m_nMargin_X 
= nLeft;
        m_nMargin_Y 
= nTop;
    }
    

    


    BOOL LockWnd();                    
// 锁定窗口
    UINT Encode();                    // 扫描窗口记录布局信息
    BOOL EliminateOnePair();
    
void EliminateAll();
    
    BOOL CheckWnd();
    
void Reset();

private:
    
    
//
    // 功能函数
    int CompareTowColor(COLORREF cColor1, COLORREF cColor2);    // 返回两颜色的RGB的差值和
    int SearchColor(COLORS color);                            // 取得颜色相同的Cell索引值

    
void FindXLine(const POS& pos, int& iLeft, int& iRight);            // 取得水平方向的路径
    void FindYLine(const POS& pos, int& iTop, int& iLow);                // 取得竖直方向的路径

    BOOL IsXPath(
const POS& pos1, const POS& pos2);        // 水平方向的路径是否相通
    BOOL IsYPath(const POS& pos1, const POS& pos2);        // 竖直方向的路径是否相通
    BOOL IsPath(const POS& pos1, const POS& pos2);        // 判断两单元格是否存在连通路径

    BOOL FindMatchingCell(
const POS& pos, POS& posMathed);    // 找到指定方块的匹配方块
    BOOL FindPair(POS& posOri, POS& posMathed);                // 找到一对可消除的方块

    
void ReleaseData();

    
//
    // 中间变量
    int **m_pMap;            // 单元格布局
    CWnd *m_pWnd;            // 游戏窗口
    vector<CELL> m_vCells;    // 单元格信息

    
//
    // 参数
    CString m_strWndCaption;
    UINT m_nHorCellCount;
    UINT m_nVerCellCount;
    UINT m_nCellWidth;
    UINT m_nCellHeight;
    UINT m_nMargin_X;
    UINT m_nMargin_Y;

    UINT m_nMax_R;
    UINT m_nMax_G;
    UINT m_nMax_B;
    UINT m_nMin_R;
    UINT m_nMin_G;
    UINT m_nMin_B;
}
;

 

class  CAboutDlg :  public  CDialog
{
public:
    CAboutDlg();

// Dialog Data
    
//{{AFX_DATA(CAboutDlg)
    enum { IDD = IDD_ABOUTBOX };
    
//}}AFX_DATA

    
// ClassWizard generated virtual function overrides
    
//{{AFX_VIRTUAL(CAboutDlg)
    protected:
    
virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    
//}}AFX_VIRTUAL

// Implementation
protected:
    
//{{AFX_MSG(CAboutDlg)
    
//}}AFX_MSG
    DECLARE_MESSAGE_MAP()
}
;

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
    
//{{AFX_DATA_INIT(CAboutDlg)
    
//}}AFX_DATA_INIT
}


void  CAboutDlg::DoDataExchange(CDataExchange *  pDX)
{
    CDialog::DoDataExchange(pDX);
    
//{{AFX_DATA_MAP(CAboutDlg)
    
//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    
// {{AFX_MSG_MAP(CAboutDlg)
        
//  No message handlers
    
// }}AFX_MSG_MAP
END_MESSAGE_MAP()

/////
//  CLLKDlg dialog

CLLKDlg::CLLKDlg(CWnd
*  pParent  /*=NULL*/ )
    : CDialog(CLLKDlg::IDD, pParent)
{
    
//{{AFX_DATA_INIT(CLLKDlg)
    m_bAutoElmit = FALSE;
    m_bIsTopMost 
= FALSE;
    
//}}AFX_DATA_INIT
    
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

    m_bStarted 
= FALSE;
}


void  CLLKDlg::DoDataExchange(CDataExchange *  pDX)
{
    CDialog::DoDataExchange(pDX);
    
//{{AFX_DATA_MAP(CLLKDlg)
    DDX_Check(pDX, IDC_CHK_AUTO, m_bAutoElmit);
    DDX_Check(pDX, IDC_CHK_TOPMOST, m_bIsTopMost);
    
//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CLLKDlg, CDialog)
    
// {{AFX_MSG_MAP(CLLKDlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_BN_CLICKED(IDC_LOCK, OnLock)
    ON_BN_CLICKED(IDC_ENCODE, OnEncode)
    ON_BN_CLICKED(IDC_DELETE, OnDelete)
    ON_WM_TIMER()
    ON_BN_CLICKED(IDC_CHK_TOPMOST, OnChkTopmost)
    
// }}AFX_MSG_MAP
END_MESSAGE_MAP()

/////
//  CLLKDlg message handlers

BOOL CLLKDlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    
// Add "About..." menu item to system menu.

    
// IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0== IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX 
< 0xF000);

    CMenu
* pSysMenu = GetSystemMenu(FALSE);
    
if (pSysMenu != NULL)
    
{
        CString strAboutMenu;
        strAboutMenu.LoadString(IDS_ABOUTBOX);
        
if (!strAboutMenu.IsEmpty())
        
{
            pSysMenu
->AppendMenu(MF_SEPARATOR);
            pSysMenu
->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
        }

    }


    
// Set the icon for this dialog.  The framework does this automatically
    
//  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE);            // Set big icon
    SetIcon(m_hIcon, FALSE);        // Set small icon
    
    
// TODO: Add extra initialization here
    ////
    // 取得配置文件路径
    char szModulPath[_MAX_PATH] = {0};
    GetModuleFileName(NULL, szModulPath, _MAX_PATH);
    CString strPath 
= szModulPath;
    
int iPos = strPath.ReverseFind('/');
    m_strInitPath 
= strPath.Left(iPos+1);
    m_strInitPath 
+= "CONFIG.INI";
    
////

    CRect rcWnd;
    GetWindowRect(rcWnd);

    
int iPos_X = GetPrivateProfileInt("OPTION""POS_X"500, m_strInitPath);
    
int iPos_Y = GetPrivateProfileInt("OPTION""POS_Y"700, m_strInitPath);
    
    rcWnd.OffsetRect(iPos_X, iPos_Y);

    MoveWindow(rcWnd, FALSE);

    BOOL m_bIsTopMost 
= GetPrivateProfileInt("OPTION""TOPMOST"0, m_strInitPath);
    CheckDlgButton(IDC_CHK_TOPMOST, m_bIsTopMost);
    HWND hWnd 
= this->GetSafeHwnd();
    
    
if ( m_bIsTopMost )
        ::SetWindowPos(hWnd, HWND_TOPMOST, 
0000, SWP_NOMOVE|SWP_NOSIZE);
    
else
        ::SetWindowPos(hWnd, HWND_NOTOPMOST, 
0000, SWP_NOMOVE|SWP_NOSIZE);

    SetTimer(
1100, NULL);

    
return TRUE;  // return TRUE  unless you set the focus to a control
}


void  CLLKDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
    
if ((nID & 0xFFF0== IDM_ABOUTBOX)
    
{
        CAboutDlg dlgAbout;
        dlgAbout.DoModal();
    }

    
else
    
{
        CDialog::OnSysCommand(nID, lParam);
    }

}


//  If you add a minimize button to your dialog, you will need the code below
//   to draw the icon.  For MFC applications using the document/view model,
//   this is automatically done for you by the framework.

void  CLLKDlg::OnPaint() 
{
    
if (IsIconic())
    
{
        CPaintDC dc(
this); // device context for painting

        SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 
0);

        
// Center icon in client rectangle
        int cxIcon = GetSystemMetrics(SM_CXICON);
        
int cyIcon = GetSystemMetrics(SM_CYICON);
        CRect rect;
        GetClientRect(
&rect);
        
int x = (rect.Width() - cxIcon + 1/ 2;
        
int y = (rect.Height() - cyIcon + 1/ 2;

        
// Draw the icon
        dc.DrawIcon(x, y, m_hIcon);
    }

    
else
    
{
        CDialog::OnPaint();
    }

}


//  The system calls this to obtain the cursor to display while the user drags
//   the minimized window.
HCURSOR CLLKDlg::OnQueryDragIcon()
{
    
return (HCURSOR) m_hIcon;
}


void  CLLKDlg::OnLock() 
{
    
// TODO: Add your control notification handler code here
    if ( m_LLKer.LockWnd() ) 
    
{
        AfxMessageBox(
"锁定成功", MB_ICONINFORMATION);

        m_bStarted 
= TRUE;
        
return;
    }

    AfxMessageBox(
"未找到游戏窗口,请确认窗口名称是否正确", MB_ICONERROR);
}


void  CLLKDlg::OnEncode() 
{
    
// TODO: Add your control notification handler code here
    UINT nBlock = m_LLKer.Encode();
    
if ( nBlock > 0 )
    
{
        AfxMessageBox(
"解析成功!", MB_ICONINFORMATION);
    }

}


void  CLLKDlg::OnDelete() 
{
    
// TODO: Add your control notification handler code here
    UpdateData(TRUE);

    POINT ptCursor;
    
    
int iRes = ::GetCursorPos(&ptCursor);

    
if ( m_bAutoElmit )
    
{
        m_LLKer.EliminateAll();
        ::SetCursorPos(ptCursor.x, ptCursor.y);
    }

    
else
    
{
        
if ( m_LLKer.EliminateOnePair() )
            ::SetCursorPos(ptCursor.x, ptCursor.y);
    }

}


void  CLLKDlg::OnTimer(UINT nIDEvent) 
{
    
// TODO: Add your message handler code here and/or call default
    if ( !m_LLKer.CheckWnd() && m_bStarted )
    
{
        m_LLKer.Reset();
    }

    CDialog::OnTimer(nIDEvent);
}


void  CLLKDlg::OnChkTopmost() 
{
    
// TODO: Add your control notification handler code here
    UpdateData(TRUE);
    
    HWND hWnd 
= this->GetSafeHwnd();

    
if ( m_bIsTopMost )
        ::SetWindowPos(hWnd, HWND_TOPMOST, 
0000, SWP_NOMOVE|SWP_NOSIZE);
    
else
        ::SetWindowPos(hWnd, HWND_NOTOPMOST, 
0000, SWP_NOMOVE|SWP_NOSIZE);

    CString strBuf;
    strBuf.Format(
"%d", m_bIsTopMost);
    WritePrivateProfileString(
"OPTION""TOPMOST", strBuf, m_strInitPath);
}


BOOL CLLKDlg::DestroyWindow() 
{
    
// TODO: Add your specialized code here and/or call the base class

    CRect rcWnd;
    GetWindowRect(rcWnd);
    
    CString strBuf;

    strBuf.Format(
"%d", rcWnd.left);
    WritePrivateProfileString(
"OPTION""POS_X", strBuf, m_strInitPath);
    strBuf.Format(
"%d", rcWnd.top);
    WritePrivateProfileString(
"OPTION""POS_Y", strBuf, m_strInitPath);

    
return CDialog::DestroyWindow();
}

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
qq游戏连连看python是一种基于Python编程语言开发的连连看游戏连连看是一种益智类游戏,通过消除相同图案的方块来得分。通过使用Python编程语言,可以实现游戏的各种功能和操作。 首先,使用Python可以很方便地实现游戏的界面设计。可以利用Python的图形库,如Tkinter或Pygame来创建游戏界面,包括游戏窗口、图标等,可以自定义游戏的背景、方块样式等。 其次,Python具有强大的数据处理能力,对于游戏的逻辑处理非常有帮助。通过Python的数据结构和算法,可以实现图块的生成、消除、移动等操作。还可以实现游戏的计时器、得分系统、关卡设置等功能。 另外,Python还可以轻松实现游戏的音效和音乐。可以利用Python的音频库来添加背景音乐、消除方块的音效等,增强游戏的趣味性和可玩性。 最后,Python是一种易于学习和使用的编程语言,拥有庞大的开发者社区和丰富的资源。对于初学者来说,通过编写一个简单的连连看游戏,可以锻炼编程能力,并为进一步学习和开发其他游戏奠定基础。 总之,qq游戏连连看python是一款基于Python编程语言开发的连连看游戏,通过Python的图形库、数据处理能力和音频库等,可以实现丰富的游戏功能,为用户提供更好的游戏体验。同时,编写这样一个游戏对于初学者来说也是一种很好的学习和实践机会。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值