public class snakeGame{ board board; snake snake; int score; int direction; int noneDirection = 0; int upDirection = 2; int downDirection = -2; int rightDirection = 1; int leftDirection = -1; boolean gameOver; public snakeGame(int numbRows, int numbCols){ // init board board = new board(numbRows, numbCols); //init snake cell initCell = board.getCells()[0][0]; initCell.setSnakeCell(true); snake = new snake(initCell); // init variabler gameOver = false; direction = rightDirection; score = 0; board.generateFood(); board.generateFood(); board.generateFood(); } public snake getSnake(){ return snake; } public board getBoard(){ return board; } public int getDirection(){ return direction; } public boolean getGameOver(){ return gameOver; } public int getScore(){ return score; } public boolean isGameOver(){ return gameOver; } public void setGameOver(boolean cond){ gameOver = cond; } public void addScore(){ score++; } public void setDirection(int direction){ this.direction = direction; } public cell getNextcell(cell currentPos){ int row = currentPos.getRow(); int col = currentPos.getCol(); if(direction == rightDirection){ col++; } else if(direction == leftDirection){ col--; } else if(direction == upDirection){ row--; } else if(direction == downDirection){ row++; } cell nextCell = board.getCell(row, col); return nextCell; } public void update(){ if(!gameOver){ if(direction != noneDirection){ cell nextCell = getNextcell(snake.getHead()); if(!snake.checkCrash(nextCell)){ if(nextCell.isFoodCell){ snake.grow(nextCell); board.generateFood(); score++; } snake.move(nextCell); } else{ setDirection(noneDirection); gameOver = true;//hvis vi kr?sjer e det game over } } } } }