xxxxxxxxxx
132
deck=[];
piles=[];
var discard;
deckx=5;
decky=5;
var ind=0;
cw=65;
ch=100;
var img;
var where=0;
function preload(){
img= loadImage('Berkshire.JPG');
}
function setup() {
createCanvas(800, 600);
background(0);
img.resize(width/4, height/2);
deck=newDeck(); //Create unshuffled deck of 52 cards
//console.log(deck);
//deck=shuffleDeck(...deck); // Shuffle deck just created
// initializePiles(); // Deal the cards!
// drawBoard(); // Shows outlines of card positions
//showPiles();
//console.log(piles[1].cards.length);
}
function draw() {
background(255);
//image(img, 0,0);
noFill();
rect(0,0, width, height)
ind=where;
for(var i=0; i<2; i++)
{
for(var j=0; j<4; j++)
{
var x=width/4*j;
var y=((height/2))*i;
noFill();
stroke(0);
rect(x,y, width/4, height/2);
switch(deck[ind].suit)
{
case "HEARTS": fill(255,0,0);
stroke(255,0,0);
break;
case "DIAMONDS": fill(255,0,0);
stroke(255,0,0);
break;
case "SPADES": fill(0,0,0);
stroke(0,0,0);
break;
case "CLUBS": fill(0,0,0);
stroke(0,0,0);
break;
}
textSize(30);
//image(img, x,y);
text(deck[ind].name+ " " + deck[ind].pic, x+75, y+50);
text(deck[ind].name+ " " + deck[ind].pic, x+75, y+250);
ind++;
}
}
}
function newDeck() // Creates a new deck of 52 cards.
{
tdeck=[]; // Temporary Deck used for builing
var suits=["HEARTS", "DIAMONDS", "CLUBS", "SPADES"];
var names=["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"];
for(var i=0; i<4; i++)
{
for(var j=0; j<13; j++)
{
tdeck.push(new Card(j+1, names[j], suits[i]));
}
}
return tdeck;
}
function shuffleDeck (inDeck){
var unshuffled=inDeck;
var temp=0;
for(var i=0; i<unshuffled.length; i++)
{
temp=unshuffled[i];
swap=floor(random(unshuffled.length));
unshuffled[i]=unshuffled[swap];
unshuffled[swap]=temp;
}
return unshuffled;
}
function showCard(x,y,incard)
{
}
function keyPressed()
{
where+=8;
}