Skip to content →

Collage

Collage is a little game that let users to rearrange pictures according to the given order. The main logic is as follows:

void canvasFrame::OnLButtonDown(UINT nFlags, CPoint point) 
{
    CClientDC dc(this);
    xx = yy = -1;

    //判断鼠标点击的位置
    if(point.x > 0 && point.x < 100)
    {

if(point.y > 0 && point.y < 100)
        {
            xx = 0;
            yy = 0;
        }
        if(point.y > 100 && point.y < 200)
        {
            xx = 1;
            yy = 0;
        }
        if(point.y > 200 && point.y < 300)
        {
            xx = 2;
            yy = 0;
        }
    }
    if(point.x > 100 && point.x < 200)
    {
        if(point.y >
0 && point.y < 100)
        {
            xx = 0;
            yy = 1;
        }
        if(point.y > 100 && point.y < 200)
        {
            xx = 1;
            yy = 1;
        }
        if(point.y > 200 && point.y < 300)
        {
            xx = 2;
            yy = 1;
        }
    }
    if(point.x > 200 && point.x < 300)
    {
        if(point.y > 0 && point.y <
100)
        {
            xx = 0;
            yy = 2;
        }
        if(point.y > 100 && point.y < 200)
        {
            xx = 1;
            yy = 2;
        }
        if(point.y > 200 && point.y < 300)
        {
            xx = 2;
            yy = 2;
        }
    }

    int xxx, yyy;
    if(xx != -1 && yy != -1)
    {
        for(int i = 0; i < 3; ++i)
        {

for(int j = 0; j < 3; ++j)
            {
                if(cur[i][j] == 9)
                {
                    xxx = i;
                    yyy = j;
                }
            }
        }
    }

    if(abs(xxx - xx) + abs(yyy - yy) == 1)
    {
        //dc.TextOut(400, 400 ,"hello!");
        //int t = cur[xxx][yyy];
        cur[xxx][yyy] = cur[xx][yy];
        cur[xx][yy] = 9;

    //交换图片位置
        mdc->SelectObject(b);
        dc.BitBlt(a[xx * 3 + yy].x, a[xx * 3 + yy].y, 100, 100, mdc, 0, 0, SRCCOPY);

        switch(cur[xxx][yyy])
        {
            case 1: mdc->SelectObject(p1);break;
            case 2: mdc->SelectObject(p2);break;
            case 3: mdc->SelectObject(p3);break;
            case 4: mdc->SelectObject(p4);break;
            case 5: mdc->SelectObject(p5);break;

    case 6: mdc->SelectObject(p6);break;
            case 7: mdc->SelectObject(p7);break;
            case 8: mdc->SelectObject(p8);break;
        }
        dc.BitBlt(a[xxx * 3 + yyy].x, a[xxx * 3 + yyy].y, 100, 100, mdc, 0, 0, SRCCOPY);

        int f = 0;
        for(int i = 0; i < 3; ++i)
        {
            int flag = 0;
            for(int j = 0; j < 3; ++j)
            {
                if(cur[i][j] != 3 * i + j + 1)

    {
                    flag = 1;
                    break;
                }
            }
            if(flag == 1)
            {
                f = 1;
                break;
            }
        }
        if(f == 0)
        {
            strcpy(result,"恭喜你,你赢了!");
            dc.TextOut(100 , 350 ,result);
        }
    }
    CFrameWnd::OnLButtonDown(nFlags,
    point);
}

 

Published in Collage

Comments

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.