mardi 16 octobre 2018

Grid for a memory game in Java

I am just starting out coding and I want to make a grid for a memory game! So far i have made this. Although the idea is there i just can't get it to work like i want it just yet. Can any of you help me with this? Thanks!I want to make an array that holds all numbers that i have assigned in the board already. And then when the random number generator generates the same number for the third time it cuts off and generates a new number

          package beroepsproduct;

          import javax.swing.*;
          import java.awt.*; 
          import java.util.Arrays;
          import java.util.Random; 


         public class Forloopbord 
        {

         public static void MyGridLayout()
          {
          JFrame f; 
          f = new JFrame();
        int[] UitgNummers = new int[36];

        f.setLayout(new GridLayout(6,6));
        for(int x = 1; x <= 36; x++)
         {
        Random rand = new Random(); 
        int randNmr = rand.nextInt(18);



        for(int i = 0; i <=UitgNummers.length; i++)
        {
            if(UitgNummers[i] == randNmr)
            {
                randNmr = rand.nextInt(); 
            }
            else
            {
                JButton BtnPlaatjex = new JButton(""+randNmr);
                f.add(BtnPlaatjex);

                UitgNummers [x-1] = randNmr;   
            }


        }
            //while(UitgNummers[i] ==randNmr)
        //{

        //}



        }
        f.setLayout(new GridLayout(6,6)); 
        f.setSize(1000,1000);
        f.setVisible(true); 

        }    
        public static void main(String[] args)
       {
       MyGridLayout(); 
      }  


      }
    }




Aucun commentaire:

Enregistrer un commentaire