Peng Jingran
/
Snake_copy
ccc
Food/Food.cpp@0:bc1d36f5f772, 2019-05-05 (annotated)
- Committer:
- VivianDu
- Date:
- Sun May 05 14:06:00 2019 +0000
- Revision:
- 0:bc1d36f5f772
- Child:
- 13:9a6aff771774
version_change
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
VivianDu | 0:bc1d36f5f772 | 1 | #include "Food.h" |
VivianDu | 0:bc1d36f5f772 | 2 | |
VivianDu | 0:bc1d36f5f772 | 3 | pos food; |
VivianDu | 0:bc1d36f5f772 | 4 | |
VivianDu | 0:bc1d36f5f772 | 5 | |
VivianDu | 0:bc1d36f5f772 | 6 | Food::Food(){ |
VivianDu | 0:bc1d36f5f772 | 7 | |
VivianDu | 0:bc1d36f5f772 | 8 | } |
VivianDu | 0:bc1d36f5f772 | 9 | |
VivianDu | 0:bc1d36f5f772 | 10 | Food::~Food(){ |
VivianDu | 0:bc1d36f5f772 | 11 | |
VivianDu | 0:bc1d36f5f772 | 12 | } |
VivianDu | 0:bc1d36f5f772 | 13 | void Food::init(){ |
VivianDu | 0:bc1d36f5f772 | 14 | |
VivianDu | 0:bc1d36f5f772 | 15 | food.x=30; |
VivianDu | 0:bc1d36f5f772 | 16 | food.y=30; |
VivianDu | 0:bc1d36f5f772 | 17 | }//set the initial foof position |
VivianDu | 0:bc1d36f5f772 | 18 | |
VivianDu | 0:bc1d36f5f772 | 19 | void Food::draw(N5110 &lcd){ |
VivianDu | 0:bc1d36f5f772 | 20 | |
VivianDu | 0:bc1d36f5f772 | 21 | lcd.setPixel(food.x,food.y); |
VivianDu | 0:bc1d36f5f772 | 22 | |
VivianDu | 0:bc1d36f5f772 | 23 | }//draw the food on the screen |
VivianDu | 0:bc1d36f5f772 | 24 | |
VivianDu | 0:bc1d36f5f772 | 25 | void Food::response(){ |
VivianDu | 0:bc1d36f5f772 | 26 | |
VivianDu | 0:bc1d36f5f772 | 27 | srand(time(NULL)); |
VivianDu | 0:bc1d36f5f772 | 28 | food.x=(rand()%35)+5; |
VivianDu | 0:bc1d36f5f772 | 29 | food.y=(rand()%28)+3; |
VivianDu | 0:bc1d36f5f772 | 30 | } |
VivianDu | 0:bc1d36f5f772 | 31 | |
VivianDu | 0:bc1d36f5f772 | 32 | pos Food::returnPos(){ |
VivianDu | 0:bc1d36f5f772 | 33 | |
VivianDu | 0:bc1d36f5f772 | 34 | pos a = { food.x, food.y}; |
VivianDu | 0:bc1d36f5f772 | 35 | return a; |
VivianDu | 0:bc1d36f5f772 | 36 | |
VivianDu | 0:bc1d36f5f772 | 37 | }//report food position |