All pastes #805981 Raw Edit

random labrynth items

public java v1 · immutable
·published 2007-12-04 21:05 UTC
rendered paste body
for (int i = 1; i<itemAmount+1; i++) {//place items	do{		leaveLoop=true;		randX = (int)(Math.random()*6);//randomize x and y variables		randY = (int)(Math.random()*6);		for (int j = 1; j<i-1; j++) {//check to make sure its not on the same place as previous items or bases			if(itemLabel[j].getX() == randX*tileSize+XEdgeInset+(tileSize/3)			&& itemLabel[j].getY() == randY*tileSize+YEdgeInset+(tileSize/3)){ //make sure not same x & y as a previous item				leaveLoop = false;//if so, dont leave the loop				//System.out.println(itemImage[i].getDescription()+" was at the same as "+itemImage[j].getDescription());			}			if(randX == 0 && randY == 0 || randX == 0 && randY == boardSize-1			|| randX == boardSize-1 && randY == 0 || randX == boardSize-1 && randY == boardSize -1){ //make sure its not the same loc as any corner				leaveLoop = false;//if so, dont leave the loop				//System.out.println("tried to place "+itemImage[i].getDescription()+" on a base.");			}		}	}while (!leaveLoop);	itemLabel[i] = new JLabel(itemImage[i]);	itemLabel[i].setBounds(0,0,itemImage[i].getIconHeight(), itemImage[i].getIconWidth());	itemLabel[i].setForeground(Color.white);	itemLabel[i].setLocation(randX*tileSize+XEdgeInset+(tileSize/3),randY*tileSize+YEdgeInset+(tileSize/3));	mainFrame.add(itemLabel[i], 0);}