| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2494 人关注过本帖
标题:运行到一会就不行了
只看楼主 加入收藏
huangqiandgz
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2017-11-24
收藏
 问题点数:0 回复次数:0 
运行到一会就不行了
// WindowsProject1.cpp: 定义应用程序的入口点。
//

#define _USE_MATH_DEFINES
#include "stdafx.h"
#include "WindowsProject1.h"
#include "math.h"
#include <stdio.h>
#pragma  comment(lib,"Msimg32.lib")   
static int locationX=0;
static int initCreate=1;
POINT ball;
static int img[10][20];
static  int cancelNum = 0;
static int cancelImg[10][20];
static POINT Location[10][20];
RECT rect;

static int lunchColor;
BOOL launchBallInit = 1;
BOOL paintInit = 1;
//HBITMAP yellowBall, redBall, blueBall;
//HBITMAP bmp;
//HDC            hdc,    g_hdc = NULL, g_mdc = NULL, g_bufdc = NULL;

//HDC                g_hdc = NULL, g_mdc = NULL, g_bufdc = NULL;
#define MAX_LOADSTRING 100
#define M_PI 3.14159265358979323846
// 全局变量:
HINSTANCE hInst;                                // 当前实例
WCHAR szTitle[MAX_LOADSTRING];                  // 标题栏文本
WCHAR szWindowClass[MAX_LOADSTRING];            // 主窗口类名
static int launch = 0;
// 此代码模块中包含的函数的前向声明:
ATOM                MyRegisterClass(HINSTANCE hInstance);
BOOL                InitInstance(HINSTANCE, int);
LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
void init();
void paint(HWND hWnd, HDC hdc);
void launchBall(HWND hWnd, HDC hdc);
void paintText(HWND hWnd, HDC hdc);
void  collision(HWND hwnd);
void  collisionOther(HWND hwnd,int j,int i);
void cancelSame( int color, int j, int i);
void Game_CleanUp(HWND hwnd);
void cancelFor();
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPWSTR    lpCmdLine,
                     _In_ int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    // TODO: 在此放置代码。

    // 初始化全局字符串
    LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    LoadStringW(hInstance, IDC_WINDOWSPROJECT1, szWindowClass, MAX_LOADSTRING);
    MyRegisterClass(hInstance);

    // 执行应用程序初始化:
    if (!InitInstance (hInstance, nCmdShow))
    {
        return FALSE;
    }

    HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WINDOWSPROJECT1));

    MSG msg;

    // 主消息循环:
    while (GetMessage(&msg, nullptr, 0, 0))
    {
        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return (int) msg.wParam;
}



//
//  函数: MyRegisterClass()
//
//  目的: 注册窗口类。
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
    WNDCLASSEXW wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);

    wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = hInstance;
    wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WINDOWSPROJECT1));
    wcex.hCursor        = LoadCursor(nullptr, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName   = MAKEINTRESOURCEW(IDC_WINDOWSPROJECT1);
    wcex.lpszClassName  = szWindowClass;
    wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

    return RegisterClassExW(&wcex);
}

//
//   函数: InitInstance(HINSTANCE, int)
//
//   目的: 保存实例句柄并创建主窗口
//
//   注释:
//
//        在此函数中,我们在全局变量中保存实例句柄并
//        创建和显示主程序窗口。
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   hInst = hInstance; // 将实例句柄存储在全局变量中

   HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

//
//  函数: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  目的:    处理主窗口的消息。
//
//  WM_COMMAND  - 处理应用程序菜单
//  WM_PAINT    - 绘制主窗口
//  WM_DESTROY  - 发送退出消息并返回
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
   
   
    static double itan;

    TCHAR m1[30] = { 0 };
    TCHAR n1[10];
    //CString str;
    float itan2= 0.5;
    static POINT mouse;
    mouse.x = 0;
    mouse.y = 0;
    int speed =10;
    //TCHAR n[10];
    switch (message)
    {
    case WM_ERASEBKGND:
        // 由于默认情况下本消息中 lParam 传入的是 0,因此默认情况下不进行绘制,以避免闪烁;但如果传入的是 TRUE,那么表示是由以下在处理 WM_PAINT 消息的代码调用的,因此需要调用默认的绘制代码,也就是 break 到 switch 语句之外  
        if (!lParam)
            return TRUE;
        break;
    case WM_LBUTTONDOWN:
        GetClientRect(hWnd, &rect);
        GetCursorPos(&mouse);
        ScreenToClient(hWnd, &mouse);
        //itan2 = asin(0.5);
        itan = atan((double)(mouse.y - rect.bottom) / (mouse.x - rect.right / 2));// );)
        if (itan>0)
        {
            itan=itan - M_PI;
        }
        //itan = atan2(mouse.y - rect.bottom, mouse.x - rect.right / 2);
        TCHAR m2[40];
        //(mouse.y-rect.bottom, mouse.x-rect.right/2);
        //_stprintf(m2, _T("itan%lfrect.bottom%d,mouse%d mouse.y - rect.bottom=%d  mouse.x - rect.right / 2=%d"), itan, rect.bottom,mouse.y , mouse.y - rect.bottom, mouse.x - rect.right / 2);

        //MessageBox(hWnd, m2, L"22", NULL);
        

        launch = 1;
        
        break;
    case WM_SIZE:
        GetClientRect(hWnd, &rect);
   
        //TCHAR n[10];
        //
        //    //
        locationX =( rect.right  - 525 )/ 2;
        //wsprintf(n, L"%d", locationX);
        //MessageBox(NULL, n, NULL, NULL);
        InvalidateRect(hWnd, NULL, TRUE);
        //init();
        ball.x = rect.right / 2;
        ball.y = rect.bottom;
        break;
    case WM_CREATE:
        SetTimer(hWnd, 1, 100, NULL);
        SetTimer(hWnd,2, 100, NULL);
        GetClientRect(hWnd, &rect);
   
    //
        //bmp2 = CreateCompatibleBitmap(hdc, rect.right - rect.left, rect.bottom - rect.top);
        locationX = (rect.right - 525) / 2;
        init();
    /*    wsprintf(n, L"%d", locationX);
        MessageBox(NULL, n, NULL, NULL);*/
        ball.x = rect.right / 2;
        ball.y = rect.bottom;
        break;
    case  WM_TIMER:
        switch (wParam)
        {
        case 1:
            collision(hWnd);
            if (launch == 1) {
                ball.x = ball.x + speed*cos(itan);
                ball.y = ball.y+ speed*sin(itan);
                //_stprintf(n1,L"sin%lf",sin(30));
                //MessageBox(NULL, n1, L"n1", NULL);
            }
            if( (ball.x-25<= locationX)||(ball.x+25>= rect.right- locationX))
            {
                itan = -(itan - M_PI);
            }
            //TCHAR n[10];
            //wsprintf(n, L"x=%d", speed*cos(itan));
            //MessageBox(hWnd, n, NULL, NULL);
            //_stprintf(m1, _T("%.3f,cos%f"), speed*sin(itan), speed*cos(itan));
            
        //MessageBox(hWnd, m1, L"cos",NULL);
        InvalidateRect(hWnd, NULL, TRUE);
            //UpdateWindow(hWnd);
            break;
        case 2:

        default:
            break;
        }
    case WM_COMMAND:
        {
            int wmId = LOWORD(wParam);
            // 分析菜单选择:
            switch (wmId)
            {
            case IDM_ABOUT:
                DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
                break;
            case IDM_EXIT:
                DestroyWindow(hWnd);
                break;
            default:
                return DefWindowProc(hWnd, message, wParam, lParam);
            }
        }
        break;
    case WM_PAINT:
        {

            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hWnd, &ps);
            OutputDebugString(_T("输出调试信息"));

        //    HDC g_mdc = CreateCompatibleDC(hdc);
            //launchBall(hWnd, hdc);
        
            paint(hWnd, hdc);
            TCHAR m[20];
            //wsprintf(m, L"%dmouse%d", itan2, mouse.x);(
            //TextOut(hdc, 0, 0, n1,30);
            // TODO: 在此处添加使用 hdc 的任何绘图代码...
            
            EndPaint(hWnd, &ps);
        }
        break;
    case WM_DESTROY:
        Game_CleanUp(hWnd);
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

// “关于”框的消息处理程序。
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    UNREFERENCED_PARAMETER(lParam);
    switch (message)
    {
    case WM_INITDIALOG:
        return (INT_PTR)TRUE;

    case WM_COMMAND:
        if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
        {
            EndDialog(hDlg, LOWORD(wParam));
            return (INT_PTR)TRUE;
        }
        break;
    }
    return (INT_PTR)FALSE;
}
void init() {
    for (int i=0;i<10;i++)
    {
        for (size_t j = 0; j < 20; j++)
        {
            img[i][j] = 0;
        }
    }

    for (int i = 0; i < 10; i++)
    {
        for (size_t j = 0; j < 20; j++)
        {if (j<8)
        {
            int k = 1 + rand() % 3;
            img[i][j] = k;
        }
            
            if (j%2==0)
            {
                Location[i][j].x = locationX+25+ i * 50;
            }
            else {
                Location[i][j].x = locationX+ 50+i * 50;
            }
            Location[i][j].y =25+j *40;

        }
    }
}
void paintText(HWND hWnd, HDC hdc) {
    POINT mo;
    TCHAR m3[30];
    GetCursorPos(&mo);
    ScreenToClient(hWnd,&mo);
    _stprintf(m3, _T("mouse.y %dmouse.x =%d") ,mo.y, mo.x);
    TextOut(hdc, rect.right / 2, 0, m3, 30);
}
void paint(HWND hWnd, HDC hdc) {
   
        //g_hdc = GetDC(hWnd);
        GetClientRect(hWnd, &rect);
        HDC        g_mdc = CreateCompatibleDC(hdc);
        HDC        g_bufdc = CreateCompatibleDC(hdc);
        
   
        HBITMAP bmp = CreateCompatibleBitmap(hdc, rect.right , rect.bottom);
    SelectObject(g_mdc, bmp);
    //HBITMAP g_hBackGround = (HBITMAP)LoadImage(NULL, L"bg.bmp", IMAGE_BITMAP, rect.right, rect.bottom, LR_LOADFROMFILE);
    //将空位图对象放到g_mdc中
   
    //SelectObject(g_bufdc, g_hBackGround);
    BitBlt(g_mdc, 0, 0, rect.right - rect.left, rect.bottom - rect.top, g_bufdc, 0, 0, SRCCOPY);
    FillRect(g_mdc, &rect, (HBRUSH)(GetClassLong(hWnd, GCL_HBRBACKGROUND) - 1));
//HBRUSH hBrush = CreateSolidBrush(RGB(255, 255, 255));
    //FillRect(hdc, &rect, hBrush);
    HBRUSH hBrush = CreateSolidBrush(RGB(0, 0, 0));
    RECT rect1,rect2;
    rect1.left = 0;
    rect1.top = 0;
    rect1.right = locationX;
    rect1.bottom = rect.bottom;
    FillRect(g_mdc, &rect1, hBrush);
    rect2.left =rect.right- locationX;
    rect2.top = 0;
    rect2.right =  rect.right;
    rect2.bottom = rect.bottom;
    FillRect(g_mdc, &rect2, hBrush);
    for (int i = 0; i < 10; i++)
    {
        for (size_t j = 0; j < 20; j++)
        {
            TCHAR n[5];
            wsprintf(n, L"%d", img[i][j]);
            TextOut(hdc, i * 20,300+ j * 20, n, 3);

        }
    }
    HBITMAP yellowBall, blueBall, redBall;
    for (int i = 0; i < 10; i++)
    {
        for (size_t j = 0; j < 20; j++)
        {
            switch (img[i][j])
            {
            case 1:
                //MessageBox(hWnd, L"yell", NULL, NULL);
                yellowBall = (HBITMAP)LoadImage(NULL, L"yellow.bmp", IMAGE_BITMAP, 66, 69, LR_LOADFROMFILE);
                SelectObject(g_bufdc, yellowBall);
                    break;
            case 2:
                    blueBall = (HBITMAP)LoadImage(NULL, L"blue.bmp", IMAGE_BITMAP, 66, 69, LR_LOADFROMFILE);
                    SelectObject(g_bufdc, blueBall);
                //TransparentBlt(hdc, 25, 25, 50, 50, gHdc, 0, 0, 66, 69, RGB(255, 255, 255));
                break;
            case 3:
                 redBall = (HBITMAP)LoadImage(NULL, L"red.bmp", IMAGE_BITMAP, 66, 69, LR_LOADFROMFILE);
                SelectObject(g_bufdc, redBall);
            //    TransparentBlt(hdc, Location[i][j].x - 25, Location[i][j].y - 25, 50, 50, gHdc, 0, 0, 66, 69, RGB(255, 255, 255));
                break;
            default:
                break;
            }
            if(img[i][j]!=0)
            TransparentBlt(g_mdc, Location[i][j].x - 25, Location[i][j].y - 25, 50, 50, g_bufdc, 0, 0, 66, 69, RGB(255, 255, 255));

        }
    }
    //BitBlt(hdc, 0, 0, rect.right, rect.bottom, g_mdc2, 0, 0, SRCCOPY);
    //BitBlt(hdc, 0, 0, rect.right - rect.left, rect.bottom - rect.top, gHdc, 0, 0, SRCCOPY);   // 复制到屏幕并清理内存图像
    //launchBall(hWnd, hdc);
    //DeleteObject(bmp);
    //DeleteDC(gHdc);
   
    //HDC gHdc = CreateCompatibleDC(NULL);
    GetClientRect(hWnd, &rect);
//g_mdc = CreateCompatibleDC(hdc);  //创建一个和hdc兼容的内存DC
//g_bufdc = CreateCompatibleDC(hdc);

//HBITMAP    bmp = CreateCompatibleBitmap(hdc, rect.right - rect.left, rect.bottom - rect.top);
//   
//SelectObject(g_mdc, bmp);
   
    //paint(hWnd, hdc);
   
    //g_mdc = CreateCompatibleDC(hdc);
    //PatBlt(ghdc, 0, 0, rect.right, rect.bottom, WHITENESS);
   
    //SelectObject(gHdc, bmp);
    //SendMessage(hWnd, WM_ERASEBKGND, (WPARAM)(gHdc), TRUE);  // 发送 WM_ERASEBKGND 消息并传入 lParam 为 TRUE,wParam 为缓冲的 DC,要求默认处理程序将背景擦除过程应用到 dcBuffer 上,详细内容参见 MSDN 中关于 WM_ERASEBKGND 消息的说明  
    //SendMessage(hWnd, WM_PRINT, (WPARAM)(gHdc), PRF_CLIENT | PRF_NONCLIENT);  // 发送 WM_PRINT,要求控件将当前状态绘制到 dcBuffer,详细内容参见 MSDN 中关于 WM_PRINT 和 WM_PRINTCLIENT 消息的说明  
    //
    //   
   
    HBITMAP ballimg1, ballimg2, ballimg3;
   
    //FillRect(hdc, &rect, (HBRUSH)(GetClassLong(hWnd, GCL_HBRBACKGROUND) - 1));

    if (launchBallInit == 1)
    {

        lunchColor = 1 + rand() % 3;
        launchBallInit = 0;
    }
        switch (lunchColor)
        {
        case 1:
            ballimg1 = (HBITMAP)LoadImage(NULL, L"yellow.bmp", IMAGE_BITMAP, 66, 69, LR_LOADFROMFILE);
            SelectObject(g_bufdc, ballimg1);
            break;
        case 2:
            ballimg2 = (HBITMAP)LoadImage(NULL, L"blue.bmp", IMAGE_BITMAP, 66, 69, LR_LOADFROMFILE);
            SelectObject(g_bufdc, ballimg2);
            break;
        case 3:
            ballimg3 = (HBITMAP)LoadImage(NULL, L"red.bmp", IMAGE_BITMAP, 66, 69, LR_LOADFROMFILE);
            SelectObject(g_bufdc, ballimg3);
            break;
        default:
            break;
        }
        
   
   
    TransparentBlt(g_mdc, ball.x - 25, ball.y - 25, 50, 50, g_bufdc, 0, 0, 66, 69, RGB(255, 255, 255));
    //BitBlt(hdc, 0, 0, rect.right - rect.left, rect.bottom - rect.top, gHdc, 0, 0, SRCCOPY);
    //ReleaseDC(hWnd, hdc);
    BitBlt(hdc, 0, 0, rect.right, rect.bottom, g_mdc, 0, 0, SRCCOPY);
    //ReleaseDC(hWnd, hdc);
    //SelectObject(gHdc, hOld);
   
    //DeleteDC(gHdc);
    ReleaseDC(hWnd, hdc);
    DeleteDC(g_mdc);
    DeleteDC(g_bufdc);
    DeleteObject(bmp);
    DeleteObject(ballimg1);
    DeleteObject(ballimg2);
    DeleteObject(ballimg3);
    DeleteObject(yellowBall);
    DeleteObject(blueBall);
    DeleteObject(redBall);
   
   
}
void  collision(HWND hwnd) {
    for (int i2=0;i2<10;i2++)
    {
        for (size_t j = 0; j < 20; j++)
        {if (img[i2][j]!=0)
        {
            if (50 >sqrt((Location[i2][j].x - ball.x)*(Location[i2][j].x - ball.x) + (Location[i2][j].y - ball.y)*(Location[i2][j].y - ball.y))) {
                //MessageBox(NULL, L"jj", NULL, NULL);
                collisionOther(hwnd, i2, j);
            }

        }
        
            
        }
    }
}
void collisionOther(HWND hwnd, int j, int i) {
    int n, m;
    GetClientRect(hwnd, &rect);
    int p[6] = {0,0,0,0,0,0};
    int k = 0, l = 999;
    if (i%2==0)
    {
        if((j - 1>=0)&&(img[j - 1][i]==0))
        p[0] = (Location[j-1][i].x - ball.x)*(Location[j-1][i].x - ball.x) + (Location[j-1][i].y - ball.y)*(Location[j-1][i].y - ball.y);
        if ((j + 1<= 10) && (img[j +1][i] == 0))
        p[1] = (Location[j +1][i].x - ball.x)*(Location[j + 1][i].x - ball.x) + (Location[j+ 1][i].y - ball.y)*(Location[j +1][i].y - ball.y);
        if ((i - 1 >= 0) && (img[j][i-1] == 0))
        p[2] = (Location[j][i-1].x - ball.x)*(Location[j ][i - 1].x - ball.x) + (Location[j ][i - 1].y - ball.y)*(Location[j ][i - 1].y - ball.y);
        if ((j - 1 >= 0) && (i - 1 >= 0)&&(img[j-1][i - 1] == 0))
        p[3] = (Location[j - 1][i-1 ].x - ball.x)*(Location[j - 1][i-1 ].x - ball.x) + (Location[j - 1][i-1 ].y - ball.y)*(Location[j - 1][i-1 ].y - ball.y);
        if ((j - 1 >= 0) && (i + 1 <=10) && (img[j - 1][i + 1] == 0))
            p[4] = (Location[j - 1][i +1].x - ball.x)*(Location[j - 1][i + 1].x - ball.x) + (Location[j - 1][i + 1].y - ball.y)*(Location[j - 1][i + 1].y - ball.y);
        if ((i + 1 <= 10) && (img[j][i + 1] == 0))
            p[5] = (Location[j ][i + 1].x - ball.x)*(Location[j ][i + 1].x - ball.x) + (Location[j ][i + 1].y - ball.y)*(Location[j][i + 1].y - ball.y);

    }
    else
    {
        if ((j - 1 >= 0) && (img[j-1][i ] == 0))
            p[0] = (Location[j - 1][i].x - ball.x)*(Location[j - 1][i].x - ball.x) + (Location[j - 1][i].y - ball.y)*(Location[j - 1][i].y - ball.y);
        if ((j + 1 <= 10) && (img[j + 1][i] == 0))
            p[1] = (Location[j + 1][i].x - ball.x)*(Location[j + 1][i].x - ball.x) + (Location[j + 1][i].y - ball.y)*(Location[j + 1][i].y - ball.y);
        if ((i - 1 >= 0) && (img[j][i-1] == 0))
            p[2] = (Location[j][i - 1].x - ball.x)*(Location[j][i - 1].x - ball.x) + (Location[j][i - 1].y - ball.y)*(Location[j][i - 1].y - ball.y);
        if ((j +1 <=10) && (i - 1 >= 0) && (img[j+1][i - 1] == 0))
            p[3] = (Location[j+1][i - 1].x - ball.x)*(Location[j + 1][i - 1].x - ball.x) + (Location[j + 1][i - 1].y - ball.y)*(Location[j + 1][i - 1].y - ball.y);
        if ((j + 1 <= 10) && (i + 1 <= 10) && (img[j + 1][i + 1] == 0))
            p[4] = (Location[j + 1][i + 1].x - ball.x)*(Location[j + 1][i + 1].x - ball.x) + (Location[j + 1][i + 1].y - ball.y)*(Location[j + 1][i + 1].y - ball.y);
        if ((i + 1 <= 10) && (img[j ][i + 1] == 0))
            p[5] = (Location[j][i + 1].x - ball.x)*(Location[j][i + 1].x - ball.x) + (Location[j][i + 1].y - ball.y)*(Location[j][i + 1].y - ball.y);

    }
    for (size_t i2 = 0; i2 < 6; i2++)
    {if ((p[i2]!=0)&&(l>p[i2]))
    {
        l = p[i2];
        k = i2;
    }
        
    }
    if (i % 2 == 0) {
        switch (k)
        {
        case 0:
            img[j - 1][i] = lunchColor;
            n = j - 1, m = i;
            break;
        case 1:
            img[j + 1][i]= lunchColor;
            n = j +1, m = i;
            break;
        case 2:
            img[j][i - 1]=lunchColor;
            n = j , m = i-1;
            break;
        case 3:
            img[j - 1][i - 1] = lunchColor;
            n = j -1, m = i-1;
            break;
        case 4:
            img[j - 1][i + 1] = lunchColor;
            n = j - 1, m = i+1;
            break;
        case 5:
            img[j][i + 1] = lunchColor;
            n = j , m = i + 1;
            break;
        default:
            break;
        }
    }
    else
    {
        switch (k)
        {
        case 0:
            img[j - 1][i] = lunchColor;
            n = j - 1, m = i ;
            break;
        case 1:
            img[j + 1][i] = lunchColor;
            n = j + 1, m = i ;
        case 2:
            img[j][i - 1] = lunchColor;
            n = j , m = i - 1;
            break;
        case 3:
            img[j + 1][i - 1] = lunchColor;
            n = j + 1, m = i - 1;
            break;
        case 4:
            img[j + 1][i + 1] = lunchColor;
            n = j + 1, m = i + 1;
            break;
        case 5:
            img[j][i + 1] = lunchColor;
            n = j , m = i + 1;
            break;
        }
    }
    cancelSame( lunchColor, n, m);
    if (cancelNum >=3) {
        cancelFor();
        cancelNum = 0;
    }
    else {
        cancelNum = 0;
    }
    launch = 0;
    ball.x = rect.right / 2;
    ball.y = rect.bottom;
}
void cancelSame( int color, int j, int i) {
    if (cancelImg[j][i]==0) {
        cancelNum++;
    }
    cancelImg[j][i] = 1;
    if(i%2==0){
        if ((img[j - 1][i] == color)&&(cancelImg[j - 1][i] != 1)&&(j-1>=0)) {
            cancelSame(color, j - 1, i);
        }
    if ((img[j + 1][i]==color) && (cancelImg[j+ 1][i] != 1)&&(j+1<=10))
    {
        cancelSame(color, j + 1, i);
    }
    if ((img[j][i - 1]==color) && (cancelImg[j][i-1] != 1) && (i - 1 >= 0))
    {
        cancelSame(color, j, i-1);
    }
    if ((img[j - 1][i - 1]==color) && (cancelImg[j - 1][i-1] != 1) && (j - 1 >= 0) && (i - 1 >= 0))
    {
        cancelSame(color, j-1, i - 1);
    }
    if ((img[j][i +1] == color) && (cancelImg[j ][i+1] != 1))
    {
        cancelSame(color, j, i + 1);
    }
    if ((img[j - 1][i + 1] == color) && (cancelImg[j - 1][i+1] != 1) && (j - 1 >= 0))
    {
        cancelSame(color, j - 1, i + 1);
    }
    }
    else {
        if ((img[j + 1][i] == color) && (cancelImg[j +1][i] != 1) && (j + 1 <= 10))
        {
            cancelSame(color, j + 1, i);
        }
        if ((img[j-1][i ] == color) && (cancelImg[j-1 ][i] != 1) && (j - 1 >= 0))
        {
            cancelSame(color, j-1, i );
        }
        if ((img[j][i - 1] == color) && (cancelImg[j][i - 1] != 1) && (i - 1 >= 0))
        {
            cancelSame(color, j, i - 1);
        }
        if ((img[j+1][i - 1] == color) && (cancelImg[j+1][i - 1] != 1) && (j + 1 <= 10) && (i - 1 >= 0))
        {
            cancelSame(color, j +1, i - 1);
        }
        if ((img[j][i +1] == color) && (cancelImg[j][i+1] != 1))
        {
            cancelSame(color, j, i +1);
        }
        if ((img[j + 1][i +1] == color) && (cancelImg[j+1][i+1] != 1) && (j + 1 <= 10))
        {
            cancelSame(color, j + 1, i +1);
        }

    }

}
void cancelFor() {
    for (size_t i = 0; i < 20; i++)
    {
        for (size_t j = 0; j < 10; j++)
        {
            if (cancelImg[j][i] == 1) {
                img[j][i] = 0;
                cancelImg[j][i] = 0;
            }
        }
    }
}
void Game_CleanUp(HWND hwnd) {
   

}
搜索更多相关主题的帖子: img int Location NULL HWND 
2017-12-04 11:06
快速回复:运行到一会就不行了
数据加载中...
 
   



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

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