Li Saiwen 201089052
Dependencies: mbed Gamepad N5110
Food/Food.cpp@7:cafa0b96e8d3, 2019-05-05 (annotated)
- Committer:
- 1012754868
- Date:
- Sun May 05 12:10:48 2019 +0000
- Revision:
- 7:cafa0b96e8d3
- Parent:
- 3:7b28047013d2
Fix some bug
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
1012754868 | 3:7b28047013d2 | 1 | #include "Food.h" |
1012754868 | 3:7b28047013d2 | 2 | |
1012754868 | 3:7b28047013d2 | 3 | Foodpos food; |
1012754868 | 3:7b28047013d2 | 4 | |
1012754868 | 3:7b28047013d2 | 5 | |
1012754868 | 3:7b28047013d2 | 6 | Food::Food(){ |
1012754868 | 3:7b28047013d2 | 7 | |
1012754868 | 3:7b28047013d2 | 8 | } |
1012754868 | 3:7b28047013d2 | 9 | |
1012754868 | 3:7b28047013d2 | 10 | Food::~Food(){ |
1012754868 | 3:7b28047013d2 | 11 | |
1012754868 | 3:7b28047013d2 | 12 | } |
1012754868 | 3:7b28047013d2 | 13 | void Food::init(){ |
1012754868 | 7:cafa0b96e8d3 | 14 | food.x=50; |
1012754868 | 3:7b28047013d2 | 15 | food.y=25; |
1012754868 | 7:cafa0b96e8d3 | 16 | } |
1012754868 | 3:7b28047013d2 | 17 | |
1012754868 | 3:7b28047013d2 | 18 | void Food::drawfood(N5110 &lcd){ |
1012754868 | 3:7b28047013d2 | 19 | |
1012754868 | 7:cafa0b96e8d3 | 20 | lcd.setPixel(food.x,food.y); |
1012754868 | 3:7b28047013d2 | 21 | |
1012754868 | 7:cafa0b96e8d3 | 22 | } |
1012754868 | 3:7b28047013d2 | 23 | |
1012754868 | 3:7b28047013d2 | 24 | void Food::createfood(){ |
1012754868 | 3:7b28047013d2 | 25 | |
1012754868 | 7:cafa0b96e8d3 | 26 | srand(time(NULL)); |
1012754868 | 3:7b28047013d2 | 27 | food.x=(rand()%81)+2; |
1012754868 | 3:7b28047013d2 | 28 | food.y=(rand()%27)+10; |
1012754868 | 3:7b28047013d2 | 29 | |
1012754868 | 7:cafa0b96e8d3 | 30 | } |
1012754868 | 3:7b28047013d2 | 31 | |
1012754868 | 3:7b28047013d2 | 32 | Foodpos Food::returnPos(){ |
1012754868 | 3:7b28047013d2 | 33 | |
1012754868 | 3:7b28047013d2 | 34 | Foodpos p = { food.x, food.y}; |
1012754868 | 3:7b28047013d2 | 35 | return p; |
1012754868 | 3:7b28047013d2 | 36 | |
1012754868 | 3:7b28047013d2 | 37 | } |