import java.util.*; public class snake{ Deque snakeList = new ArrayDeque<>(); cell head; public snake(cell startPos){ head = startPos; snakeList.add(startPos); head.setSnakeCell(true); } public void grow(cell nextCell){ nextCell.setSnakeCell(true); head = nextCell; snakeList.addFirst(nextCell); } public void move(cell nextCell){ cell tail = snakeList.removeLast(); tail.setEmptyCell(true); head = nextCell; snakeList.addFirst(nextCell); for(cell c : snakeList){ c.setSnakeCell(true); } } public boolean checkCrash(cell nextCell){ for(cell cell : snakeList){ if(cell == nextCell) { return true; } } return false; } public Deque getSnakeList(){ return snakeList; } public cell getHead(){ return head; } public void setSnakeList(Deque snakeList){ this.snakeList = snakeList; } }