Question
public void initialize() { System.out.println(initialize); for (int i = 0; i < gridColumns; ++i) { for (int j = 0; j < gridRows; ++j) {
public void initialize() { System.out.println("initialize"); for (int i = 0; i < gridColumns; ++i) { for (int j = 0; j < gridRows; ++j) { if (i % 2 == j % 2) { setBGColor(j, i, bg); } else { setBGColor(j, i, bc); } } }
head = new Block(startX, startY); tail = head; for (int i = 0; i < startLength; ++i) { Block newBlock = new Block(startX - i, startY); tail.next = newBlock; tail = newBlock; setBGColor(startY, startX - i, fg); if (i > 0) { //TODO: BASED ON THE SIZE OF THE STARTING SNAKE, ENQUEUE A NEW BLOCK TO THE LINKED LIST } }
frameTime = System.nanoTime(); nextFrameTime = frameTime + FRAMERATE; dir = Direction.EAST; lastDir = dir; apple = new Block(); bomb = new Block(); plantApple(); plantBomb(); }
// Game loop will run many times per second. // handle input, check if apple was detected, update position, redraw, // detect if snake ate itself public void gameLoop() { handleInput(); if (System.nanoTime() > nextFrameTime) { frameTime = System.nanoTime(); nextFrameTime = frameTime + FRAMERATE;
lastDir = dir;
detectApple(); detectBomb();
updatePosition();
paint();
detectDeath();
} }
public static void main(String args[]) { SnakeScaffold game = new SnakeScaffold(22, "test", "137842425086", gridColumns, gridRows); game.setTitle("snake"); game.setDescription("Snake: Eat the food, not yourself!");
game.start(); }
public static Block enqueue(Block tail, Block next) { tail.next = next; return tail; }
public static Block dequeue(Block head) {
return head.next; } }
enum Direction { NORTH, SOUTH, EAST, WEST }
class Block {
public Block next; public int x; public int y;
public Block() { this(-1, -1, null); }
public Block(int x, int y) { this(x, y, null); }
public Block(int x, int y, Block next) { this.x = x; this.y = y; this.next = next; } } Please I just need the java coding for the TODO, please code correctly. thank you.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started