PVector[]coord;
void setup() {
size(800, 800);
PFont font = createFont("微軟正黑體", 40);
textFont(font);
coord = new PVector[faces.length];
for (int i=0; i<faces.length; i++) {
coord[i] = new PVector(5+i*100, 600);
}
myShuffle();///洗牌
}
String[] shows={"黑桃A", "紅心A", "方塊A", "梅花A", };///固定A
String[] faces={
"黑桃2", "黑桃3", "黑桃4", "黑桃5", "黑桃6", "黑桃7", "黑桃8", "黑桃9", "黑桃10", "黑桃J", "黑桃Q", "黑桃K",
"紅心2", "紅心3", "紅心4", "紅心5", "紅心6", "紅心7", "紅心8", "紅心9", "紅心10", "紅心J", "紅心Q", "紅心K",
"方塊2", "方塊3", "方塊4", "方塊5", "方塊6", "方塊7", "方塊8", "方塊9", "方塊10", "方塊J", "方塊Q", "方塊K",
"梅花2", "梅花3", "梅花4", "梅花5", "梅花6", "梅花7", "梅花8", "梅花9", "梅花10", "梅花J", "梅花Q", "梅花K",
};
void myShuffle() {
for (int k=0; k<10000; k++) {
int a =int(random(48));
int b =int(random(48));
String temp=faces[a];
faces[a]=faces[b];
faces[b]=temp;
}
face1=faces[0];
face2=faces[1];
face3=faces[2];
face4=faces[3];
face5=faces[4];
face6=faces[5];
show1=shows[0];
show2=shows[1];
show3=shows[2];
show4=shows[3];
}
void keyPressed() {///按Enter可以洗牌
myShuffle();
}
void drawPokerCard() {
int W=20;
for (int i=0; i<faces.length; i++) {
fill(255);
rect(coord[i].x, coord[i].y, 80+W, 120+W, 20);
if (faces[i].indexOf("黑桃")==-1 && faces[i].indexOf("梅花")==-1)fill(#FF0000);
else fill(0);
textSize(25);
text(faces[i], coord[i].x+10, coord[i].y+30);
}
}
int selected=-1;
String face1, face2, face3, face4, face5, face6, show1, show2, show3, show4;
void draw() {
background(#FFFFF2);
drawaPokerCard(40, 100, show1);
drawaPokerCard(240, 100, show2);
drawaPokerCard(440, 100, show3);
drawaPokerCard(640, 100, show4);
for (int j=0; j<13; j++) {
rect(coord[j].x, coord[j].y, 100, 140, 20);
}
//for (int i=0; i<=6; i++) {
//drawPokerCard(30+130*i, 600, faces[i]);
/*drawPokerCard(160, 600, face2);
drawPokerCard(290, 600, face3);
drawPokerCard(420, 600, face4);
drawPokerCard(550, 600, face5);
drawPokerCard(680, 600, face6);*/
drawPokerCard();
if (mousePressed && selected != -1) {
rect(mouseX, mouseY, 100, 140, 20);
}
}
/*void drawPokerCard(int x, int y, String face) {
int W=20;
for (int i=0; i<faces.length; i++) {
fill(255);
rect(coord[i].x, coord[i].y, 80+W, 120+W, 20);
if (faces[i].indexOf("黑桃")==-1 && faces[i].indexOf("梅花")==-1)fill(#FF0000);
else fill(0);
textSize(25);
text(faces[i], coord[i].x+10, coord[i].y+30);
}
}*/
void drawaPokerCard(int x, int y, String show) {
int W=20;
fill(255);
rect(x-W/2, y-W/2, 80+W, 120+W, 20);
///fill(#BA90FF);
///rect(x, y, 150, 250, 20);
if (show.indexOf("黑桃")==-1 && show.indexOf("梅花")==-1)fill(#FF0000);
else fill(0);
textSize(25);
text(show, x+10, y+30);
}
/*void mouseDragged() {///滑鼠拖曳
for (int i=0; i< faces.length; i++) {
if (coord[i].x<mouseX && mouseX<coord[i].x+100 && coord[i].y<mouseY && mouseY<coord[i].y+140) {
coord[i].x += mouseX-pmouseX;
coord[i].y += mouseY-pmouseY;
}
}*/
void mousePressed() {
int select=-1;
for (int i=0; i<13; i++) {
if ( dist(mouseX, mouseY, 30+130*i, 600)<100) select=i;
}
if (select!=-1) selected=select;
}
//void mouseRelease() {
// if (
沒有留言:
張貼留言