|
-
KoolMoves Moderator
in case anyone is interested in looking over my shoulder here's what I have so far.
Code:
outline=function(m,x,y){
w=x+71
h=y+99
//lineStyle(thickness:Number, rgb:Number, alpha:Number, pixelHinting:Boolean, noScale:String, capsStyle:String, jointStyle:String, miterLimit:Number)
m.lineStyle(2,0x9FFFCF,50,true,"normal","round","round")
m.beginFill(0x9FFFCF,60)
m.moveTo(x,y)
m.lineTo(w,y)
m.lineTo(w,h)
m.lineTo(x,h)
m.lineTo(x,y)
m.endFill()
}
_global.cards = flash.display.BitmapData.loadBitmap('deck');
//DropShadowFilter([distance], [angle], [color], [alpha], [blurX], [blurY], [strength], [quality], [inner], [knockout], [hideObject])
myDropShadow = new flash.filters.DropShadowFilter(4,45,0x00000000,10,10,10);
MovieClip.prototype.createNewCard = function(name,depth,deck,col,row){
// create the movieclips to hold the card
var m = this.createEmptyMovieClip(name,depth);
var m1 = m.createEmptyMovieClip('m',1); m1._x = 36; m1._y = 50;
var m2 = m1.createEmptyMovieClip('m',1);
m2.filters = [myDropShadow];
// copy the passed parameters to the movieclip
m.deck = deck;
m.col = col;
m.row = row;
m.$s = true; // flip state
// add some functions
m.destroy = function(){
this.bmp.dispose();
this.swapDepths(this.getNextHighestDepth());
this.removeMovieClip();
}
m.$copy = function(col,row){
this.bmp.dispose();
this.bmp = new flash.display.BitmapData(72,100,true);
this.bmp.applyFilter(this.bmp,this.flash.geom.rectangle, new flash.geon.Point(0,0),myDropShadow)
this.bmp.copyPixels(_global.cards,new flash.geom.Rectangle(col * 72,row * 100,72,100),new flash.geom.Point(0,0));
this.m.m.attachBitmap(this.bmp,1,'auto',true);
this.m.m._x = -38; this.m.m._y = -50;
}
m.flipCard = function(){
this.$s = !this.$s;
if (this.$s) this.$copy(this.col,this.row) else this.$copy(this.deck,4);
}
m.flipCardAnimated = function(){
this._x-=8
this.$f = 0;
this.onEnterFrame = function(){
this.$f++;
this.m._xscale = Math.abs(Math.cos(Math.PI * this.$f * .1)) * 100;
if (this.$f == 5){
this.flipCard();
} else if (this.$f == 10){
this.onEnterFrame = null;
this.onAnimationCompleted();
this._x+=8
}
}
}
m.moveCardAnimated = function(dx,dy){
this.$f = 0;
this.sx = this._x;
this.sy = this._y;
this.dx = dx;
this.dy = dy;
this.onEnterFrame = function(){
this.$f++;
this._x = this.sx * (10-this.$f) * .1 + this.dx * this.$f * .1;
this._y = this.sy * (10-this.$f) * .1 + this.dy * this.$f * .1;
if (this.$f == 10){
this.onEnterFrame = null;
this.onAnimationCompleted();
}
}
}
// show card
m.flipCard();
// return refrence
return m;
}
Array.prototype.shuffle = function() {
len = this.length;
for (var i=0; i < len; i++) {
rand = Math.floor(Math.random()*len);
//swap current index with a random one
temp = this[i];
this[i] = this[rand];
this[rand] = temp;
}
}
Frame 3 code
Code:
mc7.gotoAndStop(3)
//starting values
reset=function(){
cash=500
cash_txt.text=cash
bet=0
cr=100//card row
cardStart=50
handOver=false
}
//function for array.sort
compareHands =function(a,b){
if (a.value<b.value) return(-1);
if (a.value==b.value) return(0)
if (a.value>b.value) return(1)
}
//Get Value of hand
function handVal(){
hand=deck.slice()//get copy of hand
hand.sort(compareHands)//sort it in numerical order to test for straight
//check for staights
straight=true
for (i=0;i<4;i++){
if(hand[i].value+1!=hand[i+1].value) straight=false;
}//end for
//check for 10-Ace straight
if(hand[0]==1 && hand[1]==10 && hand[2]==11 && hand[3]==12 && hand[4]==13) straight=true
//check for flush
flush=true
for (i=1;i<5;i++){
if (hand[i].suit!=hand[0].suit) flush=false
}//end for
//count pairs.
counts=new Array()//make clean array of 0s
for (i=0;i<4;i++){
counts.push(0);
}
for (i=1;i<5;i++){
counts[hand[i].value]++
}
pair=twoPair=threeOfAKind=fourOfAKind=false
for(i=1;i<4;i++){
if (counts[i]==2){
if (pair){
twoPair=true;
}else{
pair=true;
}
}else if (counts[i]==3){
threeOfAKind=true
}else if (counts[i]==4){
fourOfAKind=true
}
}//end for
jackOrHigher=false
for(i=1;i<14;i++){
if (((i==1) | (i>10)) && (counts[i]>=2)){
jackOrHigher=true;
}
}
//******************working here**********************/
//***************************************************
}//end handVal
reset()
createNewCard('drawCard',getNextHighestDepth(),3,0,1);
drawCard._x = 400; drawCard._y = cr;
Array.prototype.shuffle = function() {//adds the method shuffe() to all Arrays to shuffle it's elements
var len = this.length;
for (var i=0; i < len; i++) {
var rand = Math.floor(Math.random()*len);
//swap current index with a random one
var temp = this[i];
this[i] = this[rand];
this[rand] = temp;
}
}
Array.prototype.swap=function(i,j){
var temp=this[i]
this[i]=this[j]
this[j]=temp
}
function createDeck(){
var deck=new Array()
for(var s=0;s<4;s++){
for(var n=0;n<13;n++){
deck.push(createNewCard('Card'+s.toString()+n.toString(),getNextHighestDepth(),3,n,s));
//deck[deck.length-1]._visible=false
deck[deck.length-1]._x=-100
deck[deck.length-1]._y=cr
deck[deck.length-1].value=n+1
deck[deck.length-1].suit=s
deck[deck.length-1].onRelease = drawCard.onReleaseOutside = function(){
if(!handOver){
this.flipCardAnimated();
this.onAnimationCompleted = function(){
this.onAnimationCompleted = function(){}
}
}
}
}
}
return deck;
}
var m = this.createEmptyMovieClip("layout",getNextHighestDepth());
for (x=cardStart;x<320;x+=80){
outline(m,x,100);
}
deck = new Array()
deck=createDeck()
deck.shuffle()
deck.shuffle()
//lightrn logo
bgLogo._alpha=35
chip.onRelease=function(){
status.text=""
if (!handDealt){
bet+=5
txt3.text=bet
cash-=bet
cash_txt.text=cash
}else{
status.text="No more bets until next Hand"
}
}
cardsDrawn=0
cp=cardStart
handDealt=false
drawCard.onRelease = drawCard.onReleaseOutside = function(){
mc7.gotoAndStop(2);
if (bet!=0){
if (!handDealt){
var hand=new Array()
status.text="Dealing initial cards..."
for (x=0;x<4;x++){
status.text=deck[0].value
deck[x]._x=this._x
deck[x]._y=cr
deck[x]._visible=true
deck[x].moveCardAnimated(cp,cr)
cardsDrawn++
cp+=80
deck[x].onAnimationCompleted = function(){
this.onAnimationCompleted = function(){
}
this.flipCardAnimated();
status.text=""
}//end onAnimationCompteted
}//end for
handDealt=true
}else{//end if handdealt
mc7.gotoAndStop(3);
//deal flipped cards
if (!handOver){
for (x=0;x<4;x++){
status.text="Dealing new cards"
if (!deck[x].$s){
var tempx=deck[x]._x
deck.swap(x,cardsDrawn)
deck[x].ox=deck[x]._x
deck[cardsDrawn]._x=-100
deck[x]._x=drawCard._x
deck[x]._visible=true
deck[x].moveCardAnimated(tempx,cr)
deck[x].swapDepths(9999)
cardsDrawn++
deck[x].onAnimationCompleted = function(){
this.onAnimationCompleted = function(){
status.text=""
}
this.flipCardAnimated();
}//end onAnimationCompteted
}
handOver=true
}//end for loop
}
}//end else
}else{//end if bet
status.text="Place Bet First"
}//end if Dealt
}
}//end drawcard button action
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|