这么编写这处代码对吗
clown 2009-08-25 06:56:17 MFC编写的贪吃蛇游戏
游戏边框是窗口客户区的边框
编写蛇出边框就结束游戏的代码时,有点毛病 我是这么编写的,但是运行之后 蛇出边框之后 也没弹出结束游戏,不知道哪的毛病
void CMyView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
GetClientRect(&rect);
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 4: //向上
uPoint.y--;
if( uPoint.y < 0)
uTag = 1;
break;
}