public void checkEndState() {

			int completed = 0;
			// Check if the chests are in the goal squares.
			for (int chestIndex = 0; chestIndex < chests.size(); chestIndex++) {
				Treasure chest = (Treasure) chests.get(chestIndex);
				for (int goalIndex = 0; goalIndex < goals.size(); goalIndex++) {
					Goal goal = goals.get(goalIndex);
					if (chest.getX() == goal.getX()
							&& chest.getY() == goal.getY())
						completed++;
				}
			}
			// Current score is the number of chests in goal squares.
			currentScore = completed;
			// If all goal squares are filled, then the player is finished.
			if (completed == goals.size()) {
				finished = true;
				repaint();
			}
		}