I have to set it up into three files, Card, Deck, and CDtester.
Now, the only problems that im having are with my CDtester file
Getting errors like this "1136: Incorrect number of arguments. Expected 1."
this "1067: Implicit coercion of a value of type void to an unrelated type Card."
and this "1137: Incorrect number of arguments. Expected no more than 0."
If anyone could reply very soon, that would be great.
Thanks!
--------------------------------CARD CODE-------------------------------
package {
public class Card {
//PROPERTIES
protected var suit:int;
protected var rank:int;
protected var facing:Boolean;
const SUIT_NAMES:Array=new Array("Hearts","Diamonds","Clubs","Spades");
const RANK_NAMES:Array = new Array("Two", "Three", "Four", "Five",
"Six", "Seven", "Eight", "Nine", "Ten",
"Jack", "Queen", "King", "Ace");
//CONSTUCTOR
public function Card(s:int,r:int,f:Boolean) {
this.suit=s;
this.rank=r;
this.facing=f;
}
public function getSuitName(s:int):String {
return SUIT_NAMES[s - 1];
}
public function getRankName(r:int):String {
return RANK_NAMES[r - 1];
}
//behaviorS/FUNCTIONS
//flip
public function flip():void {
if (this.facing==false) {
this.facing==true;
}
}
public function toString(r:int, s:int){
//check if card is facing is true
if (this.facing==false) {
trace("Card is not flipped");
} else {
trace("Card is the "+r+" of "+s);
}
}
public function isValid(s:int, r:int){
if ((s>=0 && s>=4) && (r>=0 && r>=13)) {
return true;
} else {
return false;
}
}
//GETTERS
public function getSuit():int {
return this.suit;
}
public function getRank():int {
return this.rank;
}
public function getFacing():Boolean {
return this.facing;
}
}
}
----------------------------------------DECK CODE--------------------------------------
package {
public class Deck {
//PROPERTIES
protected var cards:Array;
protected var topspot:int;
protected var e:Card;
protected var facing = e.getFacing;
protected var suit = e.getSuit;
protected var rank = e.getRank;
//CONSTRUCTOR
public function Deck() {
this.cards=new Array(52);
this.topspot=cards[51];
}
//behaviorS/FUNCTIONS
//print
public function print():void {
for (var i:int=0; i<52; i++) {
trace(cards[i]);
}
}
//shuffle
public function shuffle(startIndex:int=0,endIndex:int=0):void {
if (endIndex==0) {
endIndex=cards.length-1;
}
for (var i:int=endIndex; i>startIndex; i--) {
var randomNumber:int=Math.floor(Math.random()*endIndex)+startIndex;
var tmp:* =cards[i];
cards[i]=cards[randomNumber];
cards[randomNumber]=tmp;
}
}
//add top/bottom
public function addCardToTop():void {
var tmp:* =cards[51];
cards[51]=cards[0];
cards[0]=tmp;
}
public function addCardToBottom():void {
var tmp2:* =cards[0];
cards[0]=cards[51];
cards[51]=tmp2;
}
//countcards
/*public function countCards(c):int {
}*/
//draw top/bottom
public function drawTopCard():void {
trace(cards[51]);
this.topspot=cards[50];
}
public function drawBottomCard():void {
trace(cards[0]);
this.topspot=cards[50];
}
//validated
/*public function isValid(e:Card):Boolean {
this.suit+=e.getSuit();
this.rank+=e.getRank();
}*/
//flipAll
public function flipAll(e:Card):void {
/*for (var i:int = 0; i < 52; i++) {
if (cards[i].facing=false) {
cards[i].facing=true;
}
}*/
this.facing+=e.getFacing();
cards.forEach(this.facing=true);
}
public function equals(e:Card):void {
this.rank+=e.getSuit();
this.rank+=e.getRank();
}
//GETTERS
public function getCards():Array{
return this.cards;
}
public function getTopspot():int {
return this.topspot;
}
}
}
--------------------------------------CDTESTER CODE---------------------------------
package {
import flash.events.*;
import flash.display.*;
import flash.ui.*;
public class CDtester extends MovieClip {
var input="";
var testDeck:Deck = new Deck();
var testCard:Card=new Card(-1,-1,false);
public function CDtester() {
this.stage.addEventListener(KeyboardEvent.KEY_DOWN, inputKey);
this.startMenu();
}
public function startMenu():void {
trace("[=======================]");
trace("Choose an option by hitting the corresponding number");
trace("1- Make a Deck");
trace("2- Shuffle");
trace("3- Flip deck");
trace("4- Print Deck");
trace("5- Draw top card");
trace("6- Draw bottom card");
trace("7- Add card to top");
trace("8- Add card to bottom");
trace("9- Check if deck is valid");
trace("0- Count remaining cards");
trace("[=======================]");
}
public function inputKey(e:KeyboardEvent) {
if (e.keyCode==13) {
var inputnum=parseInt(input);
switch (inputnum) {
case 1 :
trace("Making a new deck...");
testDeck = new Deck();
break;
case 2 :
trace("Shuffling deck...");
testDeck.shuffle();
break;
case 3 :
trace("Flipping cards...");
testDeck.flipAll();
break;
case 4 :
trace("");
testDeck.print();
break;
case 5 :
testCard=testDeck.drawTopCard();
trace(testCard.toString());
testCard.flip();
trace("You drew"+testCard.toString());
testCard.flip();
break;
case 6 :
testCard=testDeck.drawBottomCard();
trace(testCard.toString());
testCard.flip();
trace("You drew"+testCard.toString());
testCard.flip();
break;
case 7 :
trace("Adding "+testCard.toString() +" to the top...");
testDeck.addCardToTop(testCard);
break;
case 8 :
trace("Adding "+testCard.toString() +" to the bottom...");
testDeck.addCardToBottom(testCard);
break;
/*case 9 :
if (testDeck.isValid()) {
trace("Deck is real.");
} else {
trace("Deck is fake!!");
}
break;*/
/*case 0 :
trace("There are "+testDeck.countCards()+ " cards left.");
break;*/
default :
trace("Enter an option between 0-9.");
}
input="";
this.startMenu();
} else {
input+=String.fromCharCode(e.charCode);
}
}
}
}

New Topic/Question
Reply


MultiQuote



|