Primer Botón Crear un mazo de cartas,
Segundo Botón barajarea las cartas
Tercer Botón repartir
Código :
package { import flash.display.MovieClip; import flash.events.Event; import flash.events.MouseEvent; import flash.text.TextFormat; import flash.text.TextFormatAlign; public class Main extends MovieClip { // This example code is designed to be easier to read and learn for non-OOP and non-AS3 coders. private var aButtonText: Array; private var aButtons: Array; private var aCardSuits: Array; private var aCardValues: Array; private var aDeck: Array; private var aTempDeck: Array; private var aHands: Array; private var iHandSize: int; private var iTotalHands: int; private var bDeckShowing: Boolean; function Main() { //trace("Main()"); aButtonText = new Array("CREATE DECK", "SHUFFLE DECK", "DEAL HANDS", "CLEAR HANDS"); aButtons = new Array(); aCardSuits = new Array("Spades", "Hearts", "Diamonds", "Clubs"); aCardValues = new Array("2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"); aDeck = new Array(); aTempDeck = new Array(); aHands = new Array(); iHandSize = 5; iTotalHands = 4; bDeckShowing = false; mcShowDeck.visible = false; mcShowHands.visible = false; fSetButtons(); } private function fCreateDeck(): void { var i: int = 0; for (i = 0; i < 52; i++) { var mcNew: McCard = new McCard(); fSetCardMC(mcNew, i); mcNew.scaleX = 0.25; mcNew.scaleY = 0.25; aDeck.push(mcNew); } mcShowDeck.visible = true; } private function fShowDeck(): void { //trace("fShowDeck()"); var i: int = 0; if (bDeckShowing) { for (i = 0; i < aDeck.length; i++) { mcShowDeck.mcCards.removeChild(aDeck[i]); } } for (i = 0; i < aDeck.length; i++) { mcShowDeck.mcCards.addChild(aDeck[i]); aDeck[i].x = (i * 16) + 10; aDeck[i].y = 30; } bDeckShowing = true; } private function fShuffleDeck(): void { // create a copy of aDeck, clear aDeck, randomly push cards into aDeck var iRandomIndex: int = 0; aTempDeck = aDeck; aDeck = []; while (aTempDeck.length > 0) { iRandomIndex = (Math.random() * aTempDeck.length); aDeck.push(aTempDeck[iRandomIndex]); aTempDeck.splice(iRandomIndex, 1); } } private function fDealHands(): void { //trace("fDealHands()"); var i: int = 0; var j: int = 0; var oTemp: Object; for (i = 0; i < iTotalHands; i++) { var aTemp: Array = new Array(); aHands.push(aTemp); mcShowHands["mcShowHand_" + i].tMain.text = "Hand " + i; } for (i = 0; i < iHandSize; i++) { for (j = 0; j < iTotalHands; j++) { oTemp = aDeck.pop(); mcShowHands["mcShowHand_" + j].addChildAt(oTemp, j); oTemp.x = (i * 16) + 10; oTemp.y = 30; aHands[j].push(oTemp); } } // sort the hands and reset their indexes (depths) for (i = 0; i < iTotalHands; i++) { aHands[i].sortOn(["iValue", "iSuit"], [Array.NUMERIC, Array.NUMERIC]); for (j = 0; j < iHandSize; j++) { oTemp = aHands[i][j]; mcShowHands["mcShowHand_" + i].setChildIndex(aHands[i][j], j); oTemp.x = (j * 24) + 10; oTemp.y = 30; } } mcShowHands.visible = true; } private function fClearHands(): void { //trace("fClearHands()"); var i: int = 0; var j: int = 0; for (i = 0; i < iHandSize; i++) { for (j = iTotalHands - 1; j >= 0; j--) { var oTemp: Object = aHands[j].pop(); mcShowHands["mcShowHand_" + j].removeChild(oTemp); aDeck.push(oTemp); mcShowDeck.mcCards.addChild(oTemp); oTemp.x = ((aDeck.length - 1) * 16) + 10; oTemp.y = 30; } } aHands = []; mcShowHands.visible = false; } private function fSetCardMC(oCard: McCard, iCardNumber: int): void { //trace("fCreateCardMC(" + iCardNumber + ")"); var i: int = 0; var j: int = 0; var iSuit: int = Math.floor(iCardNumber / aCardValues.length); var iValue: int = iCardNumber % aCardValues.length; oCard.iCardNo = iCardNumber; oCard.iSuit = iSuit; oCard.iValue = iValue; // top and bottom corner icon for (i = 0; i < 2; i++) { oCard.mcCardBack.visible = false; // as2 code: oCardMC.tValueTop.textColor = 0xCC0000; var tfCard: TextFormat = new TextFormat(); if (0 < iSuit && iSuit < 3) { tfCard.color = 0xCC0000; } else { tfCard.color = 0x000000; } for (j = 0; j < aCardSuits.length; j++) { oCard["mcCardValue_" + i].mcCardSuit["mcSuit_" + j].visible = false; } oCard["mcCardValue_" + i].mcCardSuit["mcSuit_" + iSuit].visible = true; oCard["mcCardValue_" + i].tMain.text = aCardValues[iValue]; oCard["mcCardValue_" + i].tMain.setTextFormat(tfCard); } } // ------------------- buttons private function fSetButtons(): void { var i: int = 0; var oButtonMC: Object; for (i = 0; i < aButtonText.length; i++) { oButtonMC = mcButtons["mcButton_" + i]; oButtonMC.tMain.text = aButtonText[i]; oButtonMC.button.addEventListener(MouseEvent.MOUSE_DOWN, fButtonPress); oButtonMC.button.addEventListener(MouseEvent.MOUSE_OVER, fButtonOver); oButtonMC.button.addEventListener(MouseEvent.MOUSE_OUT, fButtonOut); oButtonMC.mcBackOn.visible = false; oButtonMC.iButtonNo = i; if (i > 0) { fButtonEnable(oButtonMC, false); } aButtons.push(oButtonMC); } } private function fButtonOver(e: MouseEvent): void { var oButtonMC: Object = e.currentTarget.parent; oButtonMC.mcBackOn.visible = true; } private function fButtonOut(e: MouseEvent): void { var oButtonMC: Object = e.currentTarget.parent; oButtonMC.mcBackOn.visible = false; } private function fButtonEnable(oButtonMc: Object, bOn: Boolean): void { oButtonMc.button.visible = bOn; if (bOn) { oButtonMc.alpha = 1; } else { oButtonMc.alpha = 0.5; } } private function fButtonPress(e: MouseEvent): void { var iButtonNo: int = e.currentTarget.parent.iButtonNo; trace("fButtonPress(): " + iButtonNo); switch (iButtonNo) { case 0: fButtonEnable(aButtons[0], false); fButtonEnable(aButtons[1], true); fCreateDeck(); fShowDeck(); break; case 1: //fButtonEnable(aButtons[1],false); fButtonEnable(aButtons[2], true); fShuffleDeck(); fShowDeck(); break; case 2: fButtonEnable(aButtons[1], false); fButtonEnable(aButtons[2], false); fButtonEnable(aButtons[3], true); fDealHands(); break; case 3: fButtonEnable(aButtons[3], false); fButtonEnable(aButtons[1], true); fButtonEnable(aButtons[2], true); fClearHands(); break; } } } }
Mi duda es el la linea 40 que es la siguiente:
Código :
private function fCreateDeck(): void { var i: int = 0; for (i = 0; i < 52; i++) { var mcNew: McCard = new McCard(); // aquí fSetCardMC(mcNew, i); // y aquí mcNew.scaleX = 0.25; mcNew.scaleY = 0.25; aDeck.push(mcNew); } mcShowDeck.visible = true;
No logro entender esta parte
Código :
var mcNew: McCard = new McCard();
y esta
Código :
fSetCardMC(mcNew, i);
no entiendo lo que esta dentro del paréntesis y porque ponen la variable i