2012年11月13日 星期二

Midterm

1 影片


  
2.遊戲方法&截圖
遊戲開始後,下方會開始冒泡泡出來,要用滑鼠去點泡泡,泡泡會消失並且分數會加五分,如果沒有戳到泡泡而讓泡泡跑出視窗,分數會扣五分,為時一分鐘


一分鐘結束後,會秀出所得的分數


3.程式碼

int popox=0,popoy=0,popoy1=0,popoy2=0,popoy3=0,popoy4=0,popoy5=0;
int fishx=0,fishy=0;
int score=0;
int lasttime=60;

import ddf.minim.*;
AudioPlayer  player,wate,cheers;
Minim minim;

PImage popo;
PImage finger;
PImage bobo;
PImage back;
PImage fish;
void setup()
{
  size(800,600);
  fish=loadImage("fish.png"); //游動的魚
  bobo=loadImage("bobo.png"); //海綿寶寶
  finger=loadImage("finger.png"); //手指
  popo=loadImage("popo.png"); //泡泡
  back=loadImage("back.jpeg"); //背景圖
  minim=new Minim(this);
player=minim.loadFile("file.mp3", 2048); //背景音樂
player.play();
}

void draw()
{

  image(back,0,0);
  image(bobo,250,100);


  popoy-=3; //泡泡移動量
  image(popo,popox+300,popoy+600,100,100);  //泡泡坐標,大小
  if(popoy+600<0) //判斷泡泡是否跑出視窗
  { 
    score-=5; //跑出視窗後扣五分
    popoy=0; //泡泡回到原點再跑一次
  }
   popoy1-=2;
  image(popo,popox+200,popoy1+500,100,100);
   if(popoy1+500<0)
  {
    score-=5;
    popoy1=0;
  }
   popoy2-=3;
  image(popo,popox+100,popoy2+700,100,100);
   if(popoy2+700<0)
  {
    score-=5;
    popoy2=0;
  }
   popoy3-=5.5;
  image(popo,popox+500,popoy3+650,100,100);
   if(popoy3+650<0)
  {
    score-=5;
    popoy3=0;
  }
  popoy4-=2;
  image(popo,popox+400,popoy4+850,100,100);
   if(popoy4+850<0)
  {
    score-=5;
    popoy4=0;
  }
  popoy5-=3;
  image(popo,popox+600,popoy5+950,100,100);
   if(popoy5+950<0)
  {
    score-=5;
    popoy5=0;
  }

  image(finger,mouseX-30,mouseY-30,60,60);
  
  fishx++;
  image(fish,fishx,fishy+200);
  {
    if(fishx>800) //判斷魚是否跑出視窗
    {
    fishx=0; 
    fishy=250;
    }
  }
  world();

  
}

void mousePressed()
  {
  
  if (mouseX > popox+300 && mouseX< popox+400 && mouseY<popoy+700 && mouseY>popoy+600) //判斷滑鼠是否點到泡泡的範圍
   {
     popoy=600; //泡泡回到下面再跑一次
   score+=5; //戳到泡泡加五分
   wate=minim.loadFile("wate.wav", 2048); //戳到泡泡時播放音效
   wate.play();
   }
   if (mouseX > popox+200 && mouseX< popox+300 && mouseY<popoy1+600 && mouseY>popoy1+500)
  {
    popoy1=500;
   score+=5;
   wate=minim.loadFile("wate.wav", 2048);
   wate.play();
  }
   if (mouseX > popox+100 && mouseX< popox+200 && mouseY<popoy2+800 && mouseY>popoy2+700)
  {
    popoy2=700;
   score+=5;
   wate=minim.loadFile("wate.wav", 2048);
   wate.play();
 }
   if (mouseX > popox+500 && mouseX< popox+600 && mouseY<popoy3+750 && mouseY>popoy3+650)
   {
     popoy3=600;
   score+=5;
   wate=minim.loadFile("wate.wav", 2048);
   wate.play();
   }
  if (mouseX > popox+400 && mouseX< popox+500 && mouseY<popoy4+950 && mouseY>popoy4+850)
  {
    popoy4=600;
  score+=5;
  wate=minim.loadFile("wate.wav", 2048);
   wate.play();
  }
    if (mouseX > popox+600 && mouseX< popox+700 && mouseY<popoy5+1050 && mouseY>popoy5+950)
  {
    popoy5=700;
  score+=5;
  wate=minim.loadFile("wate.wav", 2048);
   wate.play();
  }
  }
  
  void world()
  {
     textFont(createFont("Georgia", 48)); 
      fill(255);
  text("score:"+score, 50, 550); //分數
  
  textFont(createFont("Georgia", 48));
      fill(255);
  text("Time:"+lasttime, 250, 550); //計時器
  lasttime=60-millis()/1000; 
  
      if(lasttime==0) //當時間=0,秀出得分
      {
      stop();
      textFont(createFont("Georgia", 80));
      background(51,102,51);
      fill(255,255,255);
      text("Game Over",200,300);
      text("Your score:"+score,180,400);
      cheers=minim.loadFile("cheers.wav");
      cheers.play();
      }
  }


   
   

Week08,HW08

  就只有做出點一個方個會有紅點 ,然後在紅點的一定範圍內按a會可以再點一點,之後可

能就是把紅點做成炸彈超人的貼圖,另一個就做成炸彈。

不過因為打算跟黃同學一組,所以其中可能就以他的作品為主,再加以修改吧


int sx=50,sy=50;//上限
int stx,sty,enx,eny;//起始點 終點
float pencostset=0.5;//
float pencost=0;
float fillrate=0.2;
float hmult=1.15;
float maxpert=0;
boolean finding,findingsolution,d1=true,pressA=true;
int gx,gy,rx,ry;
float fx;
float fy;

void setup()
{
  size(800,800);//地圖大小
  smooth();//平滑
  sx=800>>6;
  sy=800>>6;
  stx=0;
  sty=0;
  fx=800/sx;
  fy=800/sy;
  enx=sx-1;
  eny=sy-1;
}

void draw()
{

 for(int x=0;x<sx;x++)
    for(int y=0;y<sy;y++)
    {
      strokeWeight(1);
      stroke(0);
      if(x*fx<mouseX&&mouseX<(x+1)*fx)
          if(y*fy<mouseY&&mouseY<(y+1)*fy)
          {
           if(mousePressed&&keyPressed&&key =='a'){
              rx=x;  ry=y;
              }
            if(mousePressed&&!keyPressed){
              gx=x;  gy=y;
             }
          }
       if(mousePressed&&rx==x&&ry==y&&!(gx==x&&gy==y)&&keyPressed&&(key =='a'||key =='A')
                &&(pow(gx-rx,2)+pow(gy-ry,2)<=pow(5,2)))fill(255,0,0);//丟炸彈的位置
      else if(/*mousePressed&&*/gx==x&&gy==y/*&!keyPressed*/)fill(0,255,0);//人的位置
      else fill(255,255,255);
      rect(x*fx,y*fy,fx,fy);
      }
   }



Midterm

期中作品

影片



截圖


一開始的畫面
滑鼠點選"開始遊戲"後,切換到"鐵板"的畫面

滑鼠點選"遊戲說明"後,切換到"遊戲說明"的畫面
 
製作章魚燒的鐵板


Time's up  &  Game Over的畫面
(滑鼠點選"離開遊戲"後,切換到這個畫面) 




 程式碼

float r=0.01;
int savedTime; //計時器時間
int bg=1;
PImage bg1, vv, pp, over, e, fff, tako1, all;
int state=0;
int ellipse1 = 0;


void setup() {
  size(800, 600);
  savedTime = millis();  //儲存遊戲開始的時間(只執行一次)
  bg1 = loadImage("bg1.jpg");
  vv = loadImage("vv.jpg");
  pp = loadImage("pp1.jpg");
  over = loadImage("bg4.jpg");
  e = loadImage("turtle.jpg");
  fff = loadImage("fff.jpg");
  tako1 = loadImage("tako1.jpg");
  all = loadImage("06.jpg");
}

void draw() {
  println(mouseY);
  if (bg==1) {
    image(bg1, 0, 0, 800, 600);  //一開始執行的畫面
    if (mousePressed && mouseX>=555 && mouseX<=794 && mouseY>=261 && mouseY<=396) {
      image(pp, 0, 0);
      bg=2;  //滑鼠點選"開始遊戲"後,切換到"鐵板"的畫面
    }
    else if (mousePressed && mouseX>=550 && mouseX<=800 && mouseY>=420 && mouseY<=550) {
      bg=3;  /滑鼠/點選"遊戲說明"後,切換到"遊戲說明"的畫面
    }
  }
  if (bg==3) {
    image(vv, 0, 0, 800, 600);  //"遊戲說明"的畫面
    if (mousePressed && mouseX>=255 && mouseX<=465 && mouseY>=498 && mouseY<=594) {
      image(pp, 0, 0, 800, 600);
      bg=2;  //滑鼠點選"開始遊戲"後,切換到"鐵板"的畫面
    }
  }

  if (bg==2) {  //鐵板的畫面
    int passedTime = (millis() - savedTime)/100; //經過的秒數
    if (passedTime<600) {
      image(e, 683, passedTime, 120, 98);
    }
    else if (passedTime>=600) image(over, 0, 0, 800, 600);
    println(passedTime);
    if (mousePressed && mouseX>=485 && mouseX<=645 && mouseY>=542 && mouseY<=584) {
      image(over, 0, 0);
      bg=4;  //遊戲結束的畫面
    }
    if (mousePressed && mouseX>50 && mouseX<90 && mouseY>500 && mouseY<540) { 
      state = 1;
    }
    if (mousePressed && mouseX>150 && mouseX<190 && mouseY>500 && mouseY<540) {
      state = 2;
    }
    if (mousePressed && mouseX>250 && mouseX<290 && mouseY>500 && mouseY<540) {
      state = 3;
    }
    if (mousePressed && mouseX>350 && mouseX<390 && mouseY>500 && mouseY<540) {
      state = 4;
    }
    if (state == 1) {
      if (mousePressed && mouseX>40 && mouseX<160 && mouseY>40 && mouseY<160) {
        if (passedTime<100) {
          fill(239, 228, 176);  //白
          ellipse(100, 100, 120, 120);
        }
        else if (passedTime>=100 && passedTime<150) {
          fill(235, 194, 102);  //黃
          ellipse(100, 100, 120, 120);
        }
        else if (passedTime>=150) {
          fill(223, 147, 51);  //熟
          ellipse(100, 100, 120, 120);
        }
      }
      else if (mousePressed && mouseX>40 && mouseX<160 && mouseY>190 && mouseY<310) {
        if (passedTime<100) {
          fill(239, 228, 176);  //白
          ellipse(100, 250, 120, 120);
        }
        else if (passedTime>=100 && passedTime<150) {
          fill(235, 194, 102);  //黃
          ellipse(100, 250, 120, 120);
        }
        else if (passedTime>=100) {
          fill(223, 147, 51);  //熟
          ellipse(100, 250, 120, 120);
        }
      }
      else if (mousePressed && mouseX>40 && mouseX<160 && mouseY>340 && mouseY<460) {
        if (passedTime<100) {       
          fill(239, 228, 176);  //白
          ellipse(100, 400, 120, 120);
        }
        else if (passedTime>=100 && passedTime<150) {
          fill(235, 194, 102);  //黃
          ellipse(100, 400, 120, 120);
        }
        else if (passedTime>=150) {
          fill(223, 147, 51);  //熟
          ellipse(100, 400, 120, 120);
        }
      }
      else if (mousePressed && mouseX>190 && mouseX<310 && mouseY>40 && mouseY<160) {
        if (passedTime<100) {
          fill(239, 228, 176);  //白
          ellipse(250, 100, 120, 120);
        }
        else if (passedTime>=100 && passedTime<150) {
          fill(235, 194, 102);  //黃
          ellipse(250, 100, 120, 120);
        }
        else if (passedTime>=150) {
          fill(223, 147, 51);  //熟
          ellipse(250, 100, 120, 120);
        }
      }
      else if (mousePressed && mouseX>190 && mouseX<310 && mouseY>190 && mouseY<310) {
        if (passedTime<100) {        
          fill(239, 228, 176);  //白
          ellipse(250, 250, 120, 120);
        }
        else if (passedTime>=100 && passedTime<150) {
          fill(235, 194, 102);  //黃
          ellipse(250, 250, 120, 120);
        }
        else if (passedTime>=150) {
          fill(223, 147, 51);  //熟
          ellipse(250, 250, 120, 120);
        }
      }
      else if (mousePressed && mouseX>190 && mouseX<310 && mouseY>340 && mouseY<460) {
        if (passedTime<100) {         
          fill(239, 228, 176);  //白
          ellipse(250, 400, 120, 120);
        }
        else if (passedTime>=100 && passedTime<150) {
          fill(235, 194, 102);  //黃
          ellipse(250, 400, 120, 120);
        }
        else if (passedTime>=150) {
          fill(223, 147, 51);  //熟
          ellipse(250, 400, 120, 120);
        }
      }
      else if (mousePressed && mouseX>340 && mouseX<460 && mouseY>40 && mouseY<160) {
        if (passedTime<100) { 
          fill(239, 228, 176);  //白
          ellipse(400, 100, 120, 120);
        }
        else if (passedTime>=100 && passedTime<150) {
          fill(235, 194, 102);  //黃
          ellipse(400, 100, 120, 120);
        }
        else if (passedTime>=150) {
          fill(223, 147, 51);  //熟
          ellipse(400, 100, 120, 120);
        }
      }
      else if (mousePressed && mouseX>340 && mouseX<460 && mouseY>190 && mouseY<310) {
        if (passedTime<100) { 
          fill(239, 228, 176);  //白
          ellipse(400, 250, 120, 120);
        }
        else if (passedTime>=100 && passedTime<150) {
          fill(235, 194, 102);  //黃
          ellipse(400, 250, 120, 120);
        }
        else if (passedTime>=150) {
          fill(223, 147, 51);  //熟
          ellipse(400, 250, 120, 120);
        }
      }
      else if (mousePressed && mouseX>340 && mouseX<460 && mouseY>340 && mouseY<460) {
        if (passedTime<100) { 
          fill(239, 228, 176);  //白
          ellipse(400, 400, 120, 120);
        }
        else if (passedTime>=100 && passedTime<150) {
          fill(235, 194, 102);  //黃
          ellipse(400, 400, 120, 120);
        }
        else if (passedTime>=150) {
          fill(223, 147, 51);  //熟
          ellipse(400, 400, 120, 120);
        }
      }//第三排
    }

    //手(加章魚至麵糊)
    if (state == 2) {
      if (mousePressed && mouseX>40 && mouseX<160 && mouseY>40 && mouseY<160) {
        image(tako1, 70, 70, 65, 65);
      }
      else if (mousePressed && mouseX>40 && mouseX<160 && mouseY>190 && mouseY<310) {
        image(tako1, 70, 220, 65, 65);
      }
      else if (mousePressed && mouseX>40 && mouseX<160 && mouseY>340 && mouseY<460) {
        image(tako1, 70, 370, 65, 65);
      }
      else if (mousePressed && mouseX>190 && mouseX<310 && mouseY>40 && mouseY<160) {
        image(tako1, 220, 70, 65, 65);
      }
      else if (mousePressed && mouseX>190 && mouseX<310 && mouseY>190 && mouseY<310) {
        image(tako1, 220, 220, 65, 65);
      }
      else if (mousePressed && mouseX>190 && mouseX<310 && mouseY>340 && mouseY<460) {
        image(tako1, 220, 370, 65, 65);
      }
      else if (mousePressed && mouseX>340 && mouseX<460 && mouseY>40 && mouseY<160) { 
        image(tako1, 370, 70, 65, 65);
      }
      else if (mousePressed && mouseX>340 && mouseX<460 && mouseY>190 && mouseY<310) { 
        image(tako1, 370, 220, 65, 65);
      }
      else if (mousePressed && mouseX>340 && mouseX<460 && mouseY>340 && mouseY<460) {
        image(tako1, 370, 370, 65, 65);
      }
    }
  
   //叉子   
    if (state == 3) {
      if (mousePressed && mouseX>40 && mouseX<160 && mouseY>40 && mouseY<160) {
        fill(43);
        ellipse(100, 100, 120, 120);
        image(fff, 510, 280, 50, 50);
      }
      else if (mousePressed && mouseX>40 && mouseX<160 && mouseY>190 && mouseY<310) {
        fill(43);
        ellipse(100, 250, 120, 120);
        image(fff, 560, 280, 50, 50);
      }
      else if (mousePressed && mouseX>40 && mouseX<160 && mouseY>340 && mouseY<460) {
        fill(43);
        ellipse(100, 400, 120, 120);
        image(fff, 560, 330, 50, 50);
      }
      else if (mousePressed && mouseX>190 && mouseX<310 && mouseY>40 && mouseY<160) {
        fill(43);
        ellipse(250, 100, 120, 120);
        image(fff, 510, 330, 50, 50);
      }
      else if (mousePressed && mouseX>190 && mouseX<310 && mouseY>190 && mouseY<310) {
        fill(43);
        ellipse(250, 250, 120, 120);
        image(fff, 510, 380, 50, 50);
      }
      else if (mousePressed && mouseX>190 && mouseX<310 && mouseY>340 && mouseY<460) {
        fill(43);
        ellipse(250, 400, 120, 120);
        image(fff, 560, 380, 50, 50);
      }
      else if (mousePressed && mouseX>340 && mouseX<460 && mouseY>40 && mouseY<160) { 
        fill(43);
        ellipse(400, 100, 120, 120);
        image(fff, 560, 430, 50, 50);
      }
      else if (mousePressed && mouseX>340 && mouseX<460 && mouseY>190 && mouseY<310) { 
        fill(43);
        ellipse(400, 250, 120, 120);
        image(fff, 510, 430, 50, 50);
      }
      else if (mousePressed && mouseX>340 && mouseX<460 && mouseY>340 && mouseY<460) {
        fill(43);
        ellipse(400, 400, 120, 120);
        image(fff, 535, 480, 50, 50);
      }
    }//state3
    if (state == 4) {
      //background(96,125,165);
      translate(400, 300);
      rotate(r);
      r+=0.01;
      image(all, 0, 0, 300, 383);
      //image(over, 0, 0, 800, 600);
    }
  }
}



心得及問題討論:

  我們這次的期中作業遇到了麵糊變換顏色跟時間倒數的問題,後來請教老師跟助教,
有了一點方向,經過不斷的嘗試跟調整,我們終於完成了麵糊可以從白色→黃色→褐色(時間約經過15秒),但是我們原本的想法是希望麵糊每經過10秒後會自己變色。
另外,我們了解到秒數的倒數計時程式不可以用second(),而是要用millis()千分之一秒。
  計時器部分,我們原本希望可以用兩個clock來紀錄不同的時間(烏龜的倒數計時,與麵糊改變顏色的計時),這是我們需要改進的地方。

  問題:我們目前只能完成一盒章魚燒,希望能繼續延伸製作第二盒甚至更多章魚燒。
物件及畫面可以再做調整,並需要加入更多限制使遊戲更完整、更有挑戰性。



Midtern


int i,d1=0,d2=0,d3=0,d4=0;
int score=0, lastTime=60;
int[] value = new int[50000];
color[] c=new color[4];
int a,count=0;
int tmp=0;
int startt;

void setup(){
  size(500,600);
  c[0]=color(255,0,0);
  c[1]=color(0,255,0);
  c[2]=color(0,0,255);
  c[3]=color(255,255,255);
  for(i=0;i<10000;i++)
  {
    a=int(random(0,3.99));
    /*
    if(i%25==0)
      fill(255,0,0);
      else  if(i%30==0)
          fill(0,255,0);
          else  if(i%40==0)
              fill(0,0,255);
              else
              fill(255,255,255);
    */
    count%=50000;
    value[count++]=a;
  }
}
void draw(){
  background(255,200,100);
textSize(30);
fill(100,0,50);
text("Time:"+lastTime, 50,80);
text("Score:"+score, 0,220);
 if(lastTime==0){
      stop();
      textFont(createFont("3", 60));
      background(100,100,100);
      fill(255,255,255);
      text("Game Over ",120,250);
      text("Your score:"+score,0,350);
 }
lastTime=30-millis()/1000;

    i=200;
    for(int k=startt;k<startt+20;k++){
    fill(c[value[k]]);
    rect(i,100,80,80);
    i+=20;
    }
 




  fill(255,200,100);
  rect(0,100,200,80);

  if(d1==1){
    fill(128,128,128);
  }else{
    fill(255,0,0);
  }
  rect(160,400,80,80);
  if(d2==1){
    fill(128,128,128);
  }else{
    fill(0,255,0);
  }
  rect(280,400,80,80);
  if(d3==1){
    fill(128,128,128);
  }else{
    fill(0,0,255);
  }
  rect(160,500,80,80);
  if(d4==1){
    fill(128,128,128);
  }else{
    fill(255,255,255);
  }
  rect(280,500,80,80);
}
void keyPressed(){
  if(key=='4'){
    d1=1;
    if(value[startt]==0){
      startt++;
      score+=10;
    }
  }else if(key=='5'){
 
    d2=1;if(value[startt]==1){
      startt++;
      score+=10;
    }
  }else if(key=='r'){
    d3=1;if(value[startt]==2)
    {  startt++;
    score+=10;
    }
  }else if(key=='t'){
    d4=1;if(value[startt]==3)
     { startt++;
     score+=10;
     }
  }
}
void keyReleased(){
  if(key=='4'){
    d1=0;
  }else if(key=='5'){
    d2=0;
  }else if(key=='r'){
    d3=0;
  }else if(key=='t'){
    d4=0;
  }
}

遊戲開始:





















60秒後遊戲結束:






















Midterm


期中作業:方塊射擊


因為臨時改變遊戲玩法有改
所以題目也有變化

上課的 Demo 影片




問題解決後的 Demo 影片





影片的音樂在錄製的時候有點兒奇怪
我們是從這段影片截取一段音樂使用 ( 從 2 分 42 秒開始 )
點我點我
想聽音樂可以來這裡聽哦 :D

程式碼

int i=0,j=0,k=0;
int [][]grid=new int [10][20]; // 這是一開始俄羅斯方塊的背景陣列
int mapw=20;
int score=0;
int nowX=5,nowY=0;
int backgrounds=1;
PImage startbackground;
PImage tetrisbackground;
PImage endbackground;
PImage pig;
int mx=0,my=0,mxb=0,myb=0;
int angle=0;
int shootx=-25;
int shooty=0;
boolean ctl=true;
int ctl2=0;
int gameTime,s;
int lastTime;
int count;
import ddf.minim.*; 
Minim minim; 
AudioPlayer player;

void setup(){
  size(500,400);
  startbackground = loadImage("sb.jpg");
  tetrisbackground = loadImage("200.jpg");
  endbackground = loadImage("end.JPG");
  pig = loadImage("13771.png");
  image(startbackground,0,0);
  s= millis()/1000;
  minim = new Minim(this);
  player = minim.loadFile("abdc.mp3");
  player.play();
}

void draw(){
  if( mousePressed && mouseX&rt;180 && mouseX<300 && mouseY&rt;280 && mouseY<350 && ctl)
   ctl=false;
   if(ctl==true){
    image(startbackground,0,0); 
    } 
    else if(ctl==false){{
       image(tetrisbackground,0,0);
       int m=grid[i][j];
       for(int i=0;i<mapw*20;i+=mapw){
         for(int j=0;j<mapw*10;j+=mapw){
           fill(70,70,70,10);
             stroke(175,175,175);
             rect(j+50,i,mapw,mapw);       
             }
            }  
      Tt(nowX,nowY,20,20);
      fill(0,255,255);
      shooty=340+count--;
      rec(shootx,shooty);
      if(shooty == (myb)+19 || shootx+10&rt;(mxb+500) && shootx+10< 46+(mxb+500)){
      score+=10;
      }
      image(pig,mxb+50,myb);   
    }
    s= millis()/1000;
    fill(255,0,0);
    textSize(30);
    text(score,440,127);
 
    lastTime = millis()- s; 
    gameTime = 30-lastTime/1000;  
    text(gameTime,400,70); 
  
    if (gameTime<0){
    image(endbackground,0,0,500,400);
    text("Your score is:  " +score,120,350);  
    }
  }  
}

void rec(int x,int y){
  rect(x,y,20,20);
  }

void Lt(int c, int d,int r, int e){
  int lts[][]={{0,0,0,0},
               {1,1,1,0},
               {0,0,1,0},
               {0,0,0,0}};  
     for(int a=0;a<4;a++){
      for(int b=0;b<4;b++)
        if(lts[a][b]==1){
          fill(255,0,0);
          rect(a*20,b*20,20,20);
    }
  }
}
void It(int x, int y,int r, int e){
  int its[][]={{1,0,0,0},
               {1,0,0,0},
               {1,0,0,0},
               {1,0,0,0}};  
    for(int a=0;a<4;a++){
      for(int b=0;b<4;b++)
        if(its[a][b]==1){
          fill(255,119,53);
          rect(a*20,b*20+80,20,20); // 為了確認方塊有出現先移動 y 軸 +80
    }
  }
}
void Jt(int x, int y,int r, int e){
  int jts[][]={{0,0,0,0},
               {0,0,1,0},
               {1,1,1,0},
               {0,0,0,0}};  
    for(int a=0;a<4;a++){
      for(int b=0;b<4;b++)
        if(jts[a][b]==1){
          fill(255,255,0);
          rect(a*20,b*20+120,20,20); // 為了確認方塊有出現先移動 y 軸 +120
    }
  }
}
void Wt(int x, int y,int r, int e){
  int wts[][]={{0,0,0,0},
               {0,1,1,0},
               {0,1,1,0},
               {0,0,0,0}};  
    for(int a=0;a<4;a++){
      for(int b=0;b<4;b++)
        if(wts[a][b]==1){
          fill(0,128,64);
          rect(a*20,b*20+180,20,20); // 為了確認方塊有出現先移動 y 軸 +180
    }
  }
}
void Tt(int x, int y,int r, int e){
  int tts[][]={{0,0,1,0},
               {0,1,1,0},
               {0,0,1,0},
               {0,0,0,0}};  
    for(int a=0;a<4;a++){
      for(int b=0;b<4;b++)
        if(tts[a][b]==1){
          fill(0,0,255);
          rect(a*20+50+mx,b*20+340,20,20); // 為了確認方塊有出現先移動 y 軸 +240
    }
  }
}
void Zt(int x, int y,int r, int e){
  int zts[][]={{0,1,0,0},
               {0,1,1,0},
               {0,0,1,0},
               {0,0,0,0}};  
    for(int a=0;a<4;a++){
      for(int b=0;b<4;b++)
        if(zts[a][b]==1){
          fill(26,133,221);
          rect(a*20,b*20+300,20,20); // 為了確認方塊有出現先移動 y 軸 +300
    }
  }
}
void Nt(int x, int y,int r, int e){
  int nts[][]={{0,0,1,0},
               {0,1,1,0},
               {0,1,0,0},
               {0,0,0,0}};  
    for(int a=0;a<4;a++){
      for(int b=0;b<4;b++)
        if(nts[a][b]==1){
          fill(91,0,183);
          rect(a*20+320,b*20,20,20); // 為了確認方塊有出現先移動 y 軸 +300
    }
  }
}
void keyPressed(){
  if(key==CODED && keyCode==LEFT){ 
    mx-=20;
    if(mx<0)mx=0;
  }
  if(key==CODED && keyCode==RIGHT){
    mx+=20;
    if(mx&rt;140)mx=140;
  }
  if(key==CODED && keyCode==DOWN){
    my+=20;
    if(my&rt;340)my=340;
  }
    if(key=='a'){ 
    mxb-=1;
    if(mxb<0)mxb=0;
  }
  if(key=='d'){
    mxb+=1;
    if(mxb&rt;160)mxb=160;
  }
  if(key==CODED && keyCode==UP){
     count-=20;
     shootx = mx+70;
  }
}
void keyReleased(){
  if(key==CODED && keyCode==UP){
    count=0;
  }
}   





   
這是遊戲開始畫面





這是遊戲進行畫面





這是結束畫面






遊戲玩法:
這個遊戲可以兩個人玩

我方砲台控制分別是
左 :← 右:→  發射 : ↑
敵方物體控制分別是
左 :A  右:D

當我方子彈射擊到敵方物體,則得 10 分
在 30秒 內看我玩家可得到多少分
敵方玩家就只能閃躲,沒辦法射擊子彈



這是我們原本俄羅斯方塊進行的階段





















在一開始的程式碼中
我們已成功寫出了 7 種方塊
以及利用陣列畫出背景方格
但後續要考慮到的狀有點多且複雜
例如:方塊旋轉,位置需對應到正確的背景陣列
或是方塊旋轉時,碰到已堆疊好的方塊,該如何調整位置等等
所以我們後來決定改變遊戲的進行方式


心得感想

        在一開始決定作俄羅斯方塊時,壓根的沒想過他會這麼難,要考慮到很多條件聽老師說夢想中的遊戲都可能實現,讓我們更確定了我們的目標,所以在開始期中作品一開始,我們先討論要先解決甚麼事情。

        介面的設計是我們最一開始的小目標把俄羅斯遊戲畫面的map網格畫出來,在這介面設計上,原本想說單純利用雙層for迴圈來解決,但是我們考慮到後來方塊必須在map網格上判斷是否存在,所以必須將以設定的map網格每一格初始化一個值,雖然我們遊戲邏輯在ㄧ開始有想出來,但是在程式的編寫方面就遇上了難題,我們有到處去問人及上網找解決的方法,但是後來還是老師的初始化方法比較佳且易懂,所以在這初始化map網格上的問題就暫時解決了。

        再來就是方格種類的設定,依照我們的思考後的遊戲邏輯,必須將每一個種類的俄羅斯方塊用二維陣列的方式加他寫出來,並且以布林值去做畫方格設定,在這裡也遇到相同的問題,就是知道目的是要做什麼,但是程式不知該如何撰寫會比較佳對於之後的遊戲流程,所以我們在寫俄羅斯方塊時,都是以當出假設概念一邊實驗一邊修改,在這邊徐修謙同學幫了我們很多的忙,這裡的概念是他建議我們的,之後我們自己去試且成功的利用二維與布林值畫出油四格方型排成的7種類型的俄羅斯方塊。在來就是應用在map中,當初我們試想用亂數呼叫的方式,把7種類型的俄羅斯方塊放入map中,可是在這上面頻頻出現問題,在亂數呼叫時,我們運用了random + swich-cace的概念,這個問題我們還沒有解決,因為亂數值會一直跳,停不下來,所以我們的7種方塊在遊戲畫面中,全部出現並一直閃,我們猜想是亂數值停不了,所以在這上面還有問題沒解決,之後我們問題接二連三的出現,讓我們原本的計畫都被不能執行的程式給打亂了,說真的在這邊我們有點挫折感,這時我們才發現在著手寫程式之前概念必須是正確的才會比較順。

        後來聽了小葉老師的建議,在短時間內我們無法debug完寫出完整的俄羅斯方塊,或許可以以俄羅斯方快轉個彎,加一點小巧思去改變玩法,變成是屬於我們的簡易式的俄羅斯方塊,後來我們想了一下子,利用之前已完成的7種方塊去做變化,一開始想到的改良版是小蜜蜂,但後來發現其實我們可以更簡單一點,而且可以加入兩個人玩的樂趣,就利用之前作的map網格作為我們的砲台面,我的方塊變成檯面中的砲台可以方射方格砲彈,並且將對手變成一隻豬,而上方的豬可以依照2P玩家控制閃躲,而1P玩家則是下方的方塊砲台並可以發射砲彈,而在限時內砲彈碰到豬時分數就會加10分,這是我們在短時間內不斷想以及改造後的結果。然而在改造的過程中也遇到了其他麻煩,像是砲彈發射的位置以及單按鍵觸發後子彈的反應、砲彈碰到豬的觸發分數加分、畫面的更新、開始畫面進入到遊戲畫面、時間結束跳到結束畫面...等,以上都是我們在短時間內克服的問題。

       最後雖然我們做的期中作品不是如預期的那樣,但是我們知道在做一個遊戲時,必須遇到的問題與狀況,在當初評估時並不會想到這麼多問題,所以我們認為我們都經歷了一個很好的學習經驗,在這次的期中作品中我們獲益良多。



Midterm


踩地雷
左半邊是地圖區,很簡單就是地雷可以踩或是右鍵Mark為地雷,
右邊介面區顯示當前這局總共有多少顆地雷,
可以使用下面的+或-來增加減少,然後按下PLAY開始新一局,
總地雷數就會是新設定的地雷數。

中間是經過時間,從第一顆地雷被踩下去才開始記數,
做為計算排行榜之用。

最下是高分表,顯示了目前資料中記錄的前三名,
會有一個HighSore.txt的純文字文件用於記錄當前排行榜,
如果不存在就會跳出例外,前三名的成績就為預設的255
只有玩地雷為25顆的正規局,名次才會被計算。

開始玩

如同大家所知的踩地雷一樣,
當踩到一格是周圍完全沒有地雷的空格,
就會自動把周圍全部點開,所以如果運氣好,
點兩三下就可以開出一大片安全區。

踩爆
如果不幸踩到地雷,畫面上就會秀出失敗的訊息,
這個時候時間不再繼續記數,也不能夠再踩,
只能夠按下PLAY開始新的一局,當然也可以設定地雷數後再開始。

勝利(這裡為了節省時間把地雷數改為5顆,排行榜也會計算)
當地圖上應該要被踩下的位置都被踩下後
(剩下未踩,或被Mark都是地雷)
判定勝利,秀出勝利訊息。
如果很確定是地雷的位置,那不必標記也沒關係,不影響判定。

可以看到上一局的11秒刷新了新的紀錄,
所以被記錄在第一名的位置了。


我的專案資料夾結構
HighScore是個很單純的純文字文件,
所以任何有心人士(?)都可以輕易的竄改上面的排行榜...



Code

字很多,先直接說我的做法好了QQ
程式從按下PLAY開始,
首先生成n(地雷數)個隨機不重複0~143的亂數,設定為地雷,
建構一個boolean陣列,存放144格是否地雷的地圖;
然後再做一個int二維陣列(boolean陣列為配合亂數,是一維陣列)
根據boolean陣列的資料判定當前這格周圍有多少顆地雷(或根本就是雷)
這個int map做好以後,地雷的資料就算完成了。

當使用者開始踩地雷區,因為每一格是50像素,
所以直接把使用者的mouseX.Y除50就可以對應到int map上,
判定起來很方便;
我的圖片在遊戲一開始後就載入到一個Image陣列之中,
當Click事件發生,直接讓int map中的資料去當作Image陣列的Index,
然後貼圖就是對應的數字,省去很多不必要的記憶體浪費。

大致上就是這樣,其他的小功能基本上都是小函式,
copy來研究一下就貼上了沒什麼特別的QQ

以下為程式碼:
請搭配http://ppt.cc/z6ee
完整專案檔服用,不然圖都貼不出來(doh)
int intMap[][] = new int[12][12];
boolean check[][] = new boolean[12][12];
boolean mark[][] = new boolean[12][12];
PImage pic[] = new PImage[10];
int mines = 25;
int oldTime;
int time = 0;
boolean pause;
boolean begin;
int[] highScore = {255,255,255};
int winCount;

void setup()
{
  size(800,600);
  try
  {
    String lines[] = loadStrings("HighScore.txt");
    for (int i = 0; i < 3; i++)
      highScore[i] = Integer.parseInt(lines[i]);
  }
  catch(Exception ex)
  {
    println("There is no High Score Data!\nThe High Score are all 255");
  }
  
  pic[0] = loadImage("white.jpg");
  pic[1] = loadImage("one.jpg");
  pic[2] = loadImage("two.jpg");
  pic[3] = loadImage("three.jpg");
  pic[4] = loadImage("four.jpg");
  pic[5] = loadImage("five.jpg");
  pic[6] = loadImage("six.jpg");
  pic[7] = loadImage("seven.jpg");
  pic[8] = loadImage("eight.jpg");
  pic[9] = loadImage("red.jpg");
  
  
  background(255,255,255);
  //frameRate(24);
  
  gameZoom();
  IFset();
  Start();
  
}
void gameZoom()
{
  stroke(5);
  fill(200,200,200);
  rect(0,0,600,600);
  strokeWeight(5);
  line(0,0,600,0);
  line(0,50,600,50);
  line(0,100,600,100);
  line(0,150,600,150);
  line(0,200,600,200);
  line(0,250,600,250);
  line(0,300,600,300);
  line(0,350,600,350);
  line(0,400,600,400);
  line(0,450,600,450);
  line(0,500,600,500);
  line(0,550,600,550);
  line(0,600,600,600);
  
  line(0,0,0,600);
  line(50,0,50,600);
  line(100,0,100,600);
  line(150,0,150,600);
  line(200,0,200,600);
  line(250,0,250,600);
  line(300,0,300,600);
  line(350,0,350,600);
  line(400,0,400,600);
  line(450,0,450,600);
  line(500,0,500,600);
  line(550,0,550,600);
  line(600,0,600,600);
  strokeWeight(1);
}
void IFset()
{
  fill(0,0,0);
  PFont myFont;
  myFont = createFont("FFScala", 32);
  textFont(myFont);
  text(str(mines),630,10,100,100);
  
  text("經過時間",620, 350,170,100);
  text("High Score",620, 450,170,100);
  
  myFont = createFont("FFScala", 20);
  textFont(myFont);
  text("顆地雷",690,20,200,100);
  text("1.\n2.\n3.",630,490,50,100);
  noStroke();
  fill(255,255,255);
  rect(700,490,50,100);
  fill(0,0,0);
  text(str(highScore[0])+"\n"+str(highScore[1])+"\n"+str(highScore[2]),700,490,50,100);
  stroke(1);
  
  fill(0,255,0);
  rect(630,60,40,40);
  fill(0,0,255);
  rect(700,60,40,40);
  fill(255,0,0);
  rect(635,78,30,4);
  rect(648,65,4,30);
  rect(705,78,30,4);
  
  rect(625,160,150,150);
  fill(0,0,0);
  myFont = createFont("FFScala", 50);
  textFont(myFont);
  text("PLAY",635,200,200,100);
  myFont = createFont("FFScala", 40);
  textFont(myFont);
}

void Start()
{
  int mine[] = new int[mines];
  boolean boolMap[] = new boolean[144];
  check = new boolean[12][12];
  mark = new boolean[12][12];
  for (int i = 0; i < mines; i++)
  {
    boolean checker = true;
    while(checker)
    {
      mine[i] = int(random(144));
      for(int j = 0; j <= i; j++)
      {
        if (i == j)
        {
          checker = false;
          break;
        }
        else if (mine[i] == mine[j])
          break;
      }
    }
    boolMap[mine[i]] = true;
  }
  
  int count = 0;
  if (boolMap[0])
    count = 9;
  else
  {
    if(boolMap[1])
      count++;
    if(boolMap[12])
      count++;
    if(boolMap[13])
      count++;
  }
  intMap[0][0] = count;
  count = 0;
  
  if (boolMap[11])
    count = 9;
  else
  {
    if (boolMap[10])
      count++;
    if (boolMap[22])
      count++;
    if (boolMap[23])
      count++;
  }
  intMap[11][0] = count;
  count = 0;
  
  if (boolMap[132])
    count = 9;
  else
  {
    if (boolMap[120])
      count++;
    if (boolMap[121])
      count++;
    if (boolMap[133])
      count++;
  }
  intMap[0][11] = count;
  count = 0;
  
  if (boolMap[143])
    count = 9;
  else
  {
    if (boolMap[130])
      count++;
    if (boolMap[131])
      count++;
    if (boolMap[142])
      count++;
  }
  intMap[11][11] = count;
  count = 0;
  //上排
  for (int i = 1; i < 11; i++)
  {
    int couM = 0;
    if (boolMap[i])
      couM = 9;
    else
    {
      if (boolMap[i - 1])
        couM++;
      if (boolMap[i + 1])
        couM++;
      if (boolMap[i + 11])
        couM++;
      if (boolMap[i + 12])
        couM++;
      if (boolMap[i + 13])
        couM++;
    }
    intMap[i][0] = couM;
  }
  //左排
  for (int i = 1; i < 11; i++)
  {
    int couM = 0;
    if (boolMap[12 * i])
      couM = 9;
    else
    {
      if (boolMap[12 * (i - 1)])
        couM++;
      if (boolMap[12 * (i - 1) + 1])
        couM++;
      if (boolMap[12 * i + 1])
        couM++;
      if (boolMap[12 * (i + 1)])
        couM++;
      if (boolMap[12 * (i + 1) + 1])
        couM++;
    }
    intMap[0][i] = couM;
  }
  //右排
  for (int i = 1; i < 11; i++)
  {
    int couM = 0;
    if (boolMap[(i + 1) * 12 - 1])
      couM = 9;
    else
    {
      if (boolMap[i * 12 - 2])
        couM++;
      if (boolMap[i * 12 - 1])
        couM++;
      if (boolMap[(i + 1) * 12 - 2])
        couM++;
      if (boolMap[(i + 2) * 12 - 2])
        couM++;
      if (boolMap[(i + 2) * 12 - 1])
        couM++;
    }
    intMap[11][i] = couM;
  }
  //下排
  for (int i = 1; i < 11; i++)
  {
    int couM = 0;
    if (boolMap[132 + i])
      couM = 9;
    else
    {
      if (boolMap[120 + i - 1])
        couM++;
      if (boolMap[120 + i])
        couM++;
      if (boolMap[120 + i + 1])
        couM++;
      if (boolMap[132 + i - 1])
        couM++;
      if (boolMap[132 + i + 1])
        couM++;
    }
    intMap[i][11] = couM;
  }
  //中間
  for (int i = 1; i < 11; i++)
  {
    for (int j = 1; j < 11; j++)
    {
      int couM = 0;
      if (boolMap[i * 12 + j])
        couM = 9;
      else
      {
        if (boolMap[(i - 1) * 12 + j - 1])
          couM++;
        if (boolMap[(i - 1) * 12 + j])
          couM++;
        if (boolMap[(i - 1) * 12 + j + 1])
          couM++;
        if (boolMap[i * 12 + j - 1])
          couM++;
        if (boolMap[i * 12 + j + 1])
          couM++;
        if (boolMap[(i + 1) * 12 + j - 1])
          couM++;
        if (boolMap[(i + 1) * 12 + j])
          couM++;
        if (boolMap[(i + 1) * 12 + j + 1])
          couM++;
      }
      intMap[j][i] = couM;
    }
  }
}
void mousePressed()
{
  int a = mouseX / 50;
  int b = mouseY / 50;
  if (mouseButton == LEFT)
  {
    if(mouseX<600 && !pause)
    {
      image(pic[intMap[a][b]], a * 50 + 3, b * 50 + 3, 45, 45);
      check[a][b]=true;
      winCount++;
      if (intMap[a][b] == 9)
        endGame();
      else if (intMap[a][b] == 0)
        safe(a, b);
        
      if(!begin)
      {
        begin = true;
        oldTime = second();
      }
      
      if(winCount == 144 - mines)
        win();
    }
    else if(mouseY&rt;60 && mouseY<100)
    {
      PFont myFont;
      myFont = createFont("FFScala", 32);
      textFont(myFont);
      if(mouseX&rt;630 && mouseX<670)
      {
        mines++;
        fill(255,255,255);
        noStroke();
        rect(610,8,75,40);
        fill(0,0,0);
        text(str(mines),630,10,100,100);
      }
      else if(mouseX&rt;700 && mouseX<740)
      {
        mines--;
        fill(255,255,255);
        noStroke();
        rect(610,8,55,40);
        fill(0,0,0);
        text(str(mines),630,10,100,100);
      }
    }
    else if(mouseX&rt;625 && mouseX<775 && mouseY&rt;160 && mouseY<310)
    {
      gameZoom();
      Start();
      IFset();
      time = 0;
      begin = false;
      pause = false;
    }
  }
  else if (mouseButton == RIGHT)
  {
    if(!pause)
    {
      if (!check[a][b] && !mark[a][b])
      {
        mark[a][b] = true;
        PImage flag = loadImage("mark.jpg");
        image(flag, a * 50 + 3, b * 50 + 3, 45, 45);
      }
      else if (mark[a][b])
      {
        mark[a][b] = false;
        fill(200,200,200);
        rect(a * 50 + 2, b * 50 + 2,46,46);
      }
      
    }
  }
}

void endGame()
{
  PFont myFont;
  myFont = createFont("FFScala", 80);
  textFont(myFont);
  fill(255,0,0);
  text("爆了!GG!",100,200,500,200);
  myFont = createFont("FFScala", 40);
  textFont(myFont);
  pause = true;
  winCount = 0;
}

void win()
{
  PFont myFont;
  myFont = createFont("FFScala", 80);
  textFont(myFont);
  fill(255,0,0);
  text("YOU WIN!!",100,200,500,200);
  myFont = createFont("FFScala", 40);
  textFont(myFont);
  pause = true;
  winCount = 0;
  if(mines == 25)        //如果是25顆地雷才會記錄!!!!
  {
    for(int i = 0; i < 3; i++)
      if(time < highScore[i])
      {
        for(int j = 2; j &rt; i; j--)
          highScore[j] = highScore[j - 1];
        highScore[i] = time;
        String saveHC = "";
        for(int j = 0; j < 3; j++)
          saveHC += str(highScore[j]) + " ";
        String[] list = split(saveHC, ' ');
        saveStrings("HighScore.txt", list);
        break;
      }
  }
}

void safe(int a,int b)
{
  if (a &rt; 0 && b &rt; 0)
  {
    if (!check[a-1][b-1])
    {
      image(pic[intMap[a-1][b-1]], (a-1) * 50 + 3, (b-1) * 50 + 3, 45, 45);
      check[a-1][b-1]=true;
      winCount++;
      if (intMap[a-1][b-1] == 0)
        safe(a-1, b-1);
    }
  }
  if (b &rt; 0)
  {
    if (!check[a][b-1])
    {
      image(pic[intMap[a][b-1]], (a) * 50 + 3, (b-1) * 50 + 3, 45, 45);
      check[a][b-1]=true;
      winCount++;
      if(intMap[a][b-1] == 0)
        safe(a, b-1);
    }
  }
  if (a < 11 && b &rt; 0)
  {
    if (!check[a+1][b-1])
    {
      image(pic[intMap[a+1][b-1]], (a+1) * 50 + 3, (b-1) * 50 + 3, 45, 45);
      check[a+1][b-1]=true;
      winCount++;
      if(intMap[a+1][b-1] == 0)
        safe(a+1, b-1);
    }
  }
  if (a &rt; 0 )
  {
    if (!check[a-1][b])
    {
      image(pic[intMap[a-1][b]], (a-1) * 50 + 3, (b) * 50 + 3, 45, 45);
      check[a-1][b]=true;
      winCount++;
      if(intMap[a-1][b] == 0)
        safe(a-1, b);
    }
  }
  if (a < 11)
  {
    if (!check[a+1][b])
    {
      image(pic[intMap[a+1][b]], (a+1) * 50 + 3, (b) * 50 + 3, 45, 45);
      check[a+1][b]=true;
      winCount++;
      if(intMap[a+1][b] == 0)
        safe(a+1,b);
    }
  }
  if (a &rt; 0 && b < 11)
  {
    if (!check[a-1][b+1])
    {
      image(pic[intMap[a-1][b+1]], (a-1) * 50 + 3, (b+1) * 50 + 3, 45, 45);
      check[a-1][b+1]=true;
      winCount++;
      if(intMap[a-1][b+1] == 0)
        safe(a-1,b+1);
    }
  }
  if (b < 11)
  {
    if (!check[a][b+1])
    {
      image(pic[intMap[a][b+1]], (a) * 50 + 3, (b+1) * 50 + 3, 45, 45);
      check[a][b+1]=true;
      winCount++;
      if(intMap[a][b+1] == 0)
        safe(a, b+1);
    }
  }
  if (a < 11 && b < 11)
  {
    if (!check[a+1][b+1])
    {
      image(pic[intMap[a+1][b+1]], (a+1) * 50 + 3, (b+1) * 50 + 3, 45, 45);
      check[a+1][b+1]=true;
      winCount++;
      if(intMap[a+1][b+1] == 0)
        safe(a+1,b+1);
    }
  }
}

void draw()
{
  if(begin)
  {
    if (oldTime != second())
      time++;
    oldTime = second();
  }
  noStroke();
  if(!pause)
  {  
    fill(255,255,255);
    rect(700,400,200,50);
    fill(0,0,0);
    text(str(time),700,400,200,50);
  }
}




//媽勒為什麼大家都是Midtern害我以為我拼錯