this is my numbers in an array int [] ids {1,2,3,4,5,6,7,8,9};
this is my an int [] result = {1,2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,24,27,28,30,32,35,36,40,42,45,48,49,54,56,63,64,63,72,81};
我用随机数字构建矩阵4/4,从一组id中随机选择。
5,2,3,7
3,2,3,9
7,3,3,4
4,5,3,2
矩阵中的这些数字我想安排乘法结果。
我使用矩阵的最多4个数字来做到这一点。 我不能允许,我将选择数字矩阵,我将无法从数组结果中排列结果。
例如。我使用值1绘制结果数组编号,并且矩阵没有任何值为1的数字。
如何防止我将绘制数字矩阵,我将无法安排结果数组的结果?
private int[] ids = {1,2,3,4,5,6,7,8,9};
private int total =1;
private static final int a=7;
private static final int b=7;
Random rand = new Random();
int tablica[] = {1,2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,24,27,28,30,32,35,36,40,42,45,48,49,54,56,63,64,63,72,81};
int i = tablica[rand.nextInt(36)];
private void createLayoutDynamically() {
won = (TableLayout)findViewById(R.id.won);
for ( int qq = 1; qq < a; qq++) {
TableRow tableRow = new TableRow(this);
won.addView(tableRow);
for ( int q = 1; q < b; q++) {
myButton = new Button(this);
if (q%2 == 0) {
myButton.setBackground(getResources().getDrawable(R.drawable.klik_dwa));
}
else
myButton.setBackground(getResources().getDrawable(R.drawable.klik_jeden));
final int number = new Random().nextInt(9);
final int rand = (ids[number]);
myButton.setText(""+rand);
myButton.setTypeface(type);
myButton.setId(rand);
myButton.setTag(rand);
buttons[q][qq]=myButton;
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
String mnozenie =" x ";
dzialanie.append(v.getTag().toString()+mnozenie);
int buttonValue = (int)v.getTag();
total *= buttonValue;
score.setText(String.valueOf(total));
myButton.findViewWithTag(v.getTag());
if(v.getId()==1)
{
counter*=1;
}
if(v.isClickable()){
v.setVisibility(View.INVISIBLE);
}
for (int i=1;i<buttons.length;i++) {
for (int j=1;j<buttons[i].length;j++) {
}
}
String score1 = score.getText().toString();
int a;
a = Integer.parseInt(score1);
String tylemabyc1 = tylemabyc.getText().toString();
int b;
b = Integer.parseInt(tylemabyc1);
if(counter2>3){
counter2=0;
total = 1;
score.setText(null);
dzialanie.setText(null);
oklubnie.setText("Tylko trzy liczby mozęsz użyć");
for (int i=1;i<buttons.length;i++) {
for (int j=1;j<buttons[i].length;j++) {
Button btn = buttons[i][j];
if (btn.getVisibility() == View.INVISIBLE) {
btn.setVisibility(View.VISIBLE);
}
}
}
new CountDownTimer(500, 100) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
oklubnie.setText("");
}
}.start();
}
if(a>b)
{
counter2=0;
total = 1;
score.setText(null);
counter-=5;
wynik.setText(""+counter);
dzialanie.setText(null);
wynik.setVisibility(View.INVISIBLE);
wynikk.setBackgroundResource(R.drawable.zle_bez_napisu);
for (int i=1;i<buttons.length;i++) {
for (int j=1;j<buttons[i].length;j++) {
Button btn = buttons[i][j];
if (btn.getVisibility() == View.INVISIBLE) {
btn.setVisibility(View.VISIBLE);
}
}
}
new CountDownTimer(500, 100) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
wynikk.setBackgroundResource(R.drawable.czas_punkty_bez_napisu);
wynik.setVisibility(View.VISIBLE);
}
}.start();
}
new CountDownTimer(500, 100) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
if(counter2<=3 &((String) score.getText()).equalsIgnoreCase((String) tylemabyc.getText()))
{
counter2=0;
wynik.setVisibility(View.INVISIBLE);
wynikk.setBackgroundResource(R.drawable.dobrze_bez_napisu);
new CountDownTimer(500, 100) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
wynikk.setBackgroundResource(R.drawable.czas_punkty_bez_napisu);
wynik.setVisibility(View.VISIBLE);
}
}.start();
for (int i=1;i<buttons.length;i++) {
for (int j=1;j<buttons[i].length;j++) {
Button btn = buttons[i][j];
if (btn.getVisibility() == View.INVISIBLE){
btn.setVisibility(View.VISIBLE);
btn.setTypeface(type);
int number = new Random().nextInt(9);
int rand = (ids[number]);
btn.setText(""+rand);
btn.setId(rand);
btn.setTag(rand);
btn.setTextColor(Color.WHITE);
btn.setTextSize(25);
if (i%2 == 0) {
btn.setBackground(getResources().getDrawable(R.drawable.klik_dwa));
}
else
btn.setBackground(getResources().getDrawable(R.drawable.klik_jeden));
}
}
}
String razy= dzialanie.getText().toString();
if(razy.length()>4)
counter+=20;
else if(razy.length()>3)
counter+=10;
else
counter+=5;
dzialanie.setText(null);
score.setText(null);
Random rand = new Random();
int tablica[] = {1,2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,24,27,28,30,32,35,36,40,42,45,48,49,54,56,63,64,63,72,81};
int i = tablica[rand.nextInt(36)];
tylemabyc.setText(Integer.toString(i));
total = 1;
wynik.setText(""+counter);
}
}
}.start();
}
});
tableRow.addView(myButton);
}
}
}