class19-Recursion.java

Waitforkeypressg recursionmoveg 7 0 2 1

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1, col)) + Recursion.burn(g, new Location(row, col - 1)) + Recursion.burn(g, new Location(row, col + 1)) + Recursion.burn(g, new Location(row + 1, col)); g.setColor(loc, new Color(200, 200, 200)); //light gray Recursion.waitForKeyPress(g); g.setColor(loc, new Color(100, 100, 100)); //dark gray return burned; } } public static void testBurn() { Grid g; g = new Grid(15, 15); g.setTitle("Forest Fire"); int row; for (row = 0; row < g.getNumRows(); row = row + 1) { int col; for (col = 0; col < g.getNumCols(); col = col + 1) { if (Math.random() < 0.5) { g.setColor(new Location(row, col), new Color(0, 255, 0)); } } } while (true) { g.pause(100); Location loc; loc = g.checkLastLocationClicked(); if (loc != null) { int burned; burned = Recursion.burn(g, loc); System.out.println("Trees burned: " + burned); } } } public static void waitForKeyPress(Grid g) { while (g.checkLastKeyPressed() == -1) { g.pause(100); } } }...
View Full Document

This note was uploaded on 09/14/2010 for the course CS 15-100 taught by Professor Dave during the Spring '08 term at Carnegie Mellon.

Ask a homework question - tutors are online