2022年11月21日 星期一

7ru week12

 void setup() {

  size(800, 800);
  PFont font = createFont("微軟正黑體", 40);
  textFont(font);
  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();
}
String face1, face2, face3, face4, face5, face6, show1, show2, show3, show4;
void draw() {
  background(#FFFFF2);
  drawPokerCard(30, 600, face1);
  drawPokerCard(140, 600, face2);
  drawPokerCard(250, 600, face3);
  drawPokerCard(360, 600, face4);
  drawPokerCard(470, 600, face5);
  drawPokerCard(580, 600, face6);

  drawaPokerCard(25, 100, show1);
  drawaPokerCard(225, 100, show2);
  drawaPokerCard(425, 100, show3);
  drawaPokerCard(625, 100, show4);
}
void drawPokerCard(int x, int y, String face) {
  int W=20;
  fill(255);
  rect(x-W/2, y-W/2, 150+W, 250+W, 20);
  fill(#BA90FF);
  ///rect(x, y, 180, 280, 20);
  if (face.indexOf("黑桃")==-1 && face.indexOf("梅花")==-1)fill(#FF0000);
  else fill(0);
  textSize(30);
  text(face, x+10, y+30);
}
void drawaPokerCard(int x, int y, String show) {
  int W=20;
  fill(255);
  rect(x-W/2, y-W/2, 150+W, 250+W, 20);
  fill(#BA90FF);
  ///rect(x, y, 150, 250, 20);
  if (show.indexOf("黑桃")==-1 && show.indexOf("梅花")==-1)fill(#FF0000);
  else fill(0);
  textSize(30);
  text(show, x+10, y+30);
}

沒有留言:

張貼留言