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(20, 36);
- accomplishedSnake = false;
- accomplishedApples = false;
- if(!accomplishedSnake) {
- for(int i=0; i<snake.getSize(); i++) {
- if (snake.getPart(i).getX() >= xApple
- && snake.getPart(i).getX() + 20 <= xApple
- && snake.getPart(i).getX() >= xApple+20
- && snake.getPart(i).getX() + 20 <= xApple+20
- && snake.getPart(i).getY() >= yApple
- && snake.getPart(i).getY() + 20 <= yApple
- && snake.getPart(i).getY() >= yApple +20
- && snake.getPart(i).getY() + 20 <= yApple +20) {
- break;
- }
- if(i == snake.getSize()-1)
- accomplishedSnake = true;
- }
- }
- if(!accomplishedApples) {
- for(int i=0; i<apples.size; i++) {
- if(apples.get(i).getX() == xApple && yApple == apples.get(i).getY()) {
- accomplishedApples = false;
- accomplishedSnake = false;
- break;
- }
- if(i == apples.size-1)
- accomplishedApples = true;
- }
- }
- }
- apples.add(new Apple(xApple, yApple));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement