2022年12月12日 星期一

7ru week15

  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();///洗牌

  show1 = new ArrayList<String>();

  show2 = new ArrayList<String>();

  show3 = new ArrayList<String>();

  show4 = new ArrayList<String>();

  show5 = new ArrayList<String>();

  show1.add(shows[0]);

  show2.add(shows[1]);

  show3.add(shows[2]);

  show4.add(shows[3]);

}

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];

}

void keyPressed() {///按Enter可以洗牌

  myShuffle();

}

String face1, face2, face3, face4, face5, face6;

ArrayList<String> show1;

ArrayList<String> show2;

ArrayList<String> show3;

ArrayList<String> show4;

ArrayList<String> show5;

void draw() {

  background(#FFFFF2);

  drawaPokerDeck(40, 100, show1);

  drawaPokerDeck(240, 100, show2);

  drawaPokerDeck(440, 100, show3);

  drawaPokerDeck(640, 100, show4);


  drawPokerCard(30, 600, face1);

  drawPokerCard(160, 600, face2);

  drawPokerCard(290, 600, face3);

  drawPokerCard(420, 600, face4);

  drawPokerCard(550, 600, face5);

  drawPokerCard(680, 600, face6);

}

void drawaPokerDeck(int x, int y, ArrayList<String> show) {

  for (int i=0; i<show.size(); i++) {

    drawaPokerCard(x, y+i*50, show.get(i));

  }

}

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+80 && coord[i].y<mouseY && mouseY<coord[i].y+120) {

      coord[i].x += mouseX-pmouseX;

      coord[i].y += mouseY-pmouseY;

    }

  }

}

/*void mouseReleased() {

 

}*/

沒有留言:

張貼留言