ビンゴのアルゴリズムを変更しました
配列にあらかじめ1から75までいれておいて
シャッフルするようにしました
しかし、終了後に動作が不安定になる不具合があります^^;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.util.Random;
public class Bingo extends Activity
implements View.OnClickListener {
private static Random rand = new Random();
private static int array[] = new int[75];
private static int no = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button)findViewById(R.id.Button01);
btn.setOnClickListener(this);
for(int i=0; i<75; i++){
array[i] = i+1;
}
shuffle();
TextView textView1 = (TextView)findViewById(R.id.TextView01);
textView1.setText("");
TextView textView2 = (TextView)findViewById(R.id.TextView02);
textView2.setText("");
TextView textView3 = (TextView)findViewById(R.id.TextView03);
textView3.setText("");
}
public static void shuffle(){
int tmp;
for(int i=74; i>0; i--){
int t = rand.nextInt(i); //0~iの中から適当に選ぶ
//選ばれた値と交換する
tmp = array[i];
array[i] = array[t];
array[t] = tmp;
}
}
public void onClick(View v) {
if (no < 75) {
TextView textView = (TextView)findViewById(R.id.TextView01);
textView.setTextSize(50);
textView.setText(Integer.toString(array[no]));
String out = "";
for(int i=0; i<=no; i++){
String s = String.format("%1$02d",array[i]);
if ((i+1)%10 == 0) {
out = out + s + ",\n";
} else {
out = out + s + ",";
}
}
TextView textView2 = (TextView)findViewById(R.id.TextView02);
textView2.setText(out);
no++;
} else {
TextView textView3 = (TextView)findViewById(R.id.TextView03);
textView3.setText("\nfinish!");
}
}
}
配列にあらかじめ1から75までいれておいて
シャッフルするようにしました
しかし、終了後に動作が不安定になる不具合があります^^;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.util.Random;
public class Bingo extends Activity
implements View.OnClickListener {
private static Random rand = new Random();
private static int array[] = new int[75];
private static int no = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button)findViewById(R.id.Button01);
btn.setOnClickListener(this);
for(int i=0; i<75; i++){
array[i] = i+1;
}
shuffle();
TextView textView1 = (TextView)findViewById(R.id.TextView01);
textView1.setText("");
TextView textView2 = (TextView)findViewById(R.id.TextView02);
textView2.setText("");
TextView textView3 = (TextView)findViewById(R.id.TextView03);
textView3.setText("");
}
public static void shuffle(){
int tmp;
for(int i=74; i>0; i--){
int t = rand.nextInt(i); //0~iの中から適当に選ぶ
//選ばれた値と交換する
tmp = array[i];
array[i] = array[t];
array[t] = tmp;
}
}
public void onClick(View v) {
if (no < 75) {
TextView textView = (TextView)findViewById(R.id.TextView01);
textView.setTextSize(50);
textView.setText(Integer.toString(array[no]));
String out = "";
for(int i=0; i<=no; i++){
String s = String.format("%1$02d",array[i]);
if ((i+1)%10 == 0) {
out = out + s + ",\n";
} else {
out = out + s + ",";
}
}
TextView textView2 = (TextView)findViewById(R.id.TextView02);
textView2.setText(out);
no++;
} else {
TextView textView3 = (TextView)findViewById(R.id.TextView03);
textView3.setText("\nfinish!");
}
}
}