I'm making a rubik's cube simulator for my science fair project, and I'm having some trouble. This code is supposed to randomize the cube by setting different color values in the sideValues[]
array. It's not that complicated, yet it always freezes my computer. (By the way, method1
,method2
, and method 3
are JLabels
, the counter integers are to make sure that there's no more than 9 pieces per color, drawAndButtons is the JPanel
the cube is shown on, and cubeSpace is the JPanel
drawAndButtons is on.)
method1.setForeground(Color.red);
method2.setForeground(Color.black);
method3.setForeground(Color.black);
for(int h = 1; h <= 54; h++)
{
do
{
transfer = generator.nextInt(6) + 1;
switch(transfer)
{
case 1:
numy++;
case 2:
numb++;
case 3:
numo++;
case 4:
numg++;
case 5:
numr++;
case 6:
numw++;
default:
}
if(numy > 9 || numb > 9 || numo > 9 || numg > 9 || numr > 9 || numw > 9)
{
rightAmount = false;
switch(transfer)
{
case 1:
numy--;
case 2:
numb--;
case 3:
numo--;
case 4:
numg--;
case 5:
numr--;
case 6:
numw--;
default:
}
}
else
{
sideValues[h] = transfer;
rightAmount = true;
}
}while(rightAmount == false);
}
drawAndButtons.add(new graphics());
cubeSpace.repaint();
methodValue = 3;
numy = 0;
numb = 0;
numo = 0;
numg = 0;
numr = 0;
numw = 0;
}