签到

05月11日
尚未签到

共有回帖数 0

    岁月流逝

    等级:
    本来7个灯是全关的(可以开关),
    围成一个7边形。。
    用鼠标点际一灯,
    那么这灯和这盏灯顺逆时针数到3的一共3个灯都会改边等态,
    (即本来是开的就关本来是关的就开)
    要求让所有灯都开了。

    #includeafxwin.h
    class CMainWnd:public CFrameWnd{
    public:
       CMainWnd(){
           for(int i=0;i7;i++)bTrue=false;
           CRect rMWnd(100,100,520,520);
           Create(NULL,TEXT("七灯游戏"),
                  WS_OVERLAPPEDWINDOW,rMWnd,NULL,NULL,NULL);
       }
       void OnTimer(UINT nIDEvent);
       void OnPaint();
       void OnLButtonUp(UINT,CPoint);
    protected:
       void Set(UINT);
       bool OK();
       bool bTrue[7];
    DECLARE_MESSAGE_MAP();
    };
    BEGIN_MESSAGE_MAP(CMainWnd,CFrameWnd)
        ON_WM_PAINT()
        ON_WM_LBUTTONUP()
    END_MESSAGE_MAP()
    class CWinMain:public CWinApp{
    public:
       virtual BOOL InitInstance(){
           m_pMainWnd=new CMainWnd;
           m_pMainWnd-ShowWindow(SW_SHOW);
           m_pMainWnd-UpdateWindow();
           return TRUE;
       }
    }theMain;
    void CMainWnd::OnPaint(){
       CDC *pDC=this-GetDC();
       CBrush brBrush[7];
       for(int i=0;i7;i++){
           if(bTrue)brBrush.CreateSolidBrush(RGB(255,0,0));
               else brBrush.CreateSolidBrush(RGB(255,255,255));
           pDC-SelectObject(brBrush+i);
           if(i==0)pDC-Ellipse(80,0,160,80);
           if(i==1)pDC-Ellipse(240,0,320,80);
           if(i==2)pDC-Ellipse(320,80,400,160);
           if(i==3)pDC-Ellipse(280,200,360,280);
           if(i==4)pDC-Ellipse(160,260,240,340);
           if(i==5)pDC-Ellipse(40,200,120,280);
           if(i==6)pDC-Ellipse(0,80,80,160);
       }
       if(OK()){
           if(IDOK==MessageBox(TEXT("你完成了这个游戏")))
               PostQuitMessage(NULL);
       }
       ValidateRect(NULL);
    }

    void CMainWnd::OnLButtonUp(UINT nFlags,CPoint point){
       if(point.x160&&point.x80&&point.y80&&point.y0)Set(0);
       else if(point.x320&&point.x240&&point.y80&&point.y0)Set(1);
       else if(point.x400&&point.x320&&point.y160&&point.y80)Set(2);
       else if(point.x360&&point.x280&&point.y280&&point.y200)Set(3);
       else if(point.x240&&point.x160&&point.y340&&point.y260)Set(4);
       else if(point.x120&&point.x40&&point.y280&&point.y200)Set(5);
       else if(point.x800&&point.x00&&point.y160&&point.y80)Set(6);
    }
    void CMainWnd::Set(UINT nNum){
       bTrue[nNum]=!bTrue[nNum];
       bTrue[(nNum+3)%7]=!bTrue[(nNum+3)%7];
       bTrue[(nNum+4)%7]=!bTrue[(nNum+4)%7];
       InvalidateRect(NULL);
    }
    bool CMainWnd::OK(){
       for(int i=0;i7;i++)
           if(!(bTrue))return false;
       return true;
    }

    楼主 2016-01-15 16:56 回复

共有回帖数 0
  • 回 帖
  • 表情 图片 视频
  • 发表

登录直线网账号

Copyright © 2010~2015 直线网 版权所有,All Rights Reserved.沪ICP备10039589号 意见反馈 | 关于直线 | 版权声明 | 会员须知