-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFood.cpp
More file actions
45 lines (40 loc) · 1006 Bytes
/
Food.cpp
File metadata and controls
45 lines (40 loc) · 1006 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include"Food.h"
Food::Food(Wall& w1) :wall(w1) { FoodX = 0, FoodY = 0, attribute = 0; }
void Food::Setfood() //设置食物
{
while (true)
{
FoodX = rand() % (Wall::row - 2) + 1; //随机生成x坐标
FoodY = rand() % (Wall::col - 2) + 1; //随机生成y坐标
if (wall.Getwall(FoodY, FoodX) == " ") //打印食物块
{
wall.Setwall(FoodY, FoodX, (char*)"◆");
gotoxy(hOut, FoodX*2, FoodY);
int x = rand() % 5 + 1; //产生高分食物,道具的概率各为五分之一
if (x == 1)
{
attribute = 1;
blue();
std::cout << "◆";
t_start = clock();
}
else if (x == 2&&wall.map!=0)
{
attribute = 2;
red();
std::cout << "◆";
t_start = clock();
}
else
{
attribute = 0;
white();
std::cout << "◆";
}
break;
}
}
}
int Food::Get_FoodX() { return FoodX; } //获取食物横坐标
int Food::Get_FoodY() { return FoodY; } //获取食物纵坐标
int Food::Get_attribute() { return attribute; }//获得食物属性