2022年12月26日 星期一

Yiting_week17

  int [][]board={

  { 1, 2, 3, 4, 5, 6},

  {7, 8, 9, 10, 11, 12},

  { 13, 14, 15, 16, 17, 18},

  {19, 20, 21, 22, 23, 24},

  { -1, -2, -3, -4, -5, -6},

  { -7, -8, -9, -10, -11, -12},

  { -13, -14, -15, -16, -17, -18},

  {-19, -20, -21, -22, -23, -24},

}; 


void setup() {

  size(1000, 1000);

  PFont font = createFont("微軟正黑體", 30);

  textFont(font);

  for (int k=0; k<1000; k++) {

    int i1=int(random(8)), j1=int(random(6));

    int i2=int(random(8)), j2=int(random(6));

    int temp=board[i1][j1];

    board[i1][j1]=board[i2][j2];

    board[i2][j2]=temp;

  }

  show1 = new ArrayList<String>();

  show2 = new ArrayList<String>();

  show3 = new ArrayList<String>();

  show4 = 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  face6;

ArrayList<String> show1;

ArrayList<String> show2;

ArrayList<String> show3;

ArrayList<String> show4;

void draw() {

  background(#FFFFF2);

  drawaPokerDeck(40, 100, show1);

  drawaPokerDeck(240, 100, show2);

  drawaPokerDeck(440, 100, show3);

  drawaPokerDeck(640, 100, show4);

  for (int i=0; i<8; i++) {

    for (int j=0; j<6; j++) {

      int id = board[i][j];

      drawCard(30+i*100, 600+j*10, id);

    }

  }

  if (moving) {

    drawCard(mouseX, mouseY, moveID);///讓棋子跟著滑鼠

  }

}

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 drawaPokerCard(int x, int y, String show) {

  int W=20;

  fill(255);

  rect(x-W/2, y-W/2, 80+W, 120+W, 20);

  if (show.indexOf("黑桃")==-1 && show.indexOf("梅花")==-1)fill(#FF0000);

  else fill(0);

  textSize(25);

  text(show, x+10, y+30);

}

int moveI=-1, moveJ=-1, moveID=-1;

boolean moving = false;

void mousePressed() {

  for (int i=0; i<8; i++) {

    for (int j=0; j<6; j++) {

      if (dist(mouseX, mouseY, 30+i*100, 600+j*10)<60) {

        moveI=i;

        moveJ=j;

        moveID=board[i][j];

        moving=true;

      }

    }

  }

}


void mouseReleased() {

  for (int i=0; i<8; i++) {

    for (int j=0; j<6; j++) {

      if (dist(mouseX, mouseY,30+i*100, 600+j*10)<60) {

        if (moving) {

          board[moveI][moveJ]=0;

          board[i][j]=moveID;

          moving=false;

        }

      }

    }

  }

}


String[] black={"黑桃2", "黑桃3", "黑桃4", "黑桃5", "黑桃6", "黑桃7", "黑桃8", "黑桃9", "黑桃10", "黑桃J", "黑桃Q", "黑桃K",

"梅花2", "梅花3", "梅花4", "梅花5", "梅花6", "梅花7", "梅花8", "梅花9", "梅花10", "梅花J", "梅花Q", "梅花K"};

String[] red={"紅心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 drawCard(int x, int y, int id) {

  if (id==0)return;

  fill(255);

  rect( x, y, 100, 140, 20);

  if (id>0) {//黑

    fill(0);

    text( black[id-1], x+15, y+25);

  } else {//紅

    fill(255, 0, 0);

    text( red[-id-1], x+15, y+25);

  }

}

沒有留言:

張貼留言