菜鸟问题,请高手赐教!!!
我是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;
}
请指正!!!
问题点数:50、回复次数:10Top
1 楼DentistryDoctor(不在无聊中无奈,就在沉默中变态)回复于 2004-12-03 10:55:20 得分 15
用个定时器。
在OnPaint中输出文本,在OnTimer中InvalidateRect(rect,FALSE);
Top
2 楼gimney(星外来客)回复于 2004-12-03 11:22:57 得分 0
那键盘输入怎么传递了,能不能说明白点,谢谢了!Top
3 楼gimney(星外来客)回复于 2004-12-03 11:27:10 得分 0
能把你的思路说一下就好了!Top
4 楼jack_wq(风尘往事具忘去,心地无私天地宽)回复于 2004-12-03 11:32:50 得分 0
Invalidate()Top
5 楼jack_wq(风尘往事具忘去,心地无私天地宽)回复于 2004-12-03 11:33:29 得分 7
Invalidate()刷新原来的窗口Top
6 楼xuzheng318(忧郁王子)回复于 2004-12-03 11:40:29 得分 5
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);
}
Top
7 楼oyljerry(【勇敢的心】→ ㊣提拉米苏√㊣)回复于 2004-12-03 12:42:35 得分 10
就是用定时器获得键盘输入,然后再画Top
8 楼koko1998(高价购买火车票)回复于 2004-12-03 12:46:26 得分 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);//
}
}
Top
9 楼gimney(星外来客)回复于 2004-12-03 13:02:48 得分 0
DentistryDoctor(雅克医生<改行做程序员了>) 和 jack_wq(风尘往事具忘去,心地无私天地宽) ( ) 信回答可以了,如果没有人回答,我揭帖了,分全给他们了!
在线等..............Top
10 楼crystal521(【云淡风轻】)回复于 2004-12-03 13:26:36 得分 10
在timer中实现循环判断Top




