Card Deck Shuffle
hey, everyone,
i looking way shuffle deck of cards last week , provided code so. decided straight shuffle work better project randomizing coordinates (as doing). i'm trying implement code, , think i'm pretty close, i'm running few snags. i'm using shuffle.as document class, , external class called card.as control flipping , drag action of cards. @ moment, i'm getting message when try run swf:
1084: syntax error: expecting leftbrace before deck.
i think indicative of error somewhere else in code, i'm not sure where. see upon first glance? in advance help; appreciate it!
peter
shuffle.as code:
package
{
import flash.display.movieclip;
import flash.events.mouseevent;
import card;
import boarder;
import blueboard;
import redboard;
import snow;
public class card deck
{
private var _card:card;
private var _boarder:boarder;
private var _blueboard:blueboard;
private var _redboard:redboard;
private var _snow:snow;
private var contents:array;
private var randomnum:number;
private var _cards:array;
public function carddeck()
{
//contents = new array();
_cards = new array();
}
public function set cont(_parmconts)
{
this.contents = _parmconts;
}
public function cont()
{
return this.contents;
}
public function addcard(_card):void {
contents.push(_card);
}
////////////////////////
//start shuffle
///////////////////////
public function shuffle() {
var temparray:array = new array();
var mycount = contents.length;
(var = 0; < mycount; i++) {
var rand = math.floor(math.random()*contents.length );
var mytest = contents[rand];
contents.splice(rand, 1);
temparray.push(mytest);
}
(var j = 0; j < mycount; j++) {
contents[j] = temparray[j];
}
}
/////////////////////////////////////////
//end shuffle
/////////////////////////////////////////
private var cardpicked;
public function drawcard() {
cardpicked = contents.shift();
//removetopcard();
return cardpicked;
}
public function removetopcard() {
contents.shift();
}
public function deckcount() {
return contents.length;
}
public function showtopcard()
{
return contents[0];
}
public function showcards(num)
{
var temparray:array = new array(num)
(var = 0 ; i< num;i++){
temparray[i] = contents[i];
}
return temparray;
}
public function removecard(cardname)
{
var mycount = contents.length;
var removedone = false;
(var = 0; < mycount; i++) {
trace("loopcount: " + );
if(removedone == false)
{
var mytest = contents[i];
if(mytest.cardname == cardname)
{
//remove element
trace("remove card");
contents.splice(i,1);
removedone = true;
}
}
}
}
}
}
card.as code:
package
{
import flash.display.movieclip;
import flash.events.mouseevent;
public class card extends movieclip
{
private var _type:*;
public function card()
{
this.buttonmode = true;
this.addeventlistener(mouseevent.click, onclick);
this.addeventlistener(mouseevent.mouse_down, mousedownhandler);
this.addeventlistener(mouseevent.mouse_up, mouseuphandler);
}
private function onclick(event:mouseevent):void
{
this.play();
this.removeeventlistener(mouseevent.click, onclick)
}
private function mousedownhandler(event:mouseevent):void
{
var thismc:movieclip = event.currenttarget movieclip;
thismc.startdrag(false);
thismc.addeventlistener(mouseevent.mouse_move, mousemovehandler);
}
private function mouseuphandler(event:mouseevent):void
{
var thismc:movieclip = event.currenttarget movieclip;
thismc.stopdrag();
thismc.removeeventlistener(mouseevent.mouse_move, mousemovehandler);
}
private function mousemovehandler(event:mouseevent):void
{
event.updateafterevent();
}
public function settype(type:*):void
{
_type = type;
loader_mc.addchild(_type);
}
}
}
i can't typo or forum throwing spaces code (which do), if following what's in file source of problem...
public class card deck
More discussions in Adobe Animate CC - General
adobe
Comments
Post a Comment