int k=m_body.GetUpperBound()+2; //设置一个变量存储贪吃蛇的身体长度
if(k<=10) //如果小于10,那么就为绿色
{
ysbrush.CreateSolidBrush(RGB(0,255,0));
MemDC.SelectObject(&ysbrush);
//绘制果实
MemDC.Rectangle(
CRect(10+m_psFood.y*10,
120+m_psFood.x*10,
10+(m_psFood.y+1)*10,
120+(m_psFood.x+1)*10)
);
}
else if(k>10&&k<=20) //如果在10和20之间,那么就为绿色
{
ysbrush.CreateSolidBrush(RGB(0,0,255));
MemDC.SelectObject(&ysbrush);
//绘制果实
MemDC.Rectangle(
CRect(10+m_psFood.y*10,
120+m_psFood.x*10,
10+(m_psFood.y+1)*10,
120+(m_psFood.x+1)*10)
);
}
else if(k>20&&k<=30) //如果在20和30之间,那么就为绿色
{
ysbrush.CreateSolidBrush(RGB(255,255,0));
MemDC.SelectObject(&ysbrush);
//绘制果实
MemDC.Rectangle(
CRect(10+m_psFood.y*10,
120+m_psFood.x*10,
10+(m_psFood.y+1)*10,
120+(m_psFood.x+1)*10)
);
}
else //其余情况均为红色
{
ysbrush.CreateSolidBrush(RGB(255,0,0));
MemDC.SelectObject(&ysbrush);
//绘制果实
MemDC.Rectangle(
CRect(10+m_psFood.y*10,
120+m_psFood.x*10,
10+(m_psFood.y+1)*10,
120+(m_psFood.x+1)*10) VC++贪吃蛇游戏设计+流程图(14):http://www.youerw.com/jisuanji/lunwen_3399.html