我是VC新手,做一个打字符的游戏时候,碰到几个问题,如字符串下落,我用最基本的的方法就是
dc.SetTextColor(RGB(0,0,0));
c.TextOut(nXPos,j,pChar[i]);
Sleep(300);
设置下落方式,但是前面的痕迹无法去掉,我试着用背景色重画,但是还是有百色的小框框,不知道怎么解决。
第二个问题,我用键盘输入一个字符,并依据此字符确定是否还需要画,来完成打中字符操作,好像我输入字符根本没有办法传入循环中,实现方式如下:
for(int i = 0;i < 100;i ++)
{

int nXPos = (rand()%10)*50 + 100; for(int j = 55;j < 400;j = j + 50)
{
char cChr = GetChar();
dc.TextOut(30,30,cChr);
if(pChar[i] == cChr) 
{
AfxMessageBox("打中了!!!");
break;
}
dc.SetTextColor(RGB(0,0,0));
dc.TextOut(nXPos,j,pChar[i]);
Sleep(300);
}
}
键盘输入的方式如下:
void CGame1View::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
// TODO: Add your message handler code here and/or call default
if(((nChar >= _T('A'))&&(nChar <= _T('Z')))||((nChar >= _T('a'))&&(nChar <= _T('z'))))
{
cChar = nChar;
}
CView::OnChar(nChar, nRepCnt, nFlags);
}
字符传递:
char CGame1View::GetChar()
{
return cChar;
}
请指正!!!

解决方案 »

  1.   

    用个定时器。
    在OnPaint中输出文本,在OnTimer中InvalidateRect(rect,FALSE);
      

  2.   

    Example
    This is the example from the CWnd::UpdateWindow method.// In this example a rectangle is drawn in a view. 
    // The OnChangeRect() function changes the dimensions 
    // of the rectangle and then calls CWnd::Invalidate() so the 
    // client area of the view will be redrawn next time the
    // window is updated.  It then calls CWnd::UpdateWindow 
    // to force the new rectangle to be painted.void CTestView::OnChangeRect() 
    {
      // Change Rectangle size.
      m_rcBox = CRect(20, 20, 210, 210);  // Invalidate window so entire client area 
      // is redrawn when UpdateWindow is called.
      Invalidate();    // Update Window to cause View to redraw.
      UpdateWindow();
    }// On Draw function draws the rectangle.
    void CTestView::OnDraw(CDC* pDC)
    {
    //  ..  Other draw code here.  pDC->Draw3dRect(m_rcBox, 0x00FF0000, 0x0000FF00);
    }
      

  3.   

    for(int i = 0;i < 100;i ++)
    {

    int nXPos = (rand()%10)*50 + 100; for(int j = 55;j < 400;j = j + 50)
    {
    char cChr = GetChar();
    dc.TextOut(30,30,cChr);
    if(pChar[i] == cChr) 
    {
    AfxMessageBox("打中了!!!");
    break;
    }
    dc.SetTextColor(RGB(0,0,0));
    dc.TextOut(nXPos,j,pChar[i]);
    Sleep(300);
                                        Invalidate(FALSE);//
    }
    }
      

  4.   

    DentistryDoctor(雅克医生<改行做程序员了>) 和 jack_wq(风尘往事具忘去,心地无私天地宽) ( ) 信回答可以了,如果没有人回答,我揭帖了,分全给他们了!
    在线等..............