
/*
Online Java - IDE, Code Editor, Compiler

Online Java is a quick and easy tool that helps you to build, compile, test your programs online.
*/


import java.util.*;

public class Main
{
    public static void main(String[] args) {
        System.out.println("Welcome to Online IDE!! Happy Coding :)");
        
        int numberPairs=0;
        
        System.out.println("*** WELCOME TO MEMORY GAME *** - Please select size of matrix:");
        
        
        Scanner scanner = new Scanner (System.in);
        System.out.println("Enter width:");
        int length = scanner.nextInt();
        
        System.out.println("Enter length:");
        
        
        int width =  scanner.nextInt();
        numberPairs = (length * width)/2;
        
         System.out.println("Number of pairs: " + numberPairs);
        
        
        int [] test = new int []{1,2,3};
        
        ArrayList <int[]> board = new ArrayList<>();
        
        
        playMemoryGame mg = new playMemoryGame(numberPairs, board, width, length);
        
    }
}

interface memoryGame
{
    void generateNumbers();
    void flipCard();
    void pairFound();
    void noPair();
    void timeLeft();   // not sure how this will be implemented
    void fillRow();
    void fillTable();
    
}

class playMemoryGame implements memoryGame
{
    
    
    
     
     // currently enum is not used.. was contemplated adding value of the enum into the set
     // however not sure if it serves any real value.....
     
     int numberPairs; 
     ArrayList<int[]> board; 
     int width;
     int length;
     
     
     int number;
     int i=0;
     int [] fillBoard = new int [width-1];
        
    //Set<Integer> generatedNumbers = new HashSet<Integer>();
    List <Integer> myList = new ArrayList<Integer>();
     
    //generateNumbers();
    
     public playMemoryGame(int numberPairs, ArrayList<int[]> board, int width, int length)
    {
        this.numberPairs=numberPairs;
     this.board=board;
     this.width=width;
     this.length=length;
    }
    
    
     
     public void generateNumbers()
     {
          do
        {
        
        Random rnd = new Random();
        
        number=rnd.nextInt((numberPairs));  // this ensures with 9 pairs.... it generates random number 0-8 and not 0-9
        
        
        System.out.println("Following number will be added into memory games:" + number );
        
        
        if (!myList.contains(number)) 
        { 
            myList.add(number); }
        
        
        }while (myList.size()<numberPairs);  
        
        
           Iterator it = myList.iterator();
        
        
        
        while (it.hasNext())   // this is now going through generated numbers of the Set
        {
            // it has to fill board one row at a time and then add them onto arrayList 
            fillBoard[i] = (int)it.next();
            
            System.out.println("This should be presented random order: " + fillBoard[i]);
            // for some instance, it is showing them in order even though Set should remain unordered.
            // hence a list has been used instead
            
            
            System.out.println("value:" + fillBoard[i]);
            i++;
            
            if (i<=width-1)  // this forces a newline of width
            {
                i=0;
            }
            board.add(fillBoard);
            
        }
        
        
        
        
        
        
        
         
     }
     
     
     
     public void fillRow()
     {
         
     }
     
     public void fillTable()
     {
         
     }
    
    public void timeLeft()
    {
    }
    
    public void noPair()
    {
    }
    
    public void pairFound()
    {
    }
    
    public void flipCard()
    {
    }
}

/*
   enum cards
{
    
    ZERO(0), ONE(1), TWO(2), THREE(3), FOUR(4), FIVE(5), SIX(6), SEVEN(7), EIGHT(8), NINE(9), TEN(10);
    
    final int value;
    
    cards (int value)
    {
        this.value=value;
    }
}
*/



/*
System.out.println("Testing area");
        // this is checking to see if numbers store are returned correctly
        int []testing = new int[]{5,7,4};
        board.add(testing);
        
        
        for (int m: board.get(0))
        {
            System.out.println(m);
            
        }
*/