顯示具有 Week14 標籤的文章。 顯示所有文章
顯示具有 Week14 標籤的文章。 顯示所有文章

2022年1月17日 星期一

期末作業完成week14

 期末作業完成:






Youtube連結:電流急急棒 - YouTube

程式碼:

PImage ball,maze,gem;

int[] rangeX = {0,125};

int[] rangeY = {480,235};


int ballposX = 30,ballposY = 215;

int offsetX = 0,offsetY = 0;


boolean is_over = false;

boolean is_win = false;


void setup()

{

  size(640,480);

  maze=loadImage("maze.png");

  ball=loadImage("ball.png");

  gem=loadImage("gem.png");

}

void draw()

{

  

  

  background(255);

  imageMode(CENTER); 

  image(maze,320,240);

  image(gem,590,415);

  image(ball,ballposX,ballposY);

  

  if(is_over && !is_win)

  {

    GameOver();

  }

  

  if(is_win)

  {

    Win();

  }

}


void mousePressed()

{

  offsetX = ballposX - mouseX;

  offsetY = ballposY - mouseY;

}


void mouseDragged()

{

  if(!is_over)

  {

    ballposX = offsetX + mouseX;

    ballposY = offsetY + mouseY;

  }

  

  detCollision();

  


}


void GameOver()

{

  textAlign(CENTER);

  textSize(100);

  fill(0);

  text("Game Over",320,240);

}


void Win()

{

  textAlign(CENTER);

  textSize(100);

  fill(0);

  text("Victory",320,240);

}


void detCollision()

{

   //左下

  if(ballposX-13 > 0 && ballposX-13 < 125 && ballposY+13 > 235)

  {

    is_over = true;

  }

  if(ballposX-13 > 0 && ballposX-13 < 125 && ballposY-13 > 235)

  {

    is_over = true;

  }

  if(ballposX+13 > 0 && ballposX+13 < 125 && ballposY+13 > 235)

  {

    is_over = true;

  }

  if(ballposX+13 > 0 && ballposX+13 < 125 && ballposY-13 > 235)

  {

    is_over = true;

  }

  

  //左上

  if(ballposX-13 > 0 && ballposX-13 < 125 && ballposY+13 < 195)

  {

    is_over = true;

  }

  if(ballposX-13 > 0 && ballposX-13 < 125 && ballposY-13 < 195)

  {

    is_over = true;

  }

  if(ballposX+13 > 0 && ballposX+13 < 125 && ballposY+13 < 195)

  {

    is_over = true;

  }

  if(ballposX+13 > 0 && ballposX+13 < 125 && ballposY-13 < 195)

  {

    is_over = true;

  }

  

  //右上

  if(ballposX+13 > 515 && ballposX+13 < 640 && ballposY-13 < 395)

  {

    is_over = true;

  }

  if(ballposX+13 > 515 && ballposX+13 < 640 && ballposY+13 < 395)

  {

    is_over = true;

  }

  if(ballposX+13 > 515 && ballposX+13 < 640 && ballposY-13 < 395)

  {

    is_over = true;

  }

  if(ballposX-13 > 515 && ballposX-13 < 640 && ballposY-13 < 395)

  {

    is_over = true;

  }

  

  //中上

  if(ballposX+13 > 125 && ballposX+13 < 515 && ballposY-13 < 45)

  {

    is_over = true;

  }

  if(ballposX-13 > 125 && ballposX-13 < 515 && ballposY-13 < 45)

  {

    is_over = true;

  }

  

  //中下

  if(ballposX+13 > 125 && ballposX+13 < 640 && ballposY+13 > 435)

  {

    is_over = true;

  }

  if(ballposX-13 > 125 && ballposX-13 < 640 && ballposY-13 > 435)

  {

    is_over = true;

  }

  

  //左下2

  if(ballposX+13 > 125 && ballposX+13 < 275 && ballposY+13 > 285)

  {

    is_over = true;

  }

  if(ballposX-13 > 125 && ballposX-13 < 275 && ballposY+13 > 285)

  {

    is_over = true;

  }

  if(ballposX-13 > 125 && ballposX-13 < 275 && ballposY-13 > 285)

  {

    is_over = true;

  }

  

  //右下2

  if(ballposX+13 > 275 && ballposX+13 < 475 && ballposY+13 > 385)

  {

    is_over = true;

  }

  if(ballposX-13 > 275 && ballposX-13 < 475 && ballposY+13 > 385)

  {

    is_over = true;

  }

  if(ballposX-13 > 275 && ballposX-13 < 475 && ballposY-13 > 385)

  {

    is_over = true;

  }

  

  //右下2上面的

  if(ballposX+13 > 416 && ballposX+13 < 475 && ballposY-13 > 235)

  {

    is_over = true;

  }

  if(ballposX+13 > 416 && ballposX+13 < 475 && ballposY+13 > 235)

  {

    is_over = true;

  }

  if(ballposX-13 > 416 && ballposX-13 < 475 && ballposY+13 > 235)

  {

    is_over = true;

  }

  

  //中間

  if(ballposX+13 > 165 && ballposX+13 < 376 && ballposY-13 > 85 && ballposY-13 < 245)

  {

    is_over = true;

  }

  if(ballposX+13 > 165 && ballposX+13 < 376 && ballposY+13 > 85 && ballposY+13 < 245)

  {

    is_over = true;

  }

  if(ballposX-13 > 165 && ballposX-13 < 376 && ballposY+13 > 85 && ballposY+13 < 245)

  {

    is_over = true;

  }

  if(ballposX-13 > 165 && ballposX-13 < 376 && ballposY+13 > 85 && ballposY-13 < 245)

  {

    is_over = true;

  }

  

  //中間右

  if(ballposX+13 > 376 && ballposX+13 < 475 && ballposY-13 > 85 && ballposY-13 < 195)

  {

    is_over = true;

  }

  if(ballposX+13 > 376 && ballposX+13 < 475 && ballposY+13 > 85 && ballposY+13 < 195)

  {

    is_over = true;

  }

  if(ballposX-13 > 376 && ballposX-13 < 475 && ballposY+13 > 85 && ballposY+13 < 195)

  {

    is_over = true;

  }

  if(ballposX-13 > 376 && ballposX-13 < 475 && ballposY+13 > 85 && ballposY-13 < 195)

  {

    is_over = true;

  }

  

  //中間右下

  if(ballposX+13 > 315 && ballposX+13 < 376 && ballposY-13 > 245 && ballposY-13 < 345)

  {

    is_over = true;

  }

  if(ballposX+13 > 315 && ballposX+13 < 376 && ballposY+13 > 245 && ballposY+13 < 345)

  {

    is_over = true;

  }

  if(ballposX-13 > 315 && ballposX-13 < 376 && ballposY+13 > 245 && ballposY+13 < 345)

  {

    is_over = true;

  }

  if(ballposX-13 > 315 && ballposX-13 < 376 && ballposY+13 > 245 && ballposY-13 < 345)

  {

    is_over = true;

  }

  

  //寶石

  if(ballposX > 579 && ballposX < 601 && ballposY > 409 && ballposY < 421)

  {

    is_win = true;

    is_over = true;

  }

  if(ballposX > 579 && ballposX < 601 && ballposY > 409 && ballposY < 421)

  {

    is_win = true;

    is_over = true;

  }

  if(ballposX > 579 && ballposX < 601 && ballposY > 409 && ballposY < 421)

  {

    is_win = true;

    is_over = true;

  }

  if(ballposX > 579 && ballposX < 601 && ballposY > 409 && ballposY < 421)

  {

    is_win = true;

    is_over = true;

  }

  }


2022年1月3日 星期一

都在做作業

  都在做作業所以忘記寫部落格

沒注意老師講了什麼

有去教室上課當面問老師關於子彈碰撞的問題

跟FB範例的兩個方塊碰撞的程式不一樣

2021年12月27日 星期一

期末

 有去教室上課當面問老師關於子彈碰撞的問題

跟FB範例的兩個方塊碰撞的程式不一樣

我愛卯咪Week14

 

互動技術概論🎮


期末遊戲Day2
這禮拜開始寫程式,在聽完老師講解連續動圖後,我們寫好連續動圖的程式
PImage img,img1,img2,img3,img4,img5,img6,img7,img8,img9,img10,img11,img12,img13,img14,img15,
img16,img17;///宣告圖片
void setup(){
  size(400,600);
  img=loadImage("egg.png");///讀入圖片
  img1=loadImage("panda1.png");
  img2=loadImage("panda2.png");
  img3=loadImage("panda3.png");
  img4=loadImage("panda4.png");
  img5=loadImage("panda5.png");
  img6=loadImage("panda6.png");
  img7=loadImage("panda7.png");
  img8=loadImage("panda8.png");
  img9=loadImage("panda9.png");
  img10=loadImage("panda10.png");
  img11=loadImage("panda11.png");
  img12=loadImage("panda12.png");
  img13=loadImage("panda13.png");
  img14=loadImage("panda14.png");
  img15=loadImage("panda15.png");
  img16=loadImage("panda16.png");
  img17=loadImage("panda17.png");
  imageMode(CENTER);///圖片置中
}
讀入好照片後就可以處理連續動圖了
PImage img,img1,img2,img3,img4,img5,img6,img7,img8,img9,img10,img11,img12,img13,img14,img15,img16,img17;
int state=0,remainT=0,count=1800,count1=3000,count2=0,count3=0,x=200, y=300,win=0;
void setup(){
  size(400,600);
  img=loadImage("egg.png");
  img1=loadImage("panda1.png");
                    .
                    .
                    .
  imageMode(CENTER);
}
void draw(){
  count--;
  count1--;
  if(count==0) {state=1;count1=-1;}
  else if(count1==0) {state=3;count=-1;}
  else if(count==900) {state=0;}
  else if(count1==1500) state=2;
  if(win==5) state=10;
  if(count2==0)background(255);
  else background(#D6D4D4);
  //image( img, 0,0);
  image( img ,x,y);
  if(state==0){//餓了
    image( img1 ,x,y);
  }
  if(state==1){//餓死了
    image( img2 ,x,y);
  }
  if(state==2){//玩
    image( img3 ,x,y);
  }
  if(state==3){//無聊死了
    image( img4 ,x,y);
  }
  if(state==4){//吃
    remainT--;
    count3++;
    if(remainT>60){
      image( img5 ,x,y);
    }
    else{
      image( img6 ,x,y);
    }   
  }
  if(state==5){//吃死了
    remainT--;
    if(remainT>60){
      image( img7 ,x,y);
    }
    else{
      image( img8 ,x,y);
    }
  }
  if(state==6){//打球
    count3++;
    remainT--;
    if(remainT>60){
      image( img9 ,x,y);
    }
    else{
      image( img10 ,x,y);
    }
  }
  if(state==7){//吃球
    remainT--;
    if(remainT>60){
      image( img11 ,x,y);
    }
    else{
      image( img12 ,x,y);
    }
  }
  if(state==8){//洗澡
    remainT--;
    if(remainT>60){
      image( img13 ,x,y);
    }
    else{
      image( img14 ,x,y);
    }
  }
  if(state==9){//喝洗澡水
    remainT--;
    if(remainT>60){
      image( img15 ,x,y);
    }
    else{
      image( img16 ,x,y);
    }
  }
  if(state==10){//贏了
    image( img17 ,x,y);
  }
}
void mousePressed(){
  if(mouseX>=90&&mouseX<=160&&mouseX>=90){
    if(mouseY>10*50-25 && mouseY<10*50+50){
      if(count3>0){
        state=5;
        remainT=180;
        count=-1;
        count1=-1;
      }
      else if(state!=4&&state!=1&&state!=3&&state!=5&&state!=7){
        state=4;
        remainT=180;
        count=1800;
        win++;
      }
      else if(state==4){
        state=5;
        remainT=180;
        count=-1;
        count1=-1;
      }
    }
  }

圖片已經可以放上去了


這禮拜進度到這,但圖片內容稍改,所以下禮拜還要改一下圖



天文社社員招募中week14

       

期末作品進度4!


1.旋轉









程式如下:

int[][]grid={
  {1,0,0,0,0,0,0,0,0,0,0,1},//  {1,1,1,1,1,1,1,1,1,1,1,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,1,1,1,1,1,1,1,1,1,1,1}
};
int [][]L0={
  {1,0,0,0},
  {1,0,0,0},
  {1,1,0,0},
  {0,0,0,0}};
int [][]L1={
  {0,0,1,0},
  {1,1,1,0},
  {0,0,0,0},
  {0,0,0,0}};
int [][]L2={
  {1,1,0,0},
  {0,1,0,0},
  {0,1,0,0},
  {0,0,0,0}};
int [][]L3={
  {1,1,1,0},
  {1,0,0,0},
  {0,0,0,0},
  {0,0,0,0}};
int [][]O0={
  {1,1,0,0},
  {1,1,0,0},
  {0,0,0,0},
  {0,0,0,0}};
int [][]I0={
  {1,0,0,0},
  {1,0,0,0},
  {1,0,0,0},
  {1,0,0,0}};
int [][]I1={
  {1,1,1,1},
  {0,0,0,0},
  {0,0,0,0},
  {0,0,0,0}};
int [][]J0={
  {0,1,0,0},
  {0,1,0,0},
  {1,1,0,0},
  {0,0,0,0}};
int [][]J1={
  {1,0,0,0},
  {1,1,1,0},
  {0,0,0,0},
  {0,0,0,0}};
int [][]J2={
  {1,1,0,0},
  {1,0,0,0},
  {1,0,0,0},
  {0,0,0,0}};
int [][]J3={
  {1,1,1,0},
  {0,0,1,0},
  {0,0,0,0},
  {0,0,0,0}};
int [][]T0={
  {1,1,1,0},
  {0,1,0,0},
  {0,0,0,0},
  {0,0,0,0}};
int [][]T1={
  {0,1,0,0},
  {1,1,1,0},
  {0,0,0,0},
  {0,0,0,0}};
int [][]T2={
  {0,1,0,0},
  {1,1,0,0},
  {0,1,0,0},
  {0,0,0,0}};
int [][]T3={
  {1,0,0,0},
  {1,1,0,0},
  {1,0,0,0},
  {0,0,0,0}};
int [][]S0={
  {1,0,0,0},
  {1,1,0,0},
  {0,1,0,0},
  {0,0,0,0}};
int [][]S1={
  {0,1,1,0},
  {1,1,0,0},
  {0,0,0,0},
  {0,0,0,0}};
int [][]Z0={
  {1,1,0,0},
  {0,1,1,0},
  {0,0,0,0},
  {0,0,0,0}};
int [][]Z1={
  {0,1,0,0},
  {1,1,0,0},
  {1,0,0,0},
  {0,0,0,0}};
void testDeleteAndNext(){
  testDelete();
  nextShape=int(random(19));
  //if( random(2)<1 ) nextShape=1;
  //else if(random(2)<2) nextShape=6;
  //else nextShape=11;
  //nextShape=1;
  println(nextShape);
}
void testDelete(){
  for(int i=18;i>0;i--){//modified
    int bad=0;
    for(int j=1;j<11;j++){//modified
      if(grid[i][j]!=0)bad++;
    }
    if(bad==10){//這裡的 i,j有弄反了!!!
      for(int ii=i;ii>1;ii--){//有錯
        for(int j=1;j<11;j++)grid[ii][j]=grid[ii-1][j];
      }//這裡的 j<12才對,或是改用i,總之要想想!!!!
      i++;
    }
  }
}
int nextShape=0;

boolean L0safe(int x,int y){
  if(grid[y][x]==0 && grid[y+1][x]==0 && grid[y+2][x]==0 && grid[y+2][x+1]==0)return true;
  return false;
}
void L0(int x,int y){
  fill(255,165,79);
  if(L0safe(x,y) ){
    rect(25*x    ,25*y    ,25,25);
    rect(25*x    ,25*(y+1),25,25);
    rect(25*x    ,25*(y+2),25,25);
    rect(25*(x+1),25*(y+2),25,25);
  }
}

//int nextShape=7;
boolean L1safe(int x,int y){
  if(grid[y+1][x]==0 && grid[y+1][x+1]==0 && grid[y][x+2]==0 && grid[y+1][x+2]==0)return true;
  return false;
}
void L1(int x,int y){
  fill(255,165,79);
  if(L1safe(x,y) ){
    rect(25*x    ,25*(y+1),25,25);
    rect(25*(x+1),25*(y+1),25,25);
    rect(25*(x+2),25*y    ,25,25);
    rect(25*(x+2),25*(y+1),25,25);
  }
}

//int nextShape=13;
boolean L2safe(int x,int y){
  if(grid[y][x]==0 && grid[y+1][x+1]==0 && grid[y][x+1]==0 && grid[y+2][x+1]==0)return true;
  return false;
}
void L2(int x,int y){
  fill(255,165,79);
  if(L2safe(x,y) ){
    rect(25*x    ,25*y    ,25,25);
    rect(25*(x+1),25*(y+1),25,25);
    rect(25*(x+1),25*y    ,25,25);
    rect(25*(x+1),25*(y+2),25,25);
  }
}

//int nextShape=16;
boolean L3safe(int x,int y){
  if(grid[y][x]==0 && grid[y][x+1]==0 && grid[y][x+2]==0 && grid[y+1][x]==0)return true;
  return false;
}
void L3(int x,int y){
  fill(255,165,79);
  if(L3safe(x,y) ){
    rect(25*x    ,25*y    ,25,25);
    rect(25*(x+1),25*y    ,25,25);
    rect(25*(x+2),25*y    ,25,25);
    rect(25*x    ,25*(y+1),25,25);
  }
}

//int nextShape=1;
boolean Osafe(int x,int y){
  if(grid[y][x]==0 && grid[y+1][x+1]==0 && grid[y+1][x]==0 && grid[y][x+1]==0)return true;
  return false;
}
void O0(int x,int y){
  fill(238,230,133);
  if(Osafe(x,y) ){
    rect(25*x    ,25*y    ,25,25);
    rect(25*x    ,25*(y+1),25,25);
    rect(25*(x+1),25*y    ,25,25);
    rect(25*(x+1),25*(y+1),25,25);
  }
}

//int nextShape=2;
boolean I0safe(int x,int y){
  if(grid[y][x]==0 && grid[y][x+1]==0 && grid[y][x+2]==0 && grid[y][x+3]==0)return true;
  return false;
}
void I0(int x,int y){
  fill(176,226,255);
  if(I0safe(x,y) ){
    rect(25*x    ,25*y,25,25);
    rect(25*(x+1),25*y,25,25);
    rect(25*(x+2),25*y,25,25);
    rect(25*(x+3),25*y,25,25);
  }
}

//int nextShape=8;
boolean I1safe(int x,int y){
  if(grid[y][x]==0 && grid[y+1][x]==0 && grid[y+2][x]==0 && grid[y+3][x]==0)return true;
  return false;
}
void I1(int x,int y){
  fill(176,226,255);
  if(I1safe(x,y) ){
    rect(25*x    ,25*y,25,25);
    rect(25*x    ,25*(y+1),25,25);
    rect(25*x    ,25*(y+2),25,25);
    rect(25*x    ,25*(y+3),25,25);
  }
}

//int nextShape=3;
boolean J0safe(int x,int y){
  if(grid[y][x+1]==0 && grid[y+1][x+1]==0 && grid[y+2][x+1]==0 && grid[y+2][x]==0)return true;
  return false;
}
void J0(int x,int y){
  fill(106,90,205);
  if(J0safe(x,y) ){
    rect(25*x    ,25*(y+2),25,25);
    rect(25*(x+1),25*(y+1),25,25);
    rect(25*(x+1),25*(y+2),25,25);
    rect(25*(x+1),25*y,25,25);
  }
}

//int nextShape=9;
boolean J1safe(int x,int y){
  if(grid[y][x]==0 && grid[y+1][x]==0 && grid[y+1][x+1]==0 && grid[y+1][x+2]==0)return true;
  return false;
}
void J1(int x,int y){
  fill(106,90,205);
  if(J1safe(x,y) ){
    rect(25*x    ,25*y    ,25,25);
    rect(25*x    ,25*(y+1),25,25);
    rect(25*(x+1),25*(y+1),25,25);
    rect(25*(x+2),25*(y+1),25,25);
  }
}

//int nextShape=14;
boolean J2safe(int x,int y){
  if(grid[y][x]==0 && grid[y+2][x]==0 && grid[y+1][x]==0 && grid[y][x+1]==0)return true;
  return false;
}
void J2(int x,int y){
  fill(106,90,205);
  if(J2safe(x,y) ){
    rect(25*x    ,25*y    ,25,25);
    rect(25*x    ,25*(y+2),25,25);
    rect(25*x    ,25*(y+1),25,25);
    rect(25*(x+1),25*y,25,25);
  }
}

//int nextShape=17;
boolean J3safe(int x,int y){
  if(grid[y][x]==0 && grid[y+1][x+2]==0 && grid[y][x+1]==0 && grid[y][x+2]==0)return true;
  return false;
}
void J3(int x,int y){
  fill(106,90,205);
  if(J3safe(x,y) ){
    rect(25*x    ,25*y,25,25);
    rect(25*(x+2),25*(y+1),25,25);
    rect(25*(x+1),25*y,25,25);
    rect(25*(x+2),25*y,25,25);
  }
}

//int nextShape=17;
boolean T0safe(int x,int y){
  if(grid[y][x]==0 && grid[y][x+1]==0 && grid[y][x+2]==0 && grid[y+1][x+1]==0)return true;
  return false;
}
void T0(int x,int y){
  fill(205,181,205);
  if(T0safe(x,y) ){
    rect(25*x    ,25*y,25,25);
    rect(25*(x+1),25*y,25,25);
    rect(25*(x+2),25*y,25,25);
    rect(25*(x+1),25*(y+1),25,25);
  }
}

//int nextShape=10;
boolean T1safe(int x,int y){
  if(grid[y+1][x]==0 && grid[y+1][x+1]==0 && grid[y][x+2]==0 && grid[y+1][x+2]==0)return true;
  return false;
}
void T1(int x,int y){
  fill(205,181,205);
  if(T1safe(x,y) ){
    rect(25*(x+1),25*(y+1),25,25);
    rect(25*x    ,25*(y+1),25,25);
    rect(25*(x+1),25*y,25,25);
    rect(25*(x+2),25*(y+1),25,25);
  }
}
//int nextShape=15;
boolean T2safe(int x,int y){
  if(grid[y+1][x]==0 && grid[y][x+1]==0 && grid[y+1][x+1]==0 && grid[y+2][x+1]==0)return true;
  return false;
}
void T2(int x,int y){
  fill(205,181,205);
  if(T2safe(x,y) ){
    rect(25*x    ,25*(y+1),25,25);
    rect(25*(x+1),25*y,25,25);
    rect(25*(x+1),25*(y+1),25,25);
    rect(25*(x+1),25*(y+2),25,25);
  }
}

//int nextShape=18;
boolean T3safe(int x,int y){
  if(grid[y][x]==0 && grid[y+1][x]==0 && grid[y+2][x]==0 && grid[y+1][x+1]==0)return true;
  return false;
}
void T3(int x,int y){
  fill(205,181,205);
  if(T3safe(x,y) ){
    rect(25*x    ,25*y,25,25);
    rect(25*x    ,25*(y+1),25,25);
    rect(25*x    ,25*(y+2),25,25);
    rect(25*(x+1),25*(y+1),25,25);
  }
}

//int nextShape=5;
boolean S0safe(int x,int y){
  if(grid[y][x]==0 && grid[y+1][x]==0 && grid[y+1][x+1]==0 && grid[y+2][x+1]==0)return true;
  return false;
}
void S0(int x,int y){
  fill(193,255,193);
  if(S0safe(x,y) ){
    rect(25*x    ,25*y,25,25);
    rect(25*x    ,25*(y+1),25,25);
    rect(25*(x+1),25*(y+1),25,25);
    rect(25*(x+1),25*(y+2),25,25);
  }
}

//int nextShape=11;
boolean S1safe(int x,int y){
  if(grid[y][x+1]==0 && grid[y][x+2]==0 && grid[y+1][x]==0 && grid[y+1][x+1]==0)return true;
  return false;
}
void S1(int x,int y){
  fill(193,255,193);
  if(S1safe(x,y) ){
    rect(25*(x+1),25*y,25,25);
    rect(25*(x+2),25*y,25,25);
    rect(25*x    ,25*(y+1),25,25);
    rect(25*(x+1),25*(y+1),25,25);
  }
}

//int nextShape=6;
boolean Z0safe(int x,int y){
  if(grid[y][x]==0 && grid[y+1][x+2]==0 && grid[y][x+1]==0 && grid[y+1][x+1]==0)return true;
  return false;
}
void Z0(int x,int y){
  fill(250,128,124);
  if(Z0safe(x,y) ){
    rect(25*x    ,25*y    ,25,25);
    rect(25*(x+2),25*(y+1),25,25);
    rect(25*(x+1),25*y    ,25,25);
    rect(25*(x+1),25*(y+1),25,25);
  }
}

//int nextShape=12;
boolean Z1safe(int x,int y){
  if(grid[y+1][x]==0 && grid[y+2][x]==0 && grid[y][x+1]==0 && grid[y+1][x+1]==0)return true;
  return false;
}
void Z1(int x,int y){
  fill(250,128,124);
  if(Z1safe(x,y) ){
    rect(25*x    ,25*(y+1),25,25);
    rect(25*x    ,25*(y+2),25,25);
    rect(25*(x+1),25*y    ,25,25);
    rect(25*(x+1),25*(y+1),25,25);
  }
}

void setup(){
  size(300,500);
  nextShape=int(random(19));
 // println(nextShape);
}
int b=0;
float []vx={0,0,300,500};
int rot=0;
void draw(){
  background(0);
  if(nextShape==0)L0(nowX,nowY);
  else if(nextShape==1)O0(nowX,nowY);
  else if(nextShape==2)I0(nowX,nowY);
  else if(nextShape==3)J0(nowX,nowY);
  else if(nextShape==4)T0(nowX,nowY);
  else if(nextShape==5)S0(nowX,nowY);
  else if(nextShape==6)Z0(nowX,nowY);
  
  else if(nextShape==7)L1(nowX,nowY);
  else if(nextShape==8)I1(nowX,nowY);
  else if(nextShape==9)J1(nowX,nowY);
  else if(nextShape==10)T1(nowX,nowY);
  else if(nextShape==11)S1(nowX,nowY);
  else if(nextShape==12)Z1(nowX,nowY);
  
  else if(nextShape==13)L2(nowX,nowY);  
  else if(nextShape==14)J2(nowX,nowY);
  else if(nextShape==15)T2(nowX,nowY);
  
  else if(nextShape==16)L3(nowX,nowY);
  else if(nextShape==17)J3(nowX,nowY);
  else if(nextShape==18)T3(nowX,nowY);
  else if(nextShape==19)L1(nowX,nowY);
  
  for(int x=0;x<12;x++){
    for(int y=0;y<20;y++){
      if(grid[y][x]==1)fill(70,130,180);//wall
      else if(grid[y][x]==2)fill(250,128,124);
      else if(grid[y][x]==3 || grid[y][x]==10 || grid[y][x]==16 || grid[y][x]==19)fill(255,165,79); //orangeL
      else if(grid[y][x]==4)fill(238,230,133);//yellowO
      else if(grid[y][x]==5 || grid[y][x]==11)fill(176,226,255);//blueI
      else if(grid[y][x]==6 || grid[y][x]==12 || grid[y][x]==17 || grid[y][x]==20)fill(106,90,205);//deepblueJ
      else if(grid[y][x]==7 || grid[y][x]==13 || grid[y][x]==18 || grid[y][x]==21)fill(205,181,205);//purpleT
      else if(grid[y][x]==8 || grid[y][x]==14)fill(193,255,193);//greenS
      else if(grid[y][x]==9 || grid[y][x]==15)fill(250,128,124);//pinkZ
      else fill(0);
      rect(x*25,y*25,25,25);
      if(x>300)x=-x;
      if(x<0)x=-x; 
    }
  }
  if(rot==0||nextShape==0){
    L0(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==0 && L0safe(nowX,nowY+1))nowY++;
      else{        
        grid[nowY][nowX]=3;
        grid[nowY+1][nowX]=3;
        grid[nowY+2][nowX]=3;
        grid[nowY+2][nowX+1]=3;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==0||rot==1||rot==2||rot==3||nextShape==1){
    O0(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==1 && Osafe(nowX,nowY+1))nowY++;
      else{      
        grid[nowY][nowX]=4;
        grid[nowY+1][nowX]=4;
        grid[nowY][nowX+1]=4;
        grid[nowY+1][nowX+1]=4;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==0||rot==2||nextShape==2){
    I0(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==2 && I0safe(nowX,nowY+1))nowY++;
      else{      
        grid[nowY][nowX]=5;
        grid[nowY][nowX+1]=5;
        grid[nowY][nowX+2]=5;
        grid[nowY][nowX+3]=5;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==0||nextShape==3){
    J0(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==3 && J0safe(nowX,nowY+1))nowY++;
      else{      
        grid[nowY+2][nowX]=6;
        grid[nowY+1][nowX+1]=6;
        grid[nowY+2][nowX+1]=6;
        grid[nowY][nowX+1]=6;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==0||nextShape==4){
    T0(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==4 && T0safe(nowX,nowY+1))nowY++;
      else{      
        grid[nowY][nowX]=7;
        grid[nowY][nowX+1]=7;
        grid[nowY][nowX+2]=7;
        grid[nowY+1][nowX+1]=7;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==0||rot==2||nextShape==5){
    S0(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==5 && S0safe(nowX,nowY+1))nowY++;
      else{      
        grid[nowY][nowX]=8;
        grid[nowY+1][nowX]=8;
        grid[nowY+1][nowX+1]=8;
        grid[nowY+2][nowX+1]=8;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==0||rot==2||nextShape==6){
    Z0(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==6 && Z0safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY][nowX]=9;
        grid[nowY+1][nowX+2]=9;
        grid[nowY][nowX+1]=9;
        grid[nowY+1][nowX+1]=9;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==1||nextShape==7){
    L1(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==7 && L1safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY+1][nowX]=10;
        grid[nowY+1][nowX+1]=10;
        grid[nowY][nowX+2]=10;
        grid[nowY+1][nowX+2]=10;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==1||rot==3||nextShape==8){
    I1(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==8 && I1safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY+3][nowX]=11;
        grid[nowY+2][nowX]=11;
        grid[nowY+1][nowX]=11;
        grid[nowY][nowX]=11;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==1||nextShape==9){
    J1(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==9 && J1safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY][nowX]=12;
        grid[nowY+1][nowX]=12;
        grid[nowY+1][nowX+1]=12;
        grid[nowY+1][nowX+2]=12;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  if(rot==1||nextShape==10){
    T1(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==10 && T1safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY+1][nowX+1]=13;
        grid[nowY+1][nowX]=13;
        grid[nowY][nowX+1]=13;
        grid[nowY+1][nowX+2]=13;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==1||rot==3||nextShape==11){
    S1(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==11 && S1safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY][nowX+1]=14;
        grid[nowY][nowX+2]=14;
        grid[nowY+1][nowX]=14;
        grid[nowY+1][nowX+1]=14;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  if(rot==1||rot==3||nextShape==12){
    Z1(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==12 && Z1safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY+1][nowX]=15;
        grid[nowY+2][nowX]=15;
        grid[nowY][nowX+1]=15;
        grid[nowY+1][nowX+1]=15;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==2||nextShape==13){
    L2(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==13 && L2safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY][nowX]=16;
        grid[nowY+1][nowX+1]=16;
        grid[nowY][nowX+1]=16;
        grid[nowY+2][nowX+1]=16;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==2||nextShape==14){
    J2(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==14 && J2safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY][nowX]=17;
        grid[nowY+2][nowX]=17;
        grid[nowY+1][nowX]=17;
        grid[nowY][nowX+1]=17;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==2||nextShape==15){
    T2(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==15 && T2safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY+1][nowX]=18;
        grid[nowY][nowX+1]=18;
        grid[nowY+1][nowX+1]=18;
        grid[nowY+2][nowX+1]=18;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==3||nextShape==16){
    L3(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==16 && L3safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY][nowX]=19;
        grid[nowY][nowX+1]=19;
        grid[nowY][nowX+2]=19;
        grid[nowY+1][nowX]=19;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==3||nextShape==17){
    J3(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==17 && J3safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY][nowX]=20;
        grid[nowY+1][nowX+2]=20;
        grid[nowY][nowX+1]=20;
        grid[nowY][nowX+2]=20;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==3||nextShape==18){
    T3(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==18 && T3safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY][nowX]=21;
        grid[nowY+1][nowX]=21;
        grid[nowY+2][nowX]=21;
        grid[nowY+1][nowX+1]=21;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
}
int nowX=6,nowY=1;
void keyPressed(){
  // if(keyCode==RIGHT && testSafe( nowShape, nowX+1, nowY, nowAngle)==true ){ b=3; nowX++; } 
  if(keyCode==RIGHT && grid[nowY][nowX+1]==0 ){ b=3; nowX++; }
  if(keyCode==LEFT && grid[nowY][nowX-1]==0 ) { b=2; nowX--; }
  if(keyCode==UP)rot=(rot+1)%4;
  if(keyCode==DOWN){ b=0; nowY++; }
}


2.剩下game over




程式如下:

int[][]grid={
  {1,0,0,0,0,0,0,0,0,0,0,1},//  {1,1,1,1,1,1,1,1,1,1,1,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,0,0,0,0,0,0,0,0,0,0,1},
  {1,1,1,1,1,1,1,1,1,1,1,1}
};
int [][]L0={
  {1,0,0,0},
  {1,0,0,0},
  {1,1,0,0},
  {0,0,0,0}};
int [][]L1={
  {0,0,1,0},
  {1,1,1,0},
  {0,0,0,0},
  {0,0,0,0}};
int [][]L2={
  {1,1,0,0},
  {0,1,0,0},
  {0,1,0,0},
  {0,0,0,0}};
int [][]L3={
  {1,1,1,0},
  {1,0,0,0},
  {0,0,0,0},
  {0,0,0,0}};
int [][]O0={
  {1,1,0,0},
  {1,1,0,0},
  {0,0,0,0},
  {0,0,0,0}};
int [][]I0={
  {1,0,0,0},
  {1,0,0,0},
  {1,0,0,0},
  {1,0,0,0}};
int [][]I1={
  {1,1,1,1},
  {0,0,0,0},
  {0,0,0,0},
  {0,0,0,0}};
int [][]J0={
  {0,1,0,0},
  {0,1,0,0},
  {1,1,0,0},
  {0,0,0,0}};
int [][]J1={
  {1,0,0,0},
  {1,1,1,0},
  {0,0,0,0},
  {0,0,0,0}};
int [][]J2={
  {1,1,0,0},
  {1,0,0,0},
  {1,0,0,0},
  {0,0,0,0}};
int [][]J3={
  {1,1,1,0},
  {0,0,1,0},
  {0,0,0,0},
  {0,0,0,0}};
int [][]T0={
  {1,1,1,0},
  {0,1,0,0},
  {0,0,0,0},
  {0,0,0,0}};
int [][]T1={
  {0,1,0,0},
  {1,1,1,0},
  {0,0,0,0},
  {0,0,0,0}};
int [][]T2={
  {0,1,0,0},
  {1,1,0,0},
  {0,1,0,0},
  {0,0,0,0}};
int [][]T3={
  {1,0,0,0},
  {1,1,0,0},
  {1,0,0,0},
  {0,0,0,0}};
int [][]S0={
  {1,0,0,0},
  {1,1,0,0},
  {0,1,0,0},
  {0,0,0,0}};
int [][]S1={
  {0,1,1,0},
  {1,1,0,0},
  {0,0,0,0},
  {0,0,0,0}};
int [][]Z0={
  {1,1,0,0},
  {0,1,1,0},
  {0,0,0,0},
  {0,0,0,0}};
int [][]Z1={
  {0,1,0,0},
  {1,1,0,0},
  {1,0,0,0},
  {0,0,0,0}};
  
void testDeleteAndNext(){
  testDelete();
  nextShape=int(random(6));
  //if( random(2)<1 ) nextShape=1;
  //else if(random(2)<2) nextShape=6;
  //else nextShape=11;
  //nextShape=1;
  println(nextShape);
}
void testDelete(){
  for(int i=18;i>0;i--){//modified
    int bad=0;
    for(int j=1;j<11;j++){//modified
      if(grid[i][j]!=0)bad++;
    }
    if(bad==10){//這裡的 i,j有弄反了!!!
      for(int ii=i;ii>1;ii--){//有錯
        for(int j=1;j<11;j++)grid[ii][j]=grid[ii-1][j];
      }//這裡的 j<12才對,或是改用i,總之要想想!!!!
      i++;
    }
  }
}
int nextShape=0;

boolean L0safe(int x,int y){
  if(grid[y][x]==0 && grid[y+1][x]==0 && grid[y+2][x]==0 && grid[y+2][x+1]==0)return true;
  return false;
}
void L0(int x,int y){
  fill(255,165,79);
  if(L0safe(x,y) ){
    rect(25*x    ,25*y    ,25,25);
    rect(25*x    ,25*(y+1),25,25);
    rect(25*x    ,25*(y+2),25,25);
    rect(25*(x+1),25*(y+2),25,25);
  }
}

//int nextShape=7;
boolean L1safe(int x,int y){
  if(grid[y+1][x]==0 && grid[y+1][x+1]==0 && grid[y][x+2]==0 && grid[y+1][x+2]==0)return true;
  return false;
}
void L1(int x,int y){
  fill(255,165,79);
  if(L1safe(x,y) ){
    rect(25*x    ,25*(y+1),25,25);
    rect(25*(x+1),25*(y+1),25,25);
    rect(25*(x+2),25*y    ,25,25);
    rect(25*(x+2),25*(y+1),25,25);
  }
}

//int nextShape=13;
boolean L2safe(int x,int y){
  if(grid[y][x]==0 && grid[y+1][x+1]==0 && grid[y][x+1]==0 && grid[y+2][x+1]==0)return true;
  return false;
}
void L2(int x,int y){
  fill(255,165,79);
  if(L2safe(x,y) ){
    rect(25*x    ,25*y    ,25,25);
    rect(25*(x+1),25*(y+1),25,25);
    rect(25*(x+1),25*y    ,25,25);
    rect(25*(x+1),25*(y+2),25,25);
  }
}

//int nextShape=16;
boolean L3safe(int x,int y){
  if(grid[y][x]==0 && grid[y][x+1]==0 && grid[y][x+2]==0 && grid[y+1][x]==0)return true;
  return false;
}
void L3(int x,int y){
  fill(255,165,79);
  if(L3safe(x,y) ){
    rect(25*x    ,25*y    ,25,25);
    rect(25*(x+1),25*y    ,25,25);
    rect(25*(x+2),25*y    ,25,25);
    rect(25*x    ,25*(y+1),25,25);
  }
}

//int nextShape=1;
boolean Osafe(int x,int y){
  if(grid[y][x]==0 && grid[y+1][x+1]==0 && grid[y+1][x]==0 && grid[y][x+1]==0)return true;
  return false;
}
void O0(int x,int y){
  fill(238,230,133);
  if(Osafe(x,y) ){
    rect(25*x    ,25*y    ,25,25);
    rect(25*x    ,25*(y+1),25,25);
    rect(25*(x+1),25*y    ,25,25);
    rect(25*(x+1),25*(y+1),25,25);
  }
}

//int nextShape=2;
boolean I0safe(int x,int y){
  if(grid[y][x]==0 && grid[y][x+1]==0 && grid[y][x+2]==0 && grid[y][x+3]==0)return true;
  return false;
}
void I0(int x,int y){
  fill(176,226,255);
  if(I0safe(x,y) ){
    rect(25*x    ,25*y,25,25);
    rect(25*(x+1),25*y,25,25);
    rect(25*(x+2),25*y,25,25);
    rect(25*(x+3),25*y,25,25);
  }
}

//int nextShape=8;
boolean I1safe(int x,int y){
  if(grid[y][x]==0 && grid[y+1][x]==0 && grid[y+2][x]==0 && grid[y+3][x]==0)return true;
  return false;
}
void I1(int x,int y){
  fill(176,226,255);
  if(I1safe(x,y) ){
    rect(25*x    ,25*y,25,25);
    rect(25*x    ,25*(y+1),25,25);
    rect(25*x    ,25*(y+2),25,25);
    rect(25*x    ,25*(y+3),25,25);
  }
}

//int nextShape=3;
boolean J0safe(int x,int y){
  if(grid[y][x+1]==0 && grid[y+1][x+1]==0 && grid[y+2][x+1]==0 && grid[y+2][x]==0)return true;
  return false;
}
void J0(int x,int y){
  fill(106,90,205);
  if(J0safe(x,y) ){
    rect(25*x    ,25*(y+2),25,25);
    rect(25*(x+1),25*(y+1),25,25);
    rect(25*(x+1),25*(y+2),25,25);
    rect(25*(x+1),25*y,25,25);
  }
}

//int nextShape=9;
boolean J1safe(int x,int y){
  if(grid[y][x]==0 && grid[y+1][x]==0 && grid[y+1][x+1]==0 && grid[y+1][x+2]==0)return true;
  return false;
}
void J1(int x,int y){
  fill(106,90,205);
  if(J1safe(x,y) ){
    rect(25*x    ,25*y    ,25,25);
    rect(25*x    ,25*(y+1),25,25);
    rect(25*(x+1),25*(y+1),25,25);
    rect(25*(x+2),25*(y+1),25,25);
  }
}

//int nextShape=14;
boolean J2safe(int x,int y){
  if(grid[y][x]==0 && grid[y+2][x]==0 && grid[y+1][x]==0 && grid[y][x+1]==0)return true;
  return false;
}
void J2(int x,int y){
  fill(106,90,205);
  if(J2safe(x,y) ){
    rect(25*x    ,25*y    ,25,25);
    rect(25*x    ,25*(y+2),25,25);
    rect(25*x    ,25*(y+1),25,25);
    rect(25*(x+1),25*y,25,25);
  }
}

//int nextShape=17;
boolean J3safe(int x,int y){
  if(grid[y][x]==0 && grid[y+1][x+2]==0 && grid[y][x+1]==0 && grid[y][x+2]==0)return true;
  return false;
}
void J3(int x,int y){
  fill(106,90,205);
  if(J3safe(x,y) ){
    rect(25*x    ,25*y,25,25);
    rect(25*(x+2),25*(y+1),25,25);
    rect(25*(x+1),25*y,25,25);
    rect(25*(x+2),25*y,25,25);
  }
}

//int nextShape=17;
boolean T0safe(int x,int y){
  if(grid[y][x]==0 && grid[y][x+1]==0 && grid[y][x+2]==0 && grid[y+1][x+1]==0)return true;
  return false;
}
void T0(int x,int y){
  fill(205,181,205);
  if(T0safe(x,y) ){
    rect(25*x    ,25*y,25,25);
    rect(25*(x+1),25*y,25,25);
    rect(25*(x+2),25*y,25,25);
    rect(25*(x+1),25*(y+1),25,25);
  }
}

//int nextShape=10;
boolean T1safe(int x,int y){
  if(grid[y+1][x]==0 && grid[y+1][x+1]==0 && grid[y][x+2]==0 && grid[y+1][x+2]==0)return true;
  return false;
}
void T1(int x,int y){
  fill(205,181,205);
  if(T1safe(x,y) ){
    rect(25*(x+1),25*(y+1),25,25);
    rect(25*x    ,25*(y+1),25,25);
    rect(25*(x+1),25*y,25,25);
    rect(25*(x+2),25*(y+1),25,25);
  }
}
//int nextShape=15;
boolean T2safe(int x,int y){
  if(grid[y+1][x]==0 && grid[y][x+1]==0 && grid[y+1][x+1]==0 && grid[y+2][x+1]==0)return true;
  return false;
}
void T2(int x,int y){
  fill(205,181,205);
  if(T2safe(x,y) ){
    rect(25*x    ,25*(y+1),25,25);
    rect(25*(x+1),25*y,25,25);
    rect(25*(x+1),25*(y+1),25,25);
    rect(25*(x+1),25*(y+2),25,25);
  }
}

//int nextShape=18;
boolean T3safe(int x,int y){
  if(grid[y][x]==0 && grid[y+1][x]==0 && grid[y+2][x]==0 && grid[y+1][x+1]==0)return true;
  return false;
}
void T3(int x,int y){
  fill(205,181,205);
  if(T3safe(x,y) ){
    rect(25*x    ,25*y,25,25);
    rect(25*x    ,25*(y+1),25,25);
    rect(25*x    ,25*(y+2),25,25);
    rect(25*(x+1),25*(y+1),25,25);
  }
}

//int nextShape=5;
boolean S0safe(int x,int y){
  if(grid[y][x]==0 && grid[y+1][x]==0 && grid[y+1][x+1]==0 && grid[y+2][x+1]==0)return true;
  return false;
}
void S0(int x,int y){
  fill(193,255,193);
  if(S0safe(x,y) ){
    rect(25*x    ,25*y,25,25);
    rect(25*x    ,25*(y+1),25,25);
    rect(25*(x+1),25*(y+1),25,25);
    rect(25*(x+1),25*(y+2),25,25);
  }
}

//int nextShape=11;
boolean S1safe(int x,int y){
  if(grid[y][x+1]==0 && grid[y][x+2]==0 && grid[y+1][x]==0 && grid[y+1][x+1]==0)return true;
  return false;
}
void S1(int x,int y){
  fill(193,255,193);
  if(S1safe(x,y) ){
    rect(25*(x+1),25*y,25,25);
    rect(25*(x+2),25*y,25,25);
    rect(25*x    ,25*(y+1),25,25);
    rect(25*(x+1),25*(y+1),25,25);
  }
}

//int nextShape=6;
boolean Z0safe(int x,int y){
  if(grid[y][x]==0 && grid[y+1][x+2]==0 && grid[y][x+1]==0 && grid[y+1][x+1]==0)return true;
  return false;
}
void Z0(int x,int y){
  fill(250,128,124);
  if(Z0safe(x,y) ){
    rect(25*x    ,25*y    ,25,25);
    rect(25*(x+2),25*(y+1),25,25);
    rect(25*(x+1),25*y    ,25,25);
    rect(25*(x+1),25*(y+1),25,25);
  }
}

//int nextShape=12;
boolean Z1safe(int x,int y){
  if(grid[y+1][x]==0 && grid[y+2][x]==0 && grid[y][x+1]==0 && grid[y+1][x+1]==0)return true;
  return false;
}
void Z1(int x,int y){
  fill(250,128,124);
  if(Z1safe(x,y) ){
    rect(25*x    ,25*(y+1),25,25);
    rect(25*x    ,25*(y+2),25,25);
    rect(25*(x+1),25*y    ,25,25);
    rect(25*(x+1),25*(y+1),25,25);
  }
}

void setup(){
  size(300,500);
  nextShape=int(random(6));
 // println(nextShape);
}
int b=0;
float []vx={0,0,300,500};
int rot=0;
void draw(){
  background(0);
  if(nextShape==0)L0(nowX,nowY);
  else if(nextShape==1)O0(nowX,nowY);
  else if(nextShape==2)I0(nowX,nowY);
  else if(nextShape==3)J0(nowX,nowY);
  else if(nextShape==4)T0(nowX,nowY);
  else if(nextShape==5)S0(nowX,nowY);
  else if(nextShape==6)Z0(nowX,nowY);
  
  //else if(nextShape==7)L1(nowX,nowY);
  //else if(nextShape==8)I1(nowX,nowY);
  //else if(nextShape==9)J1(nowX,nowY);
  //else if(nextShape==10)T1(nowX,nowY);
  //else if(nextShape==11)S1(nowX,nowY);
  //else if(nextShape==12)Z1(nowX,nowY);
  
  //else if(nextShape==13)L2(nowX,nowY);  
  //else if(nextShape==14)J2(nowX,nowY);
  //else if(nextShape==15)T2(nowX,nowY);
  
  //else if(nextShape==16)L3(nowX,nowY);
  //else if(nextShape==17)J3(nowX,nowY);
  //else if(nextShape==18)T3(nowX,nowY);
  //else if(nextShape==19)L1(nowX,nowY);
  
  for(int x=0;x<12;x++){
    for(int y=0;y<20;y++){
      if(grid[y][x]==1)fill(70,130,180);//wall
      else if(grid[y][x]==2)fill(250,128,124);
      else if(grid[y][x]==3 || grid[y][x]==10 || grid[y][x]==16 || grid[y][x]==19)fill(255,165,79); //orangeL
      else if(grid[y][x]==4)fill(238,230,133);//yellowO
      else if(grid[y][x]==5 || grid[y][x]==11)fill(176,226,255);//blueI
      else if(grid[y][x]==6 || grid[y][x]==12 || grid[y][x]==17 || grid[y][x]==20)fill(106,90,205);//deepblueJ
      else if(grid[y][x]==7 || grid[y][x]==13 || grid[y][x]==18 || grid[y][x]==21)fill(205,181,205);//purpleT
      else if(grid[y][x]==8 || grid[y][x]==14)fill(193,255,193);//greenS
      else if(grid[y][x]==9 || grid[y][x]==15)fill(250,128,124);//pinkZ
      else fill(0);
      rect(x*25,y*25,25,25);
      if(x>300)x=-x;
      if(x<0)x=-x; 
    }
  }
  if(rot==0&&nextShape==0){
    L0(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==0 && L0safe(nowX,nowY+1))nowY++;
      else{        
        grid[nowY][nowX]=3;
        grid[nowY+1][nowX]=3;
        grid[nowY+2][nowX]=3;
        grid[nowY+2][nowX+1]=3;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==0&&nextShape==1||rot==1&&nextShape==1||rot==2&&nextShape==1||rot==3&&nextShape==1){
    O0(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==1 && Osafe(nowX,nowY+1))nowY++;
      else{      
        grid[nowY][nowX]=4;
        grid[nowY+1][nowX]=4;
        grid[nowY][nowX+1]=4;
        grid[nowY+1][nowX+1]=4;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==0&&nextShape==2||rot==2&&nextShape==2){
    I0(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==2 && I0safe(nowX,nowY+1))nowY++;
      else{      
        grid[nowY][nowX]=5;
        grid[nowY][nowX+1]=5;
        grid[nowY][nowX+2]=5;
        grid[nowY][nowX+3]=5;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==0&&nextShape==3){
    J0(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==3 && J0safe(nowX,nowY+1))nowY++;
      else{      
        grid[nowY+2][nowX]=6;
        grid[nowY+1][nowX+1]=6;
        grid[nowY+2][nowX+1]=6;
        grid[nowY][nowX+1]=6;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==0&&nextShape==4){
    T0(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==4 && T0safe(nowX,nowY+1))nowY++;
      else{      
        grid[nowY][nowX]=7;
        grid[nowY][nowX+1]=7;
        grid[nowY][nowX+2]=7;
        grid[nowY+1][nowX+1]=7;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==0&&nextShape==5||rot==2&&nextShape==5){
    S0(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==5 && S0safe(nowX,nowY+1))nowY++;
      else{      
        grid[nowY][nowX]=8;
        grid[nowY+1][nowX]=8;
        grid[nowY+1][nowX+1]=8;
        grid[nowY+2][nowX+1]=8;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==0&&nextShape==6||rot==2&&nextShape==6){
    Z0(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==6 && Z0safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY][nowX]=9;
        grid[nowY+1][nowX+2]=9;
        grid[nowY][nowX+1]=9;
        grid[nowY+1][nowX+1]=9;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==1&&nextShape==0){
    L1(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==0 && L1safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY+1][nowX]=10;
        grid[nowY+1][nowX+1]=10;
        grid[nowY][nowX+2]=10;
        grid[nowY+1][nowX+2]=10;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==1&&nextShape==2||rot==3&&nextShape==2){
    I1(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==2 && I1safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY+3][nowX]=11;
        grid[nowY+2][nowX]=11;
        grid[nowY+1][nowX]=11;
        grid[nowY][nowX]=11;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==1&&nextShape==3){
    J1(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==3 && J1safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY][nowX]=12;
        grid[nowY+1][nowX]=12;
        grid[nowY+1][nowX+1]=12;
        grid[nowY+1][nowX+2]=12;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  if(rot==1&&nextShape==4){
    T1(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==4 && T1safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY+1][nowX+1]=13;
        grid[nowY+1][nowX]=13;
        grid[nowY][nowX+1]=13;
        grid[nowY+1][nowX+2]=13;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==1&&nextShape==5||rot==3&&nextShape==5){
    S1(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==5 && S1safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY][nowX+1]=14;
        grid[nowY][nowX+2]=14;
        grid[nowY+1][nowX]=14;
        grid[nowY+1][nowX+1]=14;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  if(rot==1&&nextShape==6||rot==3&&nextShape==6){
    Z1(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==6 && Z1safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY+1][nowX]=15;
        grid[nowY+2][nowX]=15;
        grid[nowY][nowX+1]=15;
        grid[nowY+1][nowX+1]=15;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==2&&nextShape==0){
    L2(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==0 && L2safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY][nowX]=16;
        grid[nowY+1][nowX+1]=16;
        grid[nowY][nowX+1]=16;
        grid[nowY+2][nowX+1]=16;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==2&&nextShape==3){
    J2(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==3 && J2safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY][nowX]=17;
        grid[nowY+2][nowX]=17;
        grid[nowY+1][nowX]=17;
        grid[nowY][nowX+1]=17;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==2&&nextShape==4){
    T2(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==4 && T2safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY+1][nowX]=18;
        grid[nowY][nowX+1]=18;
        grid[nowY+1][nowX+1]=18;
        grid[nowY+2][nowX+1]=18;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==3&&nextShape==0){
    L3(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==0 && L3safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY][nowX]=19;
        grid[nowY][nowX+1]=19;
        grid[nowY][nowX+2]=19;
        grid[nowY+1][nowX]=19;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==3&&nextShape==3){
    J3(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==3 && J3safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY][nowX]=20;
        grid[nowY+1][nowX+2]=20;
        grid[nowY][nowX+1]=20;
        grid[nowY][nowX+2]=20;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
  else if(rot==3&&nextShape==4){
    T3(nowX,nowY);
    if(frameCount%20==0){
      if(nextShape==4 && T3safe(nowX,nowY+1))nowY++;
      else{
        grid[nowY][nowX]=21;
        grid[nowY+1][nowX]=21;
        grid[nowY+2][nowX]=21;
        grid[nowY+1][nowX+1]=21;
        nowX=6;nowY=1;
        testDeleteAndNext();
      }
    }
  }
}
int nowX=6,nowY=1;
void keyPressed(){
  // if(keyCode==RIGHT && testSafe( nowShape, nowX+1, nowY, nowAngle)==true ){ b=3; nowX++; } 
  if(keyCode==RIGHT && grid[nowY][nowX+1]==0 ){ b=3; nowX++; }
  if(keyCode==LEFT && grid[nowY][nowX-1]==0 ) { b=2; nowX--; }
  if(keyCode==UP)rot=(rot+1)%4;
  if(keyCode==DOWN){ b=0; nowY++; }
}



顏色資料庫



   (70,130,180)

  (250,128,124)

 (255,165,79)

(176,226,255)

 (106,90,205)

(205,181,205)

(193,255,193)

(250,128,124)

 (238,230,133)



🍮有751行囉🍩