Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void addApple() {
- accomplishedSnake = false;
- accomplishedApples = false;
- while(!accomplishedSnake && !accomplishedApples) {
- xApple = 20 * MathUtils.random(0, 23);
- yApple = 20 * MathUtils.random(0, 39);
- for(int i=0; i<snake.getSize(); i++) {
- if(snake.getPart(i).getX() == xApple && yApple == snake.getPart(i).getY())
- break;
- if(i == snake.getSize()-1) {
- accomplishedSnake = true;
- break;
- }
- }
- for(int i=0; i<apples.size; i++) {
- if(apples.get(i).getX() == xApple && yApple == apples.get(i).getY())
- break;
- if(i == apples.size-1) {
- accomplishedApples = true;
- break;
- }
- }
- }
- apples.add(new Apple(xApple, yApple));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement