介紹:
我們這組所做的是剪紅線,名字只是個比喻,就好像有五顆炸彈,其中一顆會爆炸,而我們必須猜對那一顆炸彈才能讓贏得遊戲,本來是思考享用很多很多顆假炸彈參雜數顆真炸彈,可是手邊的材料沒有那麼多,所以就縮減成五顆。
程式碼:
import processing.serial.*; Serial myPort; import ddf.minim.*; Minim minim; AudioPlayer wrong,right; int com; int x=0; int val; PImage a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,r1,r2; void setup(){ myPort = new Serial(this, "COM4", 9600); com=int(random(4))+1; minim = new Minim(this); size(800,600); wrong= minim.loadFile("w.mp3"); right = minim.loadFile("r.mp3"); a1 = loadImage("a1.png"); b1 = loadImage("b1.png"); a2 = loadImage("a2.png"); b2 = loadImage("b2.png"); a3 = loadImage("a3.png"); b3 = loadImage("b3.png"); a4 = loadImage("a4.png"); b4 = loadImage("b4.png"); a5 = loadImage("a5.png"); b5 = loadImage("b5.png"); r1 = loadImage("r1.png"); r2 = loadImage("r2.png"); } void draw(){ if(myPort.available()&rt;0){ val = myPort.read(); // println(val); } if(val=='1'){ x=1; } else if(val=='2'){ x=2; } else if(val=='3'){ x=3; } else if(val=='4'){ x=4; } else if(val=='5'){ x=5; } else if(val=='R'){ x=0; right.pause(); right.rewind(); com=int(random(4))+1; } background(244,219,142); rect (200,0,400,75); if(x==1) image(b1,50,100,200,200); else image(a1,50,100,200,200); if(x==2) image(b2,300,100,200,200); else image(a2,300,100,200,200); if(x==3) image(b3,550,100,200,200); else image(a3,550,100,200,200); if(x==4) image(b4,175,300,200,200); else image(a4,175,300,200,200); if(x==5) image(b5,425,300,200,200); else image(a5,425,300,200,200); if(x==6) image(r2,0,510,800,90); else image(r1,0,510,800,90); println("com="+com); // println(x); if (x==com && x!=0) {fill(183,244,69); right.play(); } else if (x!=com && val!='H' && x!=0) { wrong.play(); wrong.rewind(); } else fill(255,0,0); rect (200,0,400,75); } void keyPressed(){ if(key=='1') x=1; if(key=='2') x=2; if(key=='3') x=3; if(key=='4') x=4; if(key=='5') x=5; if(key==' '){x=6; com=int(random(4))+1; } }
遊戲畫面:
沒有留言:
張貼留言