Please don't copy from chegg and course hero import java.util.Iterator; import java.util.Random; public class SnakeWorld { public
Question:
Please don't copy from chegg and course hero
import java.util.Iterator; import java.util.Random;
public class SnakeWorld { public static final int WIDTH = 100; public static final int HEIGHT = 70; public static final int MAX_APPLES = 8; public static class Pos { public int x, y; public Pos(int x, int y) { this.x = x; this.y = y; } public boolean equals(Pos pos) { return x == pos.x && y == pos.y; } } //class Apple private static class Apple { private Wall wall; private Snake snake; private Pos pos; //apple position private int createCount;
//constructor... public Apple(Wall wall, Snake snake) { this.wall = wall; this.snake = snake; init(); } public void init() { createCount = 0; create(); } public int create() { Random rand = new Random(); //TODO: randomly place an apple at (x,y) such that // 1. 0 <= x < WIDTH, // 2. 0 <= y < HEIGHT, and // 3. it does not hit the wall nor the snake (use the hit method)
return createCount++; } public int getCount() { return createCount; } public Pos getPos() { return pos; } }
//class Wall private static class Wall implements Iterable
public Iterator
//TODO: if incr > 0 then decrease it by 1 // otherwise, remove tail from body } public void grow() { //TODO: increase incr by the size of body } public int size() { //TODO: return the size of body return 0; } public Iterator
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch