Coby Lu / game

Dependents:   snake

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers game.cpp Source File

game.cpp

00001 #include "game.h"
00002 #include "list.h"
00003 
00004 void score(Apple* apple, int* points) {
00005     *points += 10;
00006     apple->row = rand() % ROW;
00007     apple->col = rand() % COL;
00008 }
00009 
00010 int checkGameOver(List* snake) {
00011     Lnode* head = snake->head;
00012     Lnode* phere = head->next;
00013     while(phere != NULL) {
00014         if(phere->row == head->row && phere->col == head->col) {
00015             return 0;
00016         }
00017         phere = phere->next;
00018     }
00019     if(head->row < 0 || head->row > ROW || head-> col < 0 || head->col > COL){
00020         return 0;
00021     }
00022     return 1;
00023 }
00024