var customSkin :GUISkin;
var cols :int = 4; //the number of columns in the card grid
var rows :int = 4; // the number of rows in the card grid
var totalCards :int = cols * rows;
var matchesNeededToWin :int = totalCards * 0.5;
var matchesMade :int = 0;
var cardW :int = 100;
var cardH :int = 100;
var aCards :Array; // we’ll store all the cards in this array.
var aGrid :Array ; // keeps track of shuffled/delt cards
var aCardsFlipped :ArrayList; // stores the two cards that are flipped over
var playerCanClick :boolean = false; // so we can turn off ability to click when we want
var playerHasWon :boolean = false; //store whether or notplayer has won
function Start ()
{
playerCanClick = true;
//Initialize the arrays as empty lists:
aCards = new Array();
aGrid = new Array();
aCardsFlipped = new ArrayList ();
BuildDeck();
for (i =0; i < rows; i++)
{
aGrid = new Array (); // create a new, empty array at index i
- for (var j:int = 0; j < cols; j ++)*
- {*
- var someNum:int = Random.Range (0, aCards.length);*
_ aGrid [j] = aCards[someNum];_
* aCards.RemoveAt(someNum);*
* }*
* }*
}
function OnGUI ()
{
* GUILayout.BeginArea (Rect (0, 0, Screen.width, Screen.height));*
* BuildGrid ();*
* GUILayout.EndArea ();*
* //print (“building grid”);*
}
class Card extends System.Object
{
* var isFaceUp :boolean = false;*
* var isMatched :boolean = false;*
* var img :String;*
* var id:int;*
* function Card (img:String, id:int)*
* {*
* this.img = img;*
* this.id = id;*
* }*
}
function BuildGrid ()
{
* GUILayout.BeginVertical();*
* GUILayout.FlexibleSpace();*
* for (i = 0; i < rows; i ++)*
* {*
* GUILayout.BeginHorizontal ();*
* GUILayout.FlexibleSpace();*
* for (j = 0; j < cols; j ++)*
* {*
_ var card :Object = aGrid [j];
* var img:String;*_
* if (card.isMatched)*
* {*
* img = “blank”;*
* print (“Score One!!”);*
* }*
* else*
* {*
* if (card.isFaceUp)*
* {*
* img = card.img;*
* }*
* else*
* {*
* img = “wrench”;*
* }*
* }*
* GUI.enabled = !card.isMatched;*
* if (GUILayout.Button (Resources.Load(img), GUILayout.Width(cardW)))*
* {*
* if (playerCanClick)*
* {*
* FlipCardFaceUp(card);*
* }*
* //Debug.Log (card.img);*
* }*
* GUI.enabled = true;*
* }*
* GUILayout.FlexibleSpace();*
* GUILayout.EndHorizontal ();*
* }*
* GUILayout.FlexibleSpace();*
* GUILayout.EndVertical ();*
}
function BuildDeck ()
{
* var totalRobots :int = 4; //we’ve got four robots to work with*
* var card :Object; //this stores a reference to a card*
* var id:int = 0;*
* 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, id);*
* aCards.Add(card);*
* card = new Card(“robot” + (i+1) + theMissingPart, id);*
* aCards.Add(card);*
* id ++;*
* }*
* }*
}
function FlipCardFaceUp (card:Card)
{
* card.isFaceUp = true;*
* if (aCardsFlipped.IndexOf(card) < 0)*
* {*
* aCardsFlipped.Add (card);*
* if (aCardsFlipped.Count == 2)*
* {*
* playerCanClick = false;*
* yield WaitForSeconds (1);*
* if (aCardsFlipped[0] .id == aCardsFlipped[1])*
* {*
* //Match!!!*
* print (“Match Match Match”);*
* aCardsFlipped [0] .isMatched = true;*
* aCardsFlipped [1] .isMatched = true;*
* }*
* else*
* {*
* aCardsFlipped [0] .isFaceUp = false;*
* aCardsFlipped [1] .isFaceUp = false;*
* }*
* aCardsFlipped = new ArrayList();*
* playerCanClick = true;*
* }*
* }*
}
[/QUOTE]