You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include "Food.h"
|
|
|
|
|
#include <ctime>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <graphics.h>
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
|
|
Food::Food()
|
|
|
|
|
{
|
|
|
|
|
//<2F><>ʼ<EFBFBD><CABC>ʳ<EFBFBD><CAB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
this->m_state = true;
|
|
|
|
|
this->m_pos = Point(310, 230);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Food::getState()
|
|
|
|
|
{
|
|
|
|
|
return this->m_state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Food::setState(bool state)
|
|
|
|
|
{
|
|
|
|
|
this->m_state = state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Point Food::getPos()
|
|
|
|
|
{
|
|
|
|
|
return this->m_pos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Food::Generate(Snake* snake)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ʳ<EFBFBD><CAB3>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>ȡ<EFBFBD>ߵ<EFBFBD><DFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ɵ<EFBFBD>ʳ<EFBFBD><CAB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵ<EFBFBD><DFB5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
int x = 0;
|
|
|
|
|
int y = 0;
|
|
|
|
|
bool isOk = false;
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
//ʹ<><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʳ<EFBFBD><CAB3>
|
|
|
|
|
srand(time(0));
|
|
|
|
|
x = (rand() % 24) * 20 + 10;
|
|
|
|
|
y = (rand() % 24) * 20 + 10;
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ߵ<EFBFBD><DFB5><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
isOk = 1;
|
|
|
|
|
|
|
|
|
|
std::list<Point> pos = snake->GetSnakeAllNode();
|
|
|
|
|
std::list<Point>::iterator it = find(pos.begin(), pos.end(), Point(x, y));
|
|
|
|
|
//find()<29><>Ҫ<EFBFBD>õ<EFBFBD>Point<6E><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD> == <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (it == pos.end())//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
this->m_pos = Point(x, y);//<2F><EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
this->m_state = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Food::DrawFood()
|
|
|
|
|
{
|
|
|
|
|
//<2F><>ɫ<EFBFBD><C9AB>ȫ<EFBFBD><C8AB><EFBFBD>䣬<EFBFBD>ޱ߿<DEB1><DFBF><EFBFBD>Բ
|
|
|
|
|
setfillcolor(RED);
|
|
|
|
|
setfillstyle(BS_SOLID);
|
|
|
|
|
solidcircle(this->m_pos.x, this->m_pos.y, FOOD_RADIU);
|
|
|
|
|
}
|