2017年11月20日 星期一

Week10 是賴小沫的_期中作品展示

✎期中作品

👀部分程式碼

//匯入套件
import ddf.minim.*;
Minim minim;
AudioPlayer player;

//宣告各種變數
int [][]puzzle=new int[20][20];
int [][]touch=new int[20][20];
int [][]check=new int [20][20];
//boolean bG=false;
//PrintWriter output;
int level;
int count;
int stage=0;
int bad=0;
PImage imgBack,imgL1,imgL2,imgL3,imgL4,imgL5,imgL6;

//初始狀態
void setup(){
 size(600,800);
 //音樂播放
 minim=new Minim(this);
 player=minim.loadFile("music.mp3",2048);
 player.play();
 player.loop();

 count=11;  //計算生命值
 imgBack=loadImage("back.jpg");
 imgL1=loadImage("a1.jpg");
 imgL2=loadImage("a2.jpg");
 imgL3=loadImage("a3.jpg");
 imgL4=loadImage("a6.jpg");
 imgL5=loadImage("a4.jpg");
 imgL6=loadImage("a5.jpg");
 level=1;
 //output = createWriter("ans.txt");  //create a puzzle
}

void draw(){
  //開始畫面
  if(stage==0){
    background(255);
    image(imgBack,0,0,600,800);
    textSize(100);
    fill(0);
    text("Start\nClick",160,250);
  }
  //遊戲畫面
  else if(stage==1){
    //第一關設定
    if(level==1){
      bad=0;
      image(imgBack,0,0,600,800);
      textSize(30);
      text("count="+count,350,550);
      for(int i=0;i<20;i++){
        for(int j=0;j<20;j++){
          if(touch[j][i]==0)fill(255);
          else if(puzzle[j][i]==0&& touch[j][i]==1)fill(255,0,0);
          else if(puzzle[j][i]==1&& touch[j][i]==1)fill(100);
          rect(100+20*j,100+20*i,20,20);
        }
      }
      puzzle=l1;
      //column
      textSize(15);fill(0);text("3 3",75,115);
      textSize(15);fill(0);text("5 5",75,135);
      textSize(15);fill(0);text("7 7",75,155);
      textSize(15);fill(0);text("5 5",75,175);
      textSize(15);fill(0);text("2 2 1 2 2",32,195);
      textSize(15);fill(0);text("1 1 1 3 1 1 1",5,215);
      textSize(15);fill(0);text("5 1 5",61,235);
      textSize(15);fill(0);text("1 1 1 3 1 1 1",5,255);
      textSize(15);fill(0);text("1 1 7 1 1",32,275);
      textSize(15);fill(0);text("15",80,295);
      textSize(15);fill(0);text("17",80,315);
      textSize(15);fill(0);text("17",80,335);
      textSize(15);fill(0);text("7 1 7",61,355);
      textSize(15);fill(0);text("7 1 7",61,375);
      textSize(15);fill(0);text("19",80,395);
      textSize(15);fill(0);text("7 1 7",61,415);
      textSize(15);fill(0);text("7 1 7",61,435);
      textSize(15);fill(0);text("7 1 7",61,455);
      textSize(15);fill(0);text("19",80,475);
      textSize(15);fill(0);text("19",80,495);
      //row
      textSize(15);fill(0);text("0",105,97);
      textSize(15);fill(0);text("8",125,97);
      textSize(15);fill(0);text(" 1\n10",140,73);
      textSize(15);fill(0);text("19",160,97);
      textSize(15);fill(0);text(" 5\n 1\n11",180,49);
      textSize(15);fill(0);text(" 4\n15",200,73);
      textSize(15);fill(0);text(" 5\n 1\n11",220,49);
      textSize(15);fill(0);text("19",240,97);
      textSize(15);fill(0);text(" 1\n 4\n 1\n 2",260,25);
      textSize(15);fill(0);text(" 1\n 5\n 1\n 2",280,25);
      textSize(15);fill(0);text("16",300,97);
      textSize(15);fill(0);text(" 1\n 5\n 1\n 2",320,25);
      textSize(15);fill(0);text(" 1\n 4\n 1\n 2",340,25);
      textSize(15);fill(0);text("19",360,97);
      textSize(15);fill(0);text(" 5\n 1\n11",380,49);
      textSize(15);fill(0);text(" 4\n15",400,73);
      textSize(15);fill(0);text(" 5\n 1\n11",420,49);
      textSize(15);fill(0);text("19",440,97);
      textSize(15);fill(0);text(" 1\n10",460,73);
      textSize(15);fill(0);text("8",485,97);
      if(count<=0) stage=2;  //挑戰失敗
      //比對是否與答案相同
      for(int i=0;i<20;i++){
        for(int j=0;j<20;j++){
          if(puzzle[i][j]==1 && touch[i][j]==1) check[i][j]=1;
        }
      }
      if(puzzle.length!=check.length) bad=1;
      for(int i=0;i<puzzle.length && i<check.length;i++){
        for(int j=0;j<puzzle.length && j<check.length;j++){
          if(puzzle[i][j]!=check[i][j]) bad++;
        }
      }

      if(bad==0) stage=3;  //挑戰成功
    }
  }
  //失敗畫面
  else if(stage==2){
    background(255);
    textSize(100);
    fill(255,0,0);
    text("Game Over",30,400);
  }
  //成功畫面
  else if(stage==3){
    background(255);
    if(level==1) image(imgL1,150,0,300,300);
    else if(level==2) image(imgL2,150,0,300,300);
    else if(level==3) image(imgL3,150,0,300,300);
    else if(level==4) image(imgL4,150,0,300,300);
    else if(level==5) image(imgL5,150,0,300,300);
    else if(level==6) image(imgL6,150,0,300,300);
    if(level<6){
      textSize(100);
      fill(255,0,0);
      text("Good Job",30,400);
      textSize(45);
      text("Please press '→'",30,500);
    }
    if(level==6){
      fill(255,0,0);
      textSize(50);
      text("Congratulation!",30,500);
    }
  }
}


void mouseDragged(){
  if(stage==1){
    int i=int((mouseY-100)/20);
    int j=int((mouseX-100)/20);
    touch[j][i]=1;
    if(touch[j][i]==1 && puzzle[j][i]==0 && dist(j,i,(pmouseX-100)/20,(pmouseY-100)/20)>1/20)
      count--;
  }
}

void mousePressed(){
  if(stage==1){
    int i=int((mouseY-100)/20);
    int j=int((mouseX-100)/20);
    touch[j][i]=1;
    if(puzzle[j][i]==0 && touch[j][i]==1)count--;
    if(count==0){}
  }
  if(stage==2) {  //還原初始設定
    stage=0;
    count=10;
    bad=0;
    for(int i=0;i<20;i++){
      for(int j=0;j<20;j++){
        touch[i][j]=0;
        check[i][j]=0;
      }
    }
  }
}

void keyPressed(){
  if(stage==0){
    if(key=='s') stage=1;  //開始遊戲
  }
  if(keyCode==LEFT){  //返回上一關
    level--; stage=1;
    count=10;
    bad=0;
    for(int i=0;i<20;i++){
      for(int j=0;j<20;j++){
        touch[i][j]=0;
        check[i][j]=0;
      }
    }
  }
  if(keyCode==RIGHT){  //前往下一關
    level++; stage=1;
    count=10;
    bad=0;
    for(int i=0;i<20;i++){
      for(int j=0;j<20;j++){
        touch[i][j]=0;
        check[i][j]=0;
      }
    }
  }
}

//level
int [][]l1={{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1},
{0,0,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1},
{0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,0,1,0,0,1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,0,1,0,0,1,1,1,1,1,1,1,1,1,1,1},
{0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{0,0,1,0,0,0,0,0,1,1,1,1,0,0,1,0,0,0,1,1},
{0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,0,0,0,1,1},
{0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,0,0,0,1,1},
{0,0,1,0,0,0,0,0,1,1,1,1,0,0,1,0,0,0,1,1},
{0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,0,1,0,0,1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,0,1,0,0,1,1,1,1,1,1,1,1,1,1,1},
{0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{0,0,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1},
{0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1}};

👀作品展示

https://youtu.be/FK-1Y_xf708



👀提供遊戲下載

🎯載點

沒有留言:

張貼留言