-#include <stdlib.h>
-#include <stdio.h>
 #include <SPI.h>
-//#include <SD.h>
 #include <TFT.h>
- 
+#include "structworkaround.h"
+
 /* TFT pins */
 #define LCD_CS   10
 #define SD_CS 4

    free(temp);
    head = NULL;
  } else {
    remSegment(temp->x,temp->y);
    free(last->next_ptr);
    last->next_ptr = NULL;  
  }
}

/* Check if a coordinate exist in the linked list */
int isMember(int x, int y){
   temp = head->next_ptr;
   while(temp){
     if (temp->x == x && temp->y ==y){
       return 1; 
     }
     temp = temp->next_ptr;
   }
   return 0;  
}

/* Check if the snake head is on a foodTile and should grow */
int isGrow(){
  if(head->x == foodTile.x && head->y == foodTile.y){
   return 1; 
  } else {
    return 0;
  }
}

/* Check if the snake head is on a forbidden tile and should die :/ */
int isCollision(){
  if (isMember(head->x,head->y)){
    return 1;
  }
  if(head->x < 5 || head->x > 149 || head->y < 4 || head->y > 118){
    return 1;
  }
  return 0;
}

/* Print score etc before starting over */
void endScreen(){
  myScreen.background(0, 255, 0);
  myScreen.stroke(255,255,255);
  String scorestring = String(score);
  scorestring.toCharArray(scoreChars,5);
  
  myScreen.text("Game over", 40, 40);
  myScreen.text("Score:", 40, 50);
  myScreen.text(scoreChars, 80, 50);

  delay(1000); 
}

/***********************************************************************
 * SETUP
 */

void setup(){
  myScreen.begin();
//  SD.begin(SD_CS);
  randomSeed(analogRead(0));
}

/***********************************************************************
 * LOOP
 */

void loop(){
  
  startScreen();
  /* Main brain game frame */
  while(!collision){

    /* Pushbutton input */
    getInput();
    delay(5); /* Just to be kind to the CPU */
    
    if (millis()-timestamp > 100){
      /* Update, draw, and check things */
      coord movetemp;
      movetemp.x = head->x + moveTo.x;
      movetemp.y = head->y + moveTo.y;
      
      addFirst(movetemp.x,movetemp.y);
      
      /* Draw */
      drawSegment(head->x, head->y);
      if (growBy){
        growBy--;
        score += 1;    
      }
      else {
        remLast();
      }
      
      if (isGrow()){
        growBy++;
        newFoodTile();
        drawFood(foodTile.x, foodTile.y);
      }

      if (isCollision()){
        collision = 1;
      }
      timestamp = millis();
    }
  }
  
  endScreen();
  delay(2000); /* TODO: pause until button is pressed */
}

    head = new_ptr;
}

void 
remLast(){
  coord *last;  
  temp = head;
  last = temp;
