| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 524 人关注过本帖
标题:腾迅彩色方块游戏的辅助程序,
只看楼主 加入收藏
袁德凯
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2011-4-8
结帖率:57.14%
收藏
 问题点数:0 回复次数:0 
腾迅彩色方块游戏的辅助程序,
/*我写的这个程序在14寸笔记本上运行通过了测试。其中分辨率要设成1366*768.不过我的程序由于算法不够好,所以得分不够多。希望有人可以改进算法。使得分达到200分。
下面是我的程序。*/
// CSFK.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <windows.h>
#include<Wingdi.h>
#include <Winuser.h>
#include <process.h>
#include <math.h>
#include "time.h"
#include "stdio.h"
#include<Winbase.h>
#include "stdlib.h"
#include<iostream>
using namespace std;

CRITICAL_SECTION cs;
int advice;
bool next;
int cxScreen=1366;
int l,r,u,d;
int i,j;
HDC   hdc1,hdc2,hdc3,hdc4,hdc ;
const int L=55+cxScreen/4,R=605+cxScreen/4,U=610,D=260;//游戏的边界

typedef struct QQFK
{
    int up,down;
} fk;



fk xx[15],yy[23];

int Getsc(HDC ,int ,int );//获取点的转制色彩值
bool IsSame(int ,int,int & );//对比两点是否相同
bool IsSame(int ,int ,int,int & );//对比三点是否相同
bool IsSame(int ,int ,int,double );//对比三点是否完全相同
bool IsSame(int ,int ,int ,int,int &);//对比四点是否相同
void DJ(int ,int );//点击指定点
void Lmove();//左移寻找非空白点
void Rmove();//右移寻找非空白点
void Umove();//上移寻找非空白点
void Dmove();//下移寻找非空白点


void main()
{

    InitializeCriticalSection(&cs);

    cout <<"请输入你想要得到的分数"<<endl;
    int mark;
    cin>>mark;
    time_t t_start,t_end;   
    HANDLE hThread1,hThread2,hThread3,hThread4;
    DWORD ThreadID1,ThreadID2,ThreadID3,ThreadID4;



    for(int it=0;it<15;it++)
    {
        xx[it].up =xx[it].down =L;
        yy[it].up =yy[it].down =D;
    }
    for(int it=15;it<23;it++)
    {
        yy[it].up =yy[it].down =D;
    }

    HWND hwnd ,hwnd2;
    hwnd=FindWindow(NULL,NULL);
    hwnd2=GetConsoleWindow();

    hdc1 = GetDC(NULL);
    hdc2 = GetDC(NULL);
    hdc3 = GetDC(NULL);
    hdc4 = GetDC(NULL);
    hdc = GetDC(NULL);

    if (hwnd2==NULL)
        cout<<"控制台句柄猎取失败"<<endl;

    ShowWindow(hwnd2,SW_HIDE);

    if (hdc==NULL)
        cout<<"全屏句柄猎取失败"<<endl;
    cout<<endl;
    bool continu=1;
    int marked=0;
    Sleep(3000);

    t_start = time(NULL) ;
    int ll,rr,uu,dd;//结构体的四个域

    while(marked<mark && continu)   
    {
        for ( i=L;i<=R;i=i+25)//.....................................
        {

            for( j=D;j<=U;j=j+25) //610         //.............hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
            {

                if(Getsc(hdc,i,j)==988||Getsc(hdc,i,j)==948)//kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
                {
                    EnterCriticalSection(&cs);
                    advice=0;
                    next=1;
                    LeaveCriticalSection(&cs);

                    dd=yy[(i-L)/25].down;//列
                    uu=yy[(i-L)/25].up ;//列
                    ll=xx[(j-D)/25].down;//行
                    rr=xx[(j-D)/25].up ;//行

                    if (ll<=i && i<=rr)
                    {

                        hThread2=CreateThread(NULL, 0,(LPTHREAD_START_ROUTINE)Rmove, NULL,0,  &ThreadID2);
                        hThread1=CreateThread(NULL, 0,(LPTHREAD_START_ROUTINE)Lmove, NULL,0,  &ThreadID1);
                        CloseHandle(hThread1);
                        CloseHandle(hThread2);

                    }
                    else
                    {
                        xx[(j-D)/25].down=i;
                        xx[(j-D)/25].up=i;

                        hThread2=CreateThread(NULL, 0,(LPTHREAD_START_ROUTINE)Rmove, NULL,0,  &ThreadID2);
                        hThread1=CreateThread(NULL, 0,(LPTHREAD_START_ROUTINE)Lmove, NULL,0,  &ThreadID1);
                        CloseHandle(hThread1);
                        CloseHandle(hThread2);

                    }

                    if(dd<=j && j<=uu)
                    {
                        hThread3=CreateThread(NULL, 0,(LPTHREAD_START_ROUTINE)Umove, NULL,0,  &ThreadID3);
                        hThread4=CreateThread(NULL, 0,(LPTHREAD_START_ROUTINE)Dmove, NULL,0,  &ThreadID4);
                        CloseHandle(hThread3);
                        CloseHandle(hThread4);
                    }
                    else
                    {
                        yy[(i-L)/25].down=j;
                        yy[(i-L)/25].up=j;
                        hThread3=CreateThread(NULL, 0,(LPTHREAD_START_ROUTINE)Umove, NULL,0,  &ThreadID3);
                        hThread4=CreateThread(NULL, 0,(LPTHREAD_START_ROUTINE)Dmove, NULL,0,  &ThreadID4);
                        CloseHandle(hThread3);
                        CloseHandle(hThread4);
                    }
                    while (next)
                    {
                        Sleep(50);
                    }
                    //cout<<"结束等待"<<endl;

                    if(IsSame(l,r,u,d,marked))
                    {
                        DJ(i,j);
                        Sleep(400);
                        t_end = time(NULL) ;
                        //cout<<"当前时间为:"<<difftime(t_end,t_start)<<endl;
                        cout<<endl;
                        j-=25;

                    }



                }  //kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
                if(marked>=mark)
                    break;
                t_end = time(NULL) ;
                if(difftime(t_end,t_start)>115)
                    break;

            }   //hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
            if(marked>=mark)
            {
                continu=0;
                break;
            }
            t_end = time(NULL) ;
            if(difftime(t_end,t_start)>115)
            {
                continu=0;
                break;
            }

        }

    }
    ReleaseDC(NULL,hdc );
    cout<<"得分:"<<marked<<endl;
    t_end = time(NULL) ;
    cout<<"本次用时为:"<<difftime(t_end,t_start)<<endl;

    ShowWindow(hwnd2,SW_SHOW);
    system("pause");


}



int Getsc(HDC hdc,int it,int jt)//获取点的转制色彩值
{
    int r=GetRValue((DWORD)GetPixel(hdc,it,jt));
    int b=GetBValue((DWORD)GetPixel(hdc,it,jt));
    return r+3*b;
}

bool IsSame(int a,int b,int c,int &d)//对比三点是否相同
{

    if ( a==b ||a==c ||b==c )
    {
        return true ;
    }
    else
        return false ;
}


bool IsSame(int a,int b,int c,int d,int &e)//对比四点是否相同
{
    int ss;
    if ( !IsSame(a,b,c,ss) && a!=d && b!=d && c!=d)
        return false ;
    else
    {
        e=e+2;
        return true ;
    }
}

void DJ(int it ,int jt)//点击指定点
{
    cout<<"点击"<<it<<"  "<<jt<<endl;
    SetCursorPos( it ,jt );
    mouse_event(MOUSEEVENTF_LEFTUP,0,0 ,0,0);
    mouse_event(MOUSEEVENTF_LEFTDOWN,0,0 ,0,0);   
}


void Lmove( )    //左移寻找非空白点
{
    int ql, Q;
    Q=ql=xx[(j-D)/25].down;

    while ( ( Getsc( hdc1 ,ql ,j )==988 || Getsc( hdc1 ,ql ,j)==948 )&& ql>=L )
    {
        ql-=25;
    }
    xx[(j-D)/25].down=ql;

    if(ql<L)
        l=10;
    else
        l= Getsc( hdc1 ,ql ,j );

    EnterCriticalSection(&cs);
    if(advice==3)
    {
        next=0;
    }
    else
    {
        advice++;
    }
    LeaveCriticalSection(&cs);
}


void Rmove()    //右移寻找非空白点
{
    int qr,  Q;
    Q=qr=xx[(j-D)/25].up;

    while ( ( Getsc(hdc2,qr,j)==988 || Getsc(hdc2,qr,j)==948) && qr<=R )
    {
        qr+=25;
    }

    if(qr>R)
        r= 20;
    else
        r=Getsc( hdc2 ,qr,j );

    xx[(j-D)/25].up=qr;

    EnterCriticalSection(&cs);
    if(advice==3)
    {
        next=0;
    }
    else
    {
        advice++;
    }
    LeaveCriticalSection(&cs);
}

void Umove()    //上移寻找非空白点
{
    int qu=yy[(i-L)/25].down;
    int Q=qu;

    while ( ( Getsc(hdc3,i,qu)==988 ||Getsc(hdc3,i,qu)==948 ) && qu>=D )
    {
        qu-=25;
    }

    if (qu<D)
        u=30;

    else
        u=Getsc(hdc3,i,qu);
    yy[(i-L)/25].down=qu;

    EnterCriticalSection(&cs);
    if(advice==3)
    {
        next=0;
    }
    else
    {
        advice++;
    }
    LeaveCriticalSection(&cs);
}

void Dmove()    //下移寻找非空白点
{
    int qd=yy[(i-L)/25].up;
    int Q=qd;

    while ( ( Getsc( hdc4,i,qd)==988 || Getsc( hdc4 , i ,qd )==948) && qd<=U )
    {
        qd+=25;
    }
    if (qd>U)
        d= 40;
    else
        d=Getsc( hdc4 ,i,qd);
    yy[(i-L)/25].up=qd;
    EnterCriticalSection(&cs);
    if(advice==3)
    {
        next=0;
    }
    else
    {
        advice++;
    }
    LeaveCriticalSection(&cs);
}





搜索更多相关主题的帖子: 应用程序 include advice 分辨率 
2011-09-12 18:40
快速回复:腾迅彩色方块游戏的辅助程序,
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024001 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved