lellimecnar
09-23-2009, 02:07 AM
Ok, I am trying to make a nice card game called Nert. It's very similar to Solitaire, except that it is played with multiple players. Each player has their own deck of Rook cards (56 cards, 4 colors, 14 in each color). You start out with a stack of 13 cards called your Nert pile. Next to it are 4 individual cards. The rest of the deck is held in the player's hand, and three cards are drawn at a time, much like the stack in Solitaire. Players can each start a stack in the middle of the playing field by placing out a "1" of any color, just like you would place an Ace in Solitaire. Other players can add to the same-color stack which are in ascending sequential order. The object of the game is to earn points by placing as many of your cards as possible out into the playing field. The game is over when a player uses all 13 cards in their Nert pile. Players who still have cards in their Nert pile must double the number of cards and subtract it from the number of cards out in the field to calculate their score.
So, I found a good solitaire .fla file for download and I'm trying to manipulate it to work with this game. However, the system used in ActionScript is rather confusing, and not very sensible. If someone could go through all of the code in the .fla file and write in some comments to explain what each line and each variable and number are doing, that would be VERY helpful. Thank you!!!
.fla file can be downloaded from filehosting.org (http://www.filehosting.org/file/details/61013/solitaire.fla) or filedropper.com (http://www.filedropper.com/solitaire).
despisedIcon
09-23-2009, 02:09 AM
If someone could go through all of the code in the .fla file and write in some comments to explain what each line and each variable and number are doing, that would be VERY helpful..
How about YOU go through the code first, and ask specific questions about the parts YOU don't understand?
lellimecnar
09-23-2009, 02:26 AM
I've gone through it several times, and I have no idea what all of the numbers and variables are supposed to be. It seems that whoever made it decided to just use random letters and stuff. Some parts are commented well, but others don't make any sense.
lordofduct
09-23-2009, 02:27 AM
How about YOU go through the code first, and ask specific questions about the parts YOU don't understand?
you tell em' despisedIcon
@OP - that's a bit much to be asking of us. You're a new comer and you ask us to take up a pretty hefty project. It's not like I or anyone could answer that in a few minutes. I make around 25 dollars an hour, if you want to pay me sure... but come on now. Do you work for free???
lellimecnar
09-23-2009, 02:29 AM
Alright, fair enough... How about I just past parts of the code that I don't understand? Could you help me understand it then?
lellimecnar
09-23-2009, 02:44 AM
Here's some of the ActionScript for the main part of the game... I have added some notes to point out what doesn't make any sense to me. I'm sorry. I guess I should have done this in the first place. I just wanted to establish the issue first.
//put all the cards in an array
...What do "i" and "j" and "c" stand for?
for (i=0; i<13; i++) {
for (j=0; j<4; j++) {
allcards[i,j] = "c"+order1[i]+order2[j];
cardslength = cards.push(allcards[i,j]);
alllength = all.push(allcards[i,j]);
}
}
//select background of the cards
function selectBackground(n) {
lab = n;
for (i=0; i<52; i++) {
eval(all[i]).cb.gotoAndStop(n);
}
}
//restart
function restart() {
for (i=0; i<52; i++) {
eval(all[i]).removeMovieClip();
}
gotoAndPlay(4);
}
//hand out all the cards for everyone randomly
...What does "cardDepth" mean?
function GetCards(forwho,num,cardDepth) {
var card = new Array();
var myCards=new Array();
var myCardsLength=0;
for (var i=0; i<num; i++) {
var n = random(cardslength);
card[i] = cards[n];
cards.splice( n, 1 );
myCardsLength = myCards.push(card[i]);
cardslength = cards.length;
attachMovie(card[i],card[i], cardDepth );
cardDepth = cardDepth+1;
var a = eval(card[i]);
var b = eval(forwho);
with (a) {
if (b==a1) {
_x=b._x;
_y=b._y;
gotoAndStop(20);
cb.gotoAndStop(lab);
} else {
_x=b._x;
_y=b._y+4*i;
if (i<num-1) {
gotoAndStop(20);
cb.gotoAndStop(lab);
} else {
gotoAndStop(1);
}
}
}
}
return myCards;
}
//get cards
...d1-d4 are the column cards next to the nert pile. a1 and a2 are for the draw 3 pile, and b1-b12 are for the stacks in the playing field
d1Cards=GetCards(d1,1,1);
for (i=0; i<1; i++) {
eval("o"+d1Cards[i]) = {name:d1Cards[i], group:'d1Cards', order:i,depth:1+i};
}
d2Cards=GetCards(d2,1,21);
for (i=0; i<1; i++) {
eval("o"+d2Cards[i]) = {name:d2Cards[i], group:'d2Cards', order:i,depth:21+i};
}
d3Cards=GetCards(d3,1,41);
for (i=0; i<1; i++) {
eval("o"+d3Cards[i]) = {name:d3Cards[i], group:'d3Cards', order:i,depth:41+i};
}
d4Cards=GetCards(d4,1,61);
for (i=0; i<1; i++) {
eval("o"+d4Cards[i]) = {name:d4Cards[i], group:'d4Cards', order:i,depth:61+i};
}
nertCards=GetCards(nert,13,81);
for (i=0; i<13; i++) {
eval("o"+nertCards[i]) = {name:nertCards[i], group:'nertCards', order:i,depth:81+i};
}
/*
d6Cards=GetCards(d6,6,101);
for (i=0; i<6; i++) {
eval("o"+d6Cards[i]) = {name:d6Cards[i], group:'d6Cards', order:i,depth:101+i};
}
d7Cards=GetCards(d7,7,121);
for (i=0; i<7; i++) {
eval("o"+d7Cards[i]) = {name:d7Cards[i], group:'d7Cards', order:i,depth:121+i};
}*/
a1Cards=GetCards(a1,39,141);
for (i=0; i<39; i++) {
eval("o"+a1Cards[i]) = {name:a1Cards[i], group:'a1Cards', order:i,depth:141+i};
}
a2Cards=new Array();
//a2Cards:{ name:b2Cards[i],group:'a2Cards',order:i,depth:171+i }
b1Cards=new Array();
//b1Cards:{ name:b1Cards[i],group:'b1Cards',order:i,depth:201+i }
b2Cards=new Array();
//b2Cards:{ name:b2Cards[i],group:'b2Cards',order:i,depth:221+i }
b3Cards=new Array();
//b3Cards:{ name:b3Cards[i],group:'b3Cards',order:i,depth:241+i }
b4Cards=new Array();
//b4Cards:{ name:b4Cards[i],group:'b4Cards',order:i,depth:261+i }
b5Cards=new Array();
b6Cards=new Array();
b7Cards=new Array();
b8Cards=new Array();
b9Cards=new Array();
b10Cards=new Array();
b11Cards=new Array();
b12Cards=new Array();
//a set of blank MCs for swapDepths
...I don't understand what "depths" mean
swapCards=new Array();
for (i=301; i<=313; i++) {
attachMovie( "deep", "top"+i, i );
swapCardsLength = swapCards.push("top"+i);
}
//when click,swap them to the top so that we can see them all
function swap(name) {
o = eval("o"+name);
var g=eval(o.group);
for (i=o.order,j=0; i<g.length; i++,j++) {
eval(g[i]).swapDepths(eval(swapCards[j]));
}
}
//* response the press and drag Event of every card
function pressEvent(name) {
swap(name);
attachMovie( "dragMC", "dragCards", 0);
}
//* response the release Event of every card
function releaseEvent(name,x,y) {
swap(name);
a = eval(name);
detect = eval("o"+name).group;
//** if the card is "1"
if (name.substring(1,3)=="01") {
//*** release on the top and drop succeeded
//we must put the card "1" onto the top first
//because the top is empty , we must write the script individually
for (i=1; i<=4; i++) {
var b=eval("b"+i);
var c="b"+i+"Cards";
var p=eval("b"+i+"Cards");
if (a.hitTest(b) && p.length==0) {
a._x=b._x;
a._y=b._y;
p.push(name);
eval(o.group).pop(name);
o.group=c;
o.order=0;
o.depth=181+20*i;
attachMovie( "deep", "temp", 181+20*i );
eval(name).swapDepths(temp);
temp.removeMovieClip();
break;
}
}
//*** release on the bottom and drop succeeded
bottom(name);
//*** release and drop target failed , then put the cards back
other(detect);
//** if the card is "K"
} else if (name.substring(1,3)=="13") {
//*** release on the top and drop succeeded
top(name);
//*** release on the bottom and drop succeeded
//when the bottom is empty , no cards can put to there except "K"
...Except I want to be able to put ANY card down on a blank column, but I can't figure out what controls that.
//so we also must write the script individually
for (i=1; i<=7; i++) {
var b=eval("d"+i);
var c="d"+i+"Cards";
var p=eval("d"+i+"Cards");
var s=p.length;
if (a.hitTest(b) && p.length==0) {
for (k=o.order,j=0; k<eval(o.group).length; k++,j++) {
d=eval(eval(o.group)[k]);
d._x=b._x;
d._y=b._y+15*j;
}
for (k=o.order; k<eval(o.group).length; k++) {
p.push(eval(o.group)[k]);
}
eval(o.group).splice(o.order,eval(o.group).length-o.order);
for (k=s; k<p.length; k++) {
var h=20*i-19;
eval("o"+p[k]).group=c;
eval("o"+p[k]).order=k;
attachMovie( "deep", "temp"+k, h+k );
eval(p[k]).swapDepths(eval("temp"+k));
eval("o"+p[k]).depth=h+k;
eval("temp"+k).removeMovieClip();
}
break;
}
}
//*** release and drop target failed , then put the cards back
other(detect);
//** the other cards
} else {
//*** release on the top and drop succeeded
top(name);
//*** release on the bottom and drop succeeded
bottom(name);
//*** release and drop target failed , then put the cards back
other(detect);
}
dragCards.removeMovieClip();
if (o.group.substring(0,1)!="b" && eval(o.group).length==o.order+1) {
a.play();
}
//the end
end();
}
//*** release on the top and drop succeeded
function top(name) {
for (i=1; i<=4; i++) {
var c="b"+i+"Cards";
var p=eval("b"+i+"Cards");
var b=p[p.length-1];
if (p.length>0 && a.hitTest(eval(b)) && name.substring(1,3)-b.substring(1,3)==1 && name.substring(3,4)-b.substring(3,4)==0) {
a._x=eval(b)._x;
a._y=eval(b)._y;
p.push(name);
eval(o.group).pop(name);
o.group=c;
o.order=p.length-1;
o.depth=eval("o"+p[p.length-2]).depth+1;
attachMovie( "deep", "temp", o.depth );
eval(name).swapDepths(temp);
temp.removeMovieClip();
break;
}
}
}
//*** release on the bottom and drop succeeded
function bottom(name) {
for (i=1; i<=7; i++) {
var c="d"+i+"Cards";
var p=eval("d"+i+"Cards");
var s=p.length;
var t=p[p.length-1];
var b=eval(t);
if (a.hitTest(b) && b._currentframe==1 && t.substring(1,3)-name.substring(1,3)==1 && Math.abs (t.substring(3,4)-name.substring(3,4))%2!=0) {
for (k=o.order,j=1; k<eval(o.group).length; k++,j++) {
d=eval(eval(o.group)[k]);
d._x=b._x;
d._y=b._y+15*j;
}
for (k=o.order; k<eval(o.group).length; k++) {
p.push(eval(o.group)[k]);
}
eval(o.group).splice(o.order,eval(o.group).length-o.order);
for (k=s; k<p.length; k++) {
var h=20*i-19;
eval("o"+p[k]).group=c;
eval("o"+p[k]).order=k;
attachMovie( "deep", "temp"+k, h+k );
eval(p[k]).swapDepths(eval("temp"+k));
eval("o"+p[k]).depth=h+k;
eval("temp"+k).removeMovieClip();
}
break;
}
}
}
//*** release and drop target failed , then put the cards back
function other(detect) {
if (detect==o.group) {
for (i=o.order,j=0; i<eval(o.group).length; i++,j++) {
b=eval(eval(o.group)[i]);
b._x=a.x;
b._y=a.y+15*j;
}
}
}
...I don't get any of this stuff!
//*** response the double click on the cards
function double(name) {
o = eval("o"+name);
a = eval(name);
if (name.substring(1,3)=="01") {
for (i=1; i<=4; i++) {
var b=eval("b"+i);
var c="b"+i+"Cards";
var p=eval("b"+i+"Cards");
if (p.length==0) {
a._x=b._x;
a._y=b._y;
p.push(name);
eval(o.group).pop(name);
o.group=c;
o.order=0;
o.depth=181+20*i;
attachMovie( "deep", "temp", 181+20*i );
eval(name).swapDepths(temp);
temp.removeMovieClip();
break;
}
}
} else {
for (i=1; i<=4; i++) {
var c="b"+i+"Cards";
var p=eval("b"+i+"Cards");
var b=p[p.length-1];
if (p.length>0 && name.substring(1,3)-b.substring(1,3)==1 && name.substring(3,4)-b.substring(3,4)==0) {
a._x=eval(b)._x;
a._y=eval(b)._y;
p.push(name);
eval(o.group).pop(name);
o.group=c;
o.order=p.length-1;
o.depth=eval("o"+p[p.length-2]).depth+1;
attachMovie( "deep", "temp", o.depth );
eval(name).swapDepths(temp);
temp.removeMovieClip();
break;
}
}
}
//the end
end();
}
//the end
function end() {
if (b1Cards.length==13 && b2Cards.length==13 && b3Cards.length==13 && b4Cards.length==13) {
for (i=1; i<=4; i++) {
for (j=0; j<13; j++) {
eval(eval("b"+i+"Cards")[j]).removeMovieClip();
}
}
gotoAndStop(6);
}
}
Oho, that's bad. You're probably better off starting from scratch.
i and j seem to be used as counters. Their exact use will depend on which for loop they are in. There's 4 suits, 13 cards in a suit, 52 in a deck, so that will help indicate what sort of thing the loop is sorting through.
He seems to be using c to hold names of lists. Every time there's an "eval" statement, it returns a variable of the same name.
attachMovie(card[i],card[i], cardDepth );
Depth is important when you attach movies. One movie per depth. Look up attachMovie it'll explain more.
...Except I want to be able to put ANY card down on a blank column, but I can't figure out what controls that.
Right above:
//** if the card is "K"
} else if (name.substring(1,3)=="13") {
//*** release on the top and drop succeeded
He's accessing info on the card from a substring of the name. But every time he's using .substring it's to pull out the suit of the face from the full name. This might have beein nicer to look at if he made the cards objects, and gave them .suit and .face attributes. Also you can store references to objects and movieclips, in variables which might cut down on the number of eval() calls.
sam.uk.net
09-23-2009, 07:35 AM
Since this a particularly large bit of code, I'm just gonna say specifically.
Use AS tags when posting actionscript code. It makes it much easier for us to read :)
Good luck with your card game :)
sam.uk.net
TomMalufe
09-23-2009, 02:13 PM
This is AS2 as well... I was under the impression from the title of this thread that it would be AS3.
If it helps, I made a simple AS3 card shuffle FLA the other day just because I wanted to try out a shuffle algorithm I had found. It works well and it should be an easy step to take it in the direction of a working game. I'll gave that to you if you want it.
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.