SimpleLib_03272011

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Snake.cpp Source File

Snake.cpp

00001 #include "mbed.h"
00002 #include "Snake.h"
00003 
00004 Snake::Snake( )
00005 {
00006     head = tail = NULL;
00007     size = 0;
00008 }
00009 void Snake::addHead( int xC, int yC  )
00010 {
00011     Node * p = ( Node * ) malloc ( sizeof ( Node ) );
00012     if ( head == NULL )
00013     {
00014         head = tail = p;
00015         p->next = NULL;
00016     }
00017     else
00018     {
00019         p->x = xC;
00020         p->y = yC;
00021         head->next = p;
00022         head = p;
00023     }
00024     
00025     size++;
00026 
00027 }
00028 
00029 void Snake::removeTail( )
00030 {
00031     Node * temp = tail;
00032     tail = tail->next;
00033     delete( temp );
00034     size--;
00035 }
00036 
00037 int Snake::getTailXCor( )
00038 {
00039     return tail->x;
00040 }
00041 int Snake::getTailYCor( )
00042 {
00043     return tail->y;
00044 }
00045 
00046 int Snake::getSize()
00047 {
00048     return size;
00049 }