-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFood.cpp
More file actions
41 lines (38 loc) · 812 Bytes
/
Copy pathFood.cpp
File metadata and controls
41 lines (38 loc) · 812 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
/*
* =====================================================================================
*
* Filename: Food.cpp
*
* Description: :
*
* Version: 1.0
* Created: 2012/3/31 星期六 16:14:08
* Revision: none
* Compiler: gcc
*
* Author: Python (),
* Company:
*
* =====================================================================================
*/
#include "tool.h"
#include "Food.h"
#include <iostream>
using std::cout;
Food::Food(SnakeMap *map) {
x = y = 0;
food = '@';
ate = true;
this->map = map;
srand(time(0));
}
void Food::createFood() {
if(ate) {
//为了防止食物溢出地图,所以把边界稍作修改
x = random(map->LB+1 , map->RB - 2);
y = random(map->UB+1 , map->DB - 2);
gotoPos(x,y);
cout<<food;
ate = false;
}
}