g8rjosh
YaBB Newbies
Offline
Posts: 7
fill colors changing
Oct 16th , 2007, 5:54am
I'm trying to create a game board with colored piece objects, but the colors on the objects keep changing? How can I fix it? Thanks for any help. //*************** GAME PIECE CLASS ***************// class gamePiece{ color c; int tlxPos, tlyPos, brxPos, bryPos; gamePiece(color iC, int itlxPos, int itlyPos, int ibrxPos, int ibryPos){ c = iC; tlxPos = itlxPos; //top left x pos tlyPos = itlyPos; //top left y pos brxPos = ibrxPos; //bottom right x pos bryPos = ibryPos; //bottom right y pos fill(c); rect(tlxPos, tlyPos, brxPos, bryPos); } public color getColor(){ return c; } public int getTLXPos(){ return tlxPos; } public int getTLYPos(){ return tlyPos; } public int getBRXPos(){ return brxPos; } public int getBRYPos(){ return bryPos; } public boolean compareColors(gamePiece a, gamePiece b){ if(a.getColor() == b.getColor()){ return true; } else{ return false; } } } //*************** GAME BOARD CLASS ***************// class gameBoard{ int boardSize; public gameBoard(int i){ boardSize = i; } public int getBoardSize(){ return boardSize; } public void createRandomPieces(int arraySize){ int numPieces = arraySize * arraySize; int columns[] = new int[arraySize]; int rows[] = new int[arraySize]; int tlxLocation = 0; int brxLocation = 20; int tlyLocation = 0; int bryLocation = 20; gamePiece[] pieces = new gamePiece[numPieces]; for(int columnNumber = 0; columnNumber < columns.length; columnNumber++){ for(int rowNumber = 0; rowNumber < rows.length; rowNumber++){ pieces[rowNumber] = new gamePiece(palette[int(random(colorRange))], tlxLocation, tlyLocation, brxLocation, bryLocation); tlyLocation += 20; bryLocation += 20; } tlyLocation = 0; bryLocation = 20; tlxLocation += 20; brxLocation += 20; } } } //*************** GLOBAL VARIABLES****************// color[] palette = new color[5]; int gameBoardSize = 10; int colorRange = 5; gameBoard test = new gameBoard(gameBoardSize); //*************** SETUP FUNCTION ***************// void setup(){ size(test.getBoardSize() * 20, test.getBoardSize() * 20); frameRate(1); } //*************** DRAW FUNCTION ***************// void draw(){ background(255); smooth(); palette[0] = color(255,0,0); //RED palette[1] = color(0, 255, 0); //GREEN palette[2] = color(0, 0, 255); //BLUE palette[3] = color(0, 0, 0); //BLACK palette[4] = color(255, 165, 0); //ORANGE test.createRandomPieces(test.getBoardSize()); }