Skip to content

Instantly share code, notes, and snippets.

@mattiaferigutti
Last active April 26, 2017 18:20
Show Gist options
  • Save mattiaferigutti/e3807a30f68f5f991425e74b929afe84 to your computer and use it in GitHub Desktop.
Save mattiaferigutti/e3807a30f68f5f991425e74b929afe84 to your computer and use it in GitHub Desktop.
inizializzazione tessere del dominio
import java.util.Random;
/**
* Created by feriguttim on 20/04/2017.
*/
public class Domino
{
private static final int[][] pedine = new int[49][2];
int[] random = new int[]{5, 6, 7, 8, 9, 10};
public static int[][] getPedine() {
return pedine;
}
public void inizializzaTessere()
{
System.out.println("Inizializzazione pedine: ");
int a, b;
a = -1; b = -1;
for (int i=0; i<pedine.length; i++)
{
a++;
if (i%7 == 0 && i!= 0)
a = a-7;
pedine[i][0] = a;
if (i%7 == 0)
b++;
pedine[i][1] = b;
}
for (int c=0; c<pedine.length; c++)
{
System.out.print( pedine[c][0]);
System.out.println(" " + pedine[c][1]);
}
//System.out.println("\npedine " + pedine[20][1]);
}
public void estrazionePedineRandom()
{
Random rand = new Random();
/*int casuale = rand.nextInt(random.length);
System.out.println(random[casuale]);*/
for (int i=0; i<pedine.length; i++)
{
//System.out.println(i);
int casuale = rand.nextInt(pedine.length);
if(pedine[casuale][0] == 7)
i--;
else {
if (i<pedine.length/2) {
if (i==0)
System.out.println("\nPrima tessera sul tavolo:");
if (i==1)
System.out.println("\nGiocatore 1:");
System.out.print(pedine[casuale][0]);
System.out.println(" " + pedine[casuale][1]);
pedine[casuale][0] = 7;
}
else {
if (i==(pedine.length/2)+1)
System.out.println("\nGiocatore 2:");
System.out.print(pedine[casuale][0]);
System.out.println(" " + pedine[casuale][1]);
pedine[casuale][0] = 7;
}
}
}
/*boolean contains = IntStream.of(random).anyMatch(x -> x == 9);
System.out.println(contains);*/
}
public void gioca(final int tessere[][], int casuale)
{
}
}
/**
* Created by Mattia on 19/04/2017.
*/
public class ProgDomino
{
public static void main(String... args)
{
Domino domino = new Domino();
domino.inizializzaTessere();
domino.estrazionePedineRandom();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment