I have to make the bricks i print out from the drawRow method multi coloured by calling the method and using this to go through the colors per brick.
import java.util.ArrayList; /** * Write a description of class BrickWall here. * * @author (your name) * @version (a version number or a date) */ public class BrickWall { // instance variables - replace the example below with your own private Integer bWidth; private Integer bHeight; private Integer numRows; private Integer rowLength; public ArrayList<String> colors; public ArrayList<Rectangle> bricks; private Boolean decrease; private Boolean isSymmetric; private Boolean isMultiColor; private Integer currentColor; private Integer startX; private Integer startY; private Rectangle brick; /** * Constructor for objects of class BrickWall. * @param rows The number of rows in the wall * @param rowlen The maximum number of bricks in a row * @param isMultiColor when false all bricks are the same colour. When true the colours cycle through the 6 colours. * @param decrease If true subtract 2 from rowLen for each row drawn * @param isSymmetric if decrease is greater than 0 and isSymmetric is true the wall is a pyramid shape, otherwise it is a rectangle or a right angle triangle. */ public BrickWall(Integer rows, Integer rowLen) { // initialise instance variables setUpColors(); bWidth = 54; bHeight = 16; startX = 10; startY = 550; bricks = new ArrayList<Rectangle>(); currentColor = 0; setNumRows(rows); setRowLength(rowLen); this.isMultiColor = false; this.decrease = false; this.isSymmetric = false; } private void setUpColors() { colors = new ArrayList<String>(); colors.add("red"); colors.add("yellow"); colors.add("blue"); colors.add("green"); colors.add("magenta"); colors.add("black"); } /** * Toggle whether the wall is multicoloured. */ public void toggleMultiColour() { isMultiColor = !isMultiColor; currentColor = 0; } /** * Toggle whether the decrease in a row length is symmetric. */ public void toggleSymmetric() { isSymmetric = !isSymmetric; } /** * Toggle whether the length of a new row is one less than the length of the previous row. */ public void toggleDecrease() { decrease = ! decrease; } /** * @return the number of bricks in the current wall. */ public Integer getNumberOfBricks() { return bricks.size(); } /** * Set the length of a row. There can be no more than 22 bricks in a row. * @param len The number of bricks in a row. If len is less than or equal * to zero OR len is greater than 22, the row length will be assigned the value 22. * Otherwise the length of a row will be assigned the value of len. */ public void setRowLength(Integer len) { if (len <= 0 || len > 22) { rowLength = 22; } else { rowLength = len; } } /** * Set the maximum number of rows in the wall. If the length of a row decreases, * there may not be this many rows in the wall. * @param rows The maximum number of rows in the wall. If rows is less than * or equal to zero OR rows is greater than 30, the number of rows will be assigned the value 30. * Otherwise the number of rows will be assigned the value of rows. */ public void setNumRows(Integer rows) { if (rows <= 0 || rows > 30) { numRows = 30; } else { numRows = rows; } } private void drawRow() { Integer row1 = 0; while (row1 < numRows) { for (Integer row = 0; row <= rowLength; row++) { makeBrick(); startX = startX + 54; } startY = startY + 16; startX = 10; row1++; } } private void makeBrick() { brick = new Rectangle(); brick.makeVisible(); brick.changeSize(bWidth, bHeight); brick.setPosition(startX, startY); brick.changeColor(colors.get(0)); bricks.add(brick); } /** * Draw the wall. The first brick will be positioned at the coordinates (10, 550). * The number of bricks in a row is specified by setRowLength(). The maximum number of rows * is specified by setNumRows(). If decrease is true, each subsequent row of bricks * contains one brick less than the previous row. If symmetric is true AND decrease is true then * the wall is pyramid shaped. If symmetric is false AND decrease is true then the wall is shaped * like a right angle triangle. */ public void draw() { eraseWall(); drawRow(); if (isMultiColor = true) { } boolean decrease = false; boolean symmetric = false; } public void eraseWall() { Canvas canvas = Canvas.getCanvas(); for (int i=0; !bricks.isEmpty(); i++) { canvas.erase(bricks.remove(0)); } } }
As you can see above, my code the drawRow method creates a brick wall of however many bricks in length and however many rows I declare. however when i call the toggleMultiColored method it should use the ArrayList colours and for all the bricks it creates go through each ArrayList color creating a multi coloured effect with the final wall.
Many thanks in advanced.