var cols: int = 4;

var rows: int = 4;

var totalCards: int = 16;

var matchesNeededToWin: int = totalCards * 0.5;

var matchesMade: int = 0;

var cardW: int = 100;

var cardH: int = 100;

var aCards: Array;

var aGrid: Array;

var aCardsFlipped: ArrayList;

var playerCanClick: boolean;

var playerHasWon: boolean = false;

 

function Start()

{

   

    playerCanClick = true;

    aCards = new Array();   

    aGrid = new Array();

    aCardsFlipped = new ArrayList();

    BuildDeck();

   

    for ( i=0; i<rows;i++)

    {

        aGrid[i] = new Array();

       

        for (var j: int=0; j <cols; j++)

        {

            var someNum: int = Random.Range (0,aCards.length);

            aGrid[i][j] = aCards[someNum]; 

            aCards.RemoveAt(someNum);

        }   

       

    }

}

 

 

class Card extends System.Object

{

    var isFaceUp: boolean  = false;

    var isMatched: boolean = false;

    var img: String;

   

    function Card(img: String)

    {

        this.img = img;

       

    }   

   

}

 

function OnGUI ()

{

    GUILayout.BeginArea (Rect(0,0,Screen.width, Screen.height));

    BuildGrid();

    GUILayout.EndArea();   

}

 

 

function BuildGrid()                               

{

    GUILayout.BeginVertical();

    GUILayout.FlexibleSpace();

    for (var i: int=0;i<rows;i++)

    {

        GUILayout.BeginHorizontal();

        GUILayout.FlexibleSpace();

        for (var j:int=0;j<cols; j++)

        {

            var card:Object = aGrid[i][j];

           

            if (GUILayout.Button(Resources.Load(card.img), GUILayout.Width(cardW)))

            {

                Debug.Log (card.img);   

            }   

           

        }

        GUILayout.FlexibleSpace();

        GUILayout.EndHorizontal(); 

       

    }

    GUILayout.FlexibleSpace();

    GUILayout.EndVertical();   

}

 

 

function BuildDeck()

{

    var totalRobots: int = 4;

    var card: Object;

   

    for (i=0; i<totalRobots; i++)

    {

        var aRobotParts: Array = ["Head","Arm","Leg"];

        for (j=0;j<2;j++)

        {

            var someNum: int = Random.Range (0,aRobotParts.length);

            var theMissingPart: String = aRobotParts [someNum];

           

            aRobotParts.RemoveAt(someNum);

           

            card = new Card ("robot" + (i+1) + "Missing" + theMissingPart);

            aCards.Add(card);

           

            card = new Card ("robot" + (i+1) + theMissingPart);

            aCards.Add(card);

        }   

    }