Snake game food library

Committer:
1012754868
Date:
Fri Apr 26 04:46:35 2019 +0000
Revision:
2:679ab99f2c0f
Parent:
1:8d4639c9d1b0
Completed the basic function of the game snake, made the game selection interface, and left the highest historical record of the game undone.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Nefos 0:337503f9282c 1 #include "Food.h"
Nefos 0:337503f9282c 2
1012754868 2:679ab99f2c0f 3 Foodpos food;
Nefos 0:337503f9282c 4
Nefos 0:337503f9282c 5
Nefos 0:337503f9282c 6 Food::Food(){
Nefos 0:337503f9282c 7
Nefos 1:8d4639c9d1b0 8 }
Nefos 0:337503f9282c 9
Nefos 0:337503f9282c 10 Food::~Food(){
Nefos 0:337503f9282c 11
Nefos 1:8d4639c9d1b0 12 }
Nefos 0:337503f9282c 13 void Food::init(){
Nefos 1:8d4639c9d1b0 14 food.x=48;//set first food
Nefos 1:8d4639c9d1b0 15 food.y=25;
Nefos 1:8d4639c9d1b0 16 }//end of init
Nefos 0:337503f9282c 17
1012754868 2:679ab99f2c0f 18 void Food::drawfood(N5110 &lcd){
Nefos 0:337503f9282c 19
Nefos 1:8d4639c9d1b0 20 lcd.setPixel(food.x,food.y);//draw food
Nefos 1:8d4639c9d1b0 21
Nefos 1:8d4639c9d1b0 22 }//end of draw
Nefos 0:337503f9282c 23
1012754868 2:679ab99f2c0f 24 void Food::createfood(){
Nefos 1:8d4639c9d1b0 25
Nefos 1:8d4639c9d1b0 26 srand(time(NULL));//randomly respawn food
Nefos 1:8d4639c9d1b0 27 food.x=(rand()%81)+2;
Nefos 1:8d4639c9d1b0 28 food.y=(rand()%27)+10;
Nefos 0:337503f9282c 29
Nefos 1:8d4639c9d1b0 30 }//end of respawn
Nefos 1:8d4639c9d1b0 31
1012754868 2:679ab99f2c0f 32 Foodpos Food::returnPos(){
Nefos 0:337503f9282c 33
1012754868 2:679ab99f2c0f 34 Foodpos p = { food.x, food.y};
Nefos 1:8d4639c9d1b0 35 return p;
Nefos 1:8d4639c9d1b0 36
Nefos 0:337503f9282c 37 }