void SnakePart::initialize() { setPartType(SnakePartType::Empty); setPartTop(false); setPartBottom(false); setPartLeft(false); setPartRight(false); }
//moves the given snake by 1 depending on the direction stored in its structure int moveSnake( Snake *sn ) { int px; int py; if( sn==NULL ) return -1; //check if last element in the list contains if( getPartType( sn, sn->length -1 ) == SNAKE_EATEN ) { setPartType( sn, sn->length -1, SNAKE_PART ); sn->length++; } //get last recorded head coordinates px = sn->buf[sn->head].x; py = sn->buf[sn->head].y; //move the head back sn->head--; if( sn->head < 0 ) sn->head = WIN_LENGTH - 1; //update the position of the new head sn->buf[sn->head].y = py; sn->buf[sn->head].x = px; switch( sn->dir ) { case UP : sn->buf[sn->head].y--; break; case LEFT : sn->buf[sn->head].x--; break; case DOWN : sn->buf[sn->head].y++; break; case RIGHT: sn->buf[sn->head].x++; break; } return 0; }