VC编写贪吃蛇

来源:百度知道 编辑:UC知道 时间:2024/07/07 20:59:14
改贪吃蛇程序,想以客户区为边框,改的好象不对!

void CMyView::OnDraw(CDC* pDC)
{
CMyDoc* pDoc=GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//画边框
CRect rect;
GetClientRect(&rect); 我的意思是不画框了。直接区域就以客户区为边框

void CMyView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CPoint uPoint = m_aBody.GetAt(0);
int uTag = 0; //是否失败

switch( m_nDirct) //判断下一步蛇是否出边界
{
case 1: //向右
uPoint.x++;
if( uPoint.x >= rect.Width()) 说是这里错误,如何获得客户区的宽度
uTag = 1; 我这是瞎蒙的,呵呵,哪位朋友指点一下
break; 小弟初学者
case 2: //向左
uPoint.x--;
if( uPoint.x < 0)
uTag = 1;
break;
case 3: //向下
uPoint.y++;
if( uPoint.y >= rect.Height()) 说是这里错误
uTag = 1;
break;
case

你不应该改了uPoint的值再去判断,应该是先判断,越界就不处理。如:
if(uPoint.x!=0)
{
uPoint.x--;
}
这样才会正确,不然就会有uPoint.x<0了,这是不正确的,显示时有问题