2023年10月5日 星期四

XX - Week04


=========================================================================

FOURTH

今天要做的是UNO抽卡、發牌,下面這是UNO卡牌的原版樣式


1.先畫出卡牌的格子
void setup(){
  size(400,400);
}
int [][] card = new int[8][11];
void draw(){
  background(255);
  for(int i=0; i<8; i++){
    for(int j=0; j<11; j++){
      rect(j*32, i*50, 32, 50);
    }
  }
}
2.利用fill填充顏色到格子裡面(可以利用小畫家的吸管+顏色選擇器來找出顏色)
void setup(){
  size(400,400);
}
int [][] card = new int[8][11];
color [] C = {#FF5555, #FFAA00, #55AA55, #5555FF};
void draw(){
  background(255);
  for(int i=0; i<8; i++){
    for(int j=0; j<11; j++){
      fill(C[i%4]);
      rect(j*32, i*50, 32, 50);
    }
  }
}
3.定義一個函式,來讓卡片的邊邊圓滑一點、有白邊
void setup(){
  size(400,400);
}
int [][] card = new int[8][11];
color [] C = {#FF5555, #FFAA00, #55AA55, #5555FF};
void draw(){
  background(255);
  for(int i=0; i<8; i++){
    for(int j=0; j<11; j++){
      drawCard(j*32, i*50, C[i%4]);
    }
  }
}
void drawCard(int x, int y, color c){
  stroke(128);
  fill(255);
  rect(x, y, 32, 50, 7);
  noStroke();
  fill(c);
  rect(x+3, y+3, 32-5, 50-5, 4);
}

4.畫出UNO卡牌中間的橢圓
void setup(){
  size(400,400);
}
int [][] card = new int[8][11];
color [] C = {#FF5555, #FFAA00, #55AA55, #5555FF};
void draw(){
  background(255);
  for(int i=0; i<8; i++){
    for(int j=0; j<11; j++){
      drawCard(j*32, i*50, C[i%4]);//呼叫
    }
  }
}
void drawCard(int x, int y, color c){
  stroke(128);
  fill(255);
  rect(x, y, 32, 50, 7);
  noStroke();
  fill(c);
  rect(x+3, y+3, 32-5, 50-5, 4);//紙牌邊邊圓滑
  
  pushMatrix();//畫橢圓
  fill(255);
  translate(x+16, y+25);
  rotate(radians(45));
  ellipse(0, 0, 20, 30);
  popMatrix();
}
5.將數字的位子先放置好
void setup(){
  size(400,400);
}
int [][] card = new int[8][11];
color [] C = {#FF5555, #FFAA00, #55AA55, #5555FF};
void draw(){
  background(255);
  for(int i=0; i<8; i++){
    for(int j=0; j<11; j++){
      drawCard(j*32, i*50, C[i%4], j);
    }
  }
}
void drawCard(int x, int y, color c, int n){
  stroke(128);//gray stroke
  fill(255);
  rect(x, y, 32, 50, 7);
  noStroke();
  fill(c);
  rect(x+3, y+3, 32-5, 50-5, 4);//紙牌邊邊圓滑
  
  pushMatrix();//畫橢圓
  fill(255);
  translate(x+16, y+25);
  rotate(radians(45));
  ellipse(0, 0, 20, 30);
  popMatrix();
  
  textSize(9);//左上角的數字
  textAlign(CENTER,CENTER);
  text(""+n, x+7, y+6);
  
  textSize(20);//中間的數字
  fill(c);
  text(""+n, x+16, y+22);
}
6.加上一個洗牌Shuffle函式,讓牌組能夠洗牌
void setup(){
  size(400,400);
  myShuffle();
}
void myShuffle(){
  for(int i=0; i<8; i++){
    for(int j=0; j<11; j++){
      cardN[i*11+j] = j;
      cardC[i*11+j] = C[i%4];
    }
  }
  for(int i=0; i<10000; i++){
    int a = int(random(88)), b = int(random(88));
    int temp = cardN[a];
    cardN[a] = cardN[b];
    cardN[b] = temp;
    temp = cardC[a];
    cardC[a] = cardC[b];
    cardC[b] = temp;
  }
}
//int[][]card = new int[8][11];
int [] cardN = new int[88];///存放卡片的數字n
int [] cardC = new int[88];///存放卡片的顏色
color [] C = { #FF5555, #FFAA00, #55AA55, #5555FF};
void draw(){
  background(255);
  for(int i=0; i<8; i++){
    for(int j=0; j<11; j++){
      //drawCard( j*32, i*50, C[i%4],j);
      drawCard( j*32, i*50, cardC[i*11+j],cardN[i*11+j]);
    }
  }
}
void drawCard(int x,int y,color c,int n){
  stroke(128);
  fill(255);
  rect( x, y, 32, 50, 7);
  noStroke();
  fill(c);
  rect( x+3, y+3, 32-5, 50-5,4);
  
  pushMatrix();
  fill(255);
  translate(x+16,y+25);//移動
  rotate(radians(45));///轉45度
  ellipse(0,0,20,30);///STEP 1畫橢圓
  popMatrix();
  
  textAlign(CENTER,CENTER);//將對齊點移到字的正中間
  textSize(9);
  text( ""+n, x+7, y+8);///畫左上角的字//文字的中心點對齊點在左下角
  
  textSize(20);//畫中間字
  fill(c);//設定中間字的顏色
  text( ""+n, x+16, y+25);
}
7.將視窗變寬一點,在旁邊放上一個洗出來的大卡片
void setup(){
  size(800,400);
  myShuffle();
}
void myShuffle(){
  for(int i=0; i<8; i++){
    for(int j=0; j<11; j++){
      cardN[i*11+j] = j;
      cardC[i*11+j] = C[i%4];
    }
  }
  for(int i=0; i<10000; i++){
    int a = int(random(88)), b = int(random(88));
    int temp = cardN[a];
    cardN[a] = cardN[b];
    cardN[b] = temp;
    temp = cardC[a];
    cardC[a] = cardC[b];
    cardC[b] = temp;
  }
}
int [] cardN = new int[88];///存放卡片的數字n
int [] cardC = new int[88];///存放卡片的顏色
color [] C = { #FF5555, #FFAA00, #55AA55, #5555FF};
void draw(){
  background(255);
  for(int i=0; i<8; i++){
    for(int j=0; j<11; j++){
      drawCard( j*32, i*50, cardC[i*11+j],cardN[i*11+j], 32);
    }
  }
  drawCard(450, 50, cardC[7], cardN[77], 128);
}
void drawCard(int x,int y,color c,int n, int w){
  float s = w/32.0; //scale size
  stroke(128);
  fill(255);
  rect( x, y, 32*s, 50*s, 7*s);
  noStroke();
  fill(c);
  rect( x+2.5*s, y+2.5*s, 32*s-5*s, 50*s-5*s, 4*s);
  
  pushMatrix();
  fill(255);
  translate(x+16*s,y+25*s);//移動
  rotate(radians(45));///轉45度
  ellipse(0,0,20*s,30*s);///STEP 1畫橢圓
  popMatrix();
  
  textAlign(CENTER,CENTER);//將對齊點移到字的正中間
  textSize(9*s);
  text( ""+n, x+7*s, y+6*s);///畫左上角的字//文字的中心點對齊點在左下角
  
  textSize(20*s);//畫中間字
  fill(c);//設定中間字的顏色
  text( ""+n, x+16*s, y+22*s);
}

8.抽牌的概念,按下滑鼠左鍵就可以抽牌,按下右鍵就可以作弊的看到發牌的順序
void setup(){
  size(800,400);
  myShuffle();
}
void myShuffle(){
  for(int i=0; i<8; i++){
    for(int j=0; j<11; j++){
      cardN[i*11+j] = j;
      cardC[i*11+j] = C[i%4];
    }
  }
  for(int i=0; i<10000; i++){
    int a = int(random(88)), b = int(random(88));
    int temp = cardN[a];
    cardN[a] = cardN[b];
    cardN[b] = temp;
    temp = cardC[a];
    cardC[a] = cardC[b];
    cardC[b] = temp;
  }
}
int [] cardN = new int[88];///存放卡片的數字n
int [] cardC = new int[88];///存放卡片的顏色
color [] C = { #FF5555, #FFAA00, #55AA55, #5555FF};
void draw(){
  background(255);
  if(mousePressed && mouseButton==RIGHT){ //cheat key,peek all
    for(int i=0; i<8; i++){
      for(int j=0; j<11; j++){
        drawCard( j*32, i*50, cardC[i*11+j],cardN[i*11+j], 32);
      }
    }
  }else drawCard(50, 50, #000000, 99, 128); //get card here
  
  for(int i=0; i<myCard; i++){
    drawCard(450+40*i, 50, cardC[i], cardN[i], 128);
  }
}
int myCard = 0;
void mousePressed(){
  if(mouseButton==LEFT) myCard++;
}
void drawCard(int x,int y,color c,int n, int w){
  float s = w/32.0; //scale size
  stroke(128);
  fill(255);
  rect( x, y, 32*s, 50*s, 7*s);
  noStroke();
  fill(c);
  rect( x+2.5*s, y+2.5*s, 32*s-5*s, 50*s-5*s, 4*s);
  
  pushMatrix();
  fill(255);
  translate(x+16*s,y+25*s);//移動
  rotate(radians(45));///轉45度
  ellipse(0,0,20*s,30*s);///STEP 1畫橢圓
  popMatrix();
  
  textAlign(CENTER,CENTER);//將對齊點移到字的正中間
  textSize(9*s);
  text( ""+n, x+7*s, y+6*s);///畫左上角的字//文字的中心點對齊點在左下角
  
  textSize(20*s);//畫中間字
  fill(c);//設定中間字的顏色
  text( ""+n, x+16*s, y+22*s);
}
9.將視窗拉大,並且能夠發牌給4個位子
void setup(){
  size(850,850);
  myShuffle();
}
void myShuffle(){
  for(int i=0; i<8; i++){
    for(int j=0; j<11; j++){
      cardN[i*11+j] = j;
      cardC[i*11+j] = C[i%4];
    }
  }
  for(int i=0; i<10000; i++){
    int a = int(random(88)), b = int(random(88));
    int temp = cardN[a];
    cardN[a] = cardN[b];
    cardN[b] = temp;
    temp = cardC[a];
    cardC[a] = cardC[b];
    cardC[b] = temp;
  }
}
int [] cardN = new int[88];///存放卡片的數字n
int [] cardC = new int[88];///存放卡片的顏色
color [] C = { #FF5555, #FFAA00, #55AA55, #5555FF};
void draw(){
  background(255);
  if(mousePressed && mouseButton==RIGHT){ //cheat key,peek all
    for(int i=0; i<8; i++){
      for(int j=0; j<11; j++){
        drawCard( j*32, i*50, cardC[i*11+j],cardN[i*11+j], 32);
      }
    }
  }else drawCard(50, 50, #000000, 99, 128); //get card here
  
  for(int i=0; i<myCard; i++){
    if(i%4==0) drawCard(430+40*i/4, 50, cardC[i], cardN[i], 128);
    if(i%4==1) drawCard(630+40*i/4, 350, cardC[i], cardN[i], 128);
    if(i%4==2) drawCard(430+40*i/4, 650, cardC[i], cardN[i], 128);
    if(i%4==3) drawCard(230+40*i/4, 350, cardC[i], cardN[i], 128);
  }
}
int myCard = 0;
void mousePressed(){
  if(mouseButton==LEFT) myCard++;
}
void drawCard(int x,int y,color c,int n, int w){
  float s = w/32.0; //scale size
  stroke(128);
  fill(255);
  rect( x, y, 32*s, 50*s, 7*s);
  noStroke();
  fill(c);
  rect( x+2.5*s, y+2.5*s, 32*s-5*s, 50*s-5*s, 4*s);
  
  pushMatrix();
  fill(255);
  translate(x+16*s,y+25*s);//移動
  rotate(radians(45));///轉45度
  ellipse(0,0,20*s,30*s);///STEP 1畫橢圓
  popMatrix();
  
  textAlign(CENTER,CENTER);//將對齊點移到字的正中間
  textSize(9*s);
  text( ""+n, x+7*s, y+6*s);///畫左上角的字//文字的中心點對齊點在左下角
  
  textSize(20*s);//畫中間字
  fill(c);//設定中間字的顏色
  text( ""+n, x+16*s, y+22*s);
}

沒有留言:

張貼留言