0% found this document useful (0 votes)
8 views1 page

Runnable Example with Dice Logic

The document defines a Runnable class that implements the Runnable interface. The run method contains a for loop that iterates 3 times. Within each iteration, it posts a Runnable to the handler that simulates rolling dice and calculating the sum. It checks the sum every 3 iterations to determine if the player won, lost, or should keep rolling.

Uploaded by

Francisco Javier
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Runnable Example with Dice Logic

The document defines a Runnable class that implements the Runnable interface. The run method contains a for loop that iterates 3 times. Within each iteration, it posts a Runnable to the handler that simulates rolling dice and calculating the sum. It checks the sum every 3 iterations to determine if the player won, lost, or should keep rolling.

Uploaded by

Francisco Javier
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

public class ejemploRunnable implements Runnable{

@Override
public void run() {
for (int i = 0; i < 3; i++) {
[Link](new Runnable() {
@Override
public void run() {

r1=[Link](6);
r2=[Link](6);
[Link](imgs[r2]);
[Link](imgs[r1]);
suma = (r1+1)+(r2+1);
cont++;
if(cont%3==0){
if(suma==7||suma==11){
//[Link]([Link], "Haz gando", Toast.LENGTH_SHORT).show();
}else if (suma==2||suma==3||suma==12){
//[Link]([Link], "Haz perdido",
Toast.LENGTH_SHORT).show();
}else{
//[Link](getBaseContext(),"Sigue tirando",Toast.LENGTH_SHORT).show();
}
[Link]([Link], ""+suma, Toast.LENGTH_SHORT).show();
}

});
Log.d(TAG,"Hilo inciado "+i);
try {
[Link](1000);
} catch (InterruptedException e) {
[Link]();
}

}
}

You might also like