一,遊戲構思和介紹
動機:
由於現在人使用大量的電子產品,很多事情都賴於墊子產品的紀錄功能,而使用到腦袋來記憶的機會越來越少,因此我們想設計出一個記憶遊戲,除了富含娛樂功能,有能激活大家的記憶細胞:D
介紹;
就跟大部分的記憶遊戲玩法差不多。主遊戲畫面上共排列不同的五張貓咪圖片,當遊戲開始時,會依照所選擇的難度,隨機亮起不同的圖片,而玩家須要記得圖片的排列順序,依照順序按下按鈕後,再按下確認鍵確認答案,接著遊戲會給予回饋,看是答對或失敗,也可在選擇難度繼續遊戲,或是離開。
二,畫面介紹
↓ 剛進入的遊戲起始畫面:
↓ 按下確認鍵後,會進入到選擇難度的畫面:
↓ 選擇難度後,會進入到遊戲主畫面:
↓ 會隨機出現
↓ 遊戲失敗畫面:
↓ 遊戲離開畫面:
↓ 成功破最難關卡的畫面:
三,硬體
遊戲裝置上有六個按鈕,其中五個白色保麗龍按鈕是用來回答題目順序的,而右下角的紅色按鈕則是確認紐。
四,程式碼
Arduino:
//大的圓形鈕 const int buttonPin1 = 2; const int buttonPin2 = 3; const int buttonPin3 = 4; const int buttonPin4 = 5; const int buttonPin5 = 6; const int buttonPin6 = 7; //確認鈕 int buttonState1 = 0; int buttonState2 = 0; int buttonState3 = 0; int buttonState4 = 0; int buttonState5 = 0; int buttonState6 = 0; int input=0, oldInput=0, a=0; void setup(){ Serial.begin(9600); pinMode(buttonPin1, INPUT); pinMode(buttonPin2, INPUT); pinMode(buttonPin3, INPUT); pinMode(buttonPin4, INPUT); pinMode(buttonPin5, INPUT); pinMode(buttonPin6, INPUT); } void loop(){ buttonState1 = digitalRead(buttonPin1); buttonState2 = digitalRead(buttonPin2); buttonState3 = digitalRead(buttonPin3); buttonState4 = digitalRead(buttonPin4); buttonState5 = digitalRead(buttonPin5); buttonState6 = digitalRead(buttonPin6); if(buttonState1== HIGH) input=1; else if(buttonState2== HIGH) input=2; else if(buttonState3== HIGH) input=3; else if(buttonState4== HIGH) input=4; else if(buttonState5== HIGH) input=5; else if(buttonState6== HIGH) input=6; else input=0; if(input!=oldInput){ if(input==1){ Serial.print(1); oldInput=input; a=1; }else if(input==2){ Serial.print(2); oldInput=input; a=2; }else if(input==3){ Serial.print(3); oldInput=input; a=3; }else if(input==4){ Serial.print(4); oldInput=input; a=4; }else if(input==5){ Serial.print(5); oldInput=input; a=5; }else if(input==6){ Serial.print(6); oldInput=input; a=6; } } }Processing:
import processing.serial.*; Serial myport; PImage rule, start; //開始 PImage easy, nor, hard, bEasy, bNormal, bHard; //選單 PImage gmioumi1, gmioumi2, gmioumi3, gmioumi4, gmioumi5; //底圖 PImage mioumi1, mioumi2, mioumi3, mioumi4, mioumi5; //亮圖 PImage pass, over, win, End;//結果 float x=0, y=0, z=0, oldx=0, nowx=0; float xTime=3; String str="", str2="",oldstr2="", a="6",b="6", c="", oldc=""; int inByte=0, choose=0, end=3, e=0, f=0, g=0; void setup(){ myport=new Serial(this,"COM3",9600); //開始 rule = loadImage("rule.jpg"); start = loadImage("start.png"); //選單 easy = loadImage("easy.png"); nor = loadImage("normal.png"); hard = loadImage("hard.png"); bEasy = loadImage("bEasy.jpg"); bNormal = loadImage("bNormal.jpg"); bHard = loadImage("bHard.jpg"); //底圖 gmioumi1 = loadImage("g1.jpg"); gmioumi2 = loadImage("g2.jpg"); gmioumi3 = loadImage("g3.jpg"); gmioumi4 = loadImage("g4.jpg"); gmioumi5 = loadImage("g5.jpg"); //亮圖 mioumi1 = loadImage("c1.png"); mioumi2 = loadImage("c2.png"); mioumi3 = loadImage("c3.png"); mioumi4 = loadImage("c4.png"); mioumi5 = loadImage("c5.png"); //結果 pass = loadImage("pass.jpg"); over = loadImage("over.jpg"); win = loadImage("win.jpg"); End = loadImage("end.jpg"); size(600,400); background(0,0,0); } void draw(){ if(myport.available()>0){ //測試有無訊號來 inByte=myport.read(); //如果有來就read if(inByte==1+48) c="1"; else if(inByte==2+48) c="2"; else if(inByte==3+48) c="3"; else if(inByte==4+48) c="4"; else if(inByte==5+48) c="5"; else if(inByte==6+48) c="6"; } if(c!=oldc){ println(c); oldc=c; } if(c==""){ image(rule,50,50,500,250); image(start,200,320,200,50); e=1; }else if(c=="6" && e==1){ fill(0,0,0); rect(0,0,600,400); image(easy,50,50,160,50); image(nor,220,50,160,50); image(hard,390,50,160,50); image(bEasy,50,100,160,250); image(bNormal,220,100,160,250); image(bHard,390,100,160,250); c="0"; } if(c=="1" && e==1){ choose=1; e=2; c="0"; }else if(c=="3" && e==1){ choose=3; e=2; c="0"; }else if(c=="5" && e==1){ choose=5; e=2; c="0"; } if(choose==1){ //easy if(y<6){ if(millis()-xTime>1000){ x=random(5); b=a; nowx=(int)x/1; if(nowx==oldx){ if(nowx==4){ x=1; oldx=(int)x/1; }else if(nowx==5){ x=2; oldx=(int)x/1; }else{ x=x+1; oldx=(int)x/1; } }else oldx=(int)x/1; if(x>0 && x<=1){ fill(0,0,0); rect(0,0,600,400); image(mioumi1,50,100,100,100); image(gmioumi2,150,100,100,100); image(gmioumi3,250,100,100,100); image(gmioumi4,350,100,100,100); image(gmioumi5,450,100,100,100); a="1"; }else if(x>1 && x<=2){ fill(0,0,0); rect(0,0,600,400); image(mioumi2,150,100,100,100); image(gmioumi1,50,100,100,100); image(gmioumi3,250,100,100,100); image(gmioumi4,350,100,100,100); image(gmioumi5,450,100,100,100); a="2"; }else if(x>2 && x<=3){ fill(0,0,0); rect(0,0,600,400); image(mioumi3,250,100,100,100); image(gmioumi1,50,100,100,100); image(gmioumi2,150,100,100,100); image(gmioumi4,350,100,100,100); image(gmioumi5,450,100,100,100); a="3"; }else if(x>3 && x<=4){ fill(0,0,0); rect(0,0,600,400); image(mioumi4,350,100,100,100); image(gmioumi1,50,100,100,100); image(gmioumi2,150,100,100,100); image(gmioumi3,250,100,100,100); image(gmioumi5,450,100,100,100); a="4"; }else if(x>4 && x<=5){ fill(0,0,0); rect(0,0,600,400); image(mioumi5,450,100,100,100); image(gmioumi1,50,100,100,100); image(gmioumi2,150,100,100,100); image(gmioumi3,250,100,100,100); image(gmioumi4,350,100,100,100); a="5"; } xTime=millis(); y=y+1; if(y<6 && b!=a){ str=str+a; println("*"+str); z=0; }else if(y<6 && z==0 && b==a){ str=str+a; println("*"+str); z=1; } }else if(millis()-xTime>600 && millis()-xTime<800){ fill(0,0,0); rect(0,0,600,400); image(gmioumi1,50,100,100,100); image(gmioumi2,150,100,100,100); image(gmioumi3,250,100,100,100); image(gmioumi4,350,100,100,100); image(gmioumi5,450,100,100,100); } }else if(e==2){ fill(0,0,0); rect(0,0,600,400); image(gmioumi1,50,100,100,100); image(gmioumi2,150,100,100,100); image(gmioumi3,250,100,100,100); image(gmioumi4,350,100,100,100); image(gmioumi5,450,100,100,100); } if(c!=oldstr2){ if( c=="1" || c=="2" || c=="3" || c=="4" || c=="5"){ oldstr2=c; str2=str2+c; println("**"+str2+"**"); } } }else if(choose==3){ //normal if(y<8){ if(millis()-xTime>1000){ x=random(5); b=a; nowx=(int)x/1; if(nowx==oldx){ if(nowx==4){ x=1; oldx=(int)x/1; }else if(nowx==5){ x=2; oldx=(int)x/1; }else{ x=x+1; oldx=(int)x/1; } }else oldx=(int)x/1; if(x>0 && x<=1){ fill(0,0,0); rect(0,0,600,400); image(mioumi1,50,100,100,100); image(gmioumi2,150,100,100,100); image(gmioumi3,250,100,100,100); image(gmioumi4,350,100,100,100); image(gmioumi5,450,100,100,100); a="1"; }else if(x>1 && x<=2){ fill(0,0,0); rect(0,0,600,400); image(mioumi2,150,100,100,100); image(gmioumi1,50,100,100,100); image(gmioumi3,250,100,100,100); image(gmioumi4,350,100,100,100); image(gmioumi5,450,100,100,100); a="2"; }else if(x>2 && x<=3){ fill(0,0,0); rect(0,0,600,400); image(mioumi3,250,100,100,100); image(gmioumi1,50,100,100,100); image(gmioumi2,150,100,100,100); image(gmioumi4,350,100,100,100); image(gmioumi5,450,100,100,100); a="3"; }else if(x>3 && x<=4){ fill(0,0,0); rect(0,0,600,400); image(mioumi4,350,100,100,100); image(gmioumi1,50,100,100,100); image(gmioumi2,150,100,100,100); image(gmioumi3,250,100,100,100); image(gmioumi5,450,100,100,100); a="4"; }else if(x>4 && x<=5){ fill(0,0,0); rect(0,0,600,400); image(mioumi5,450,100,100,100); image(gmioumi1,50,100,100,100); image(gmioumi2,150,100,100,100); image(gmioumi3,250,100,100,100); image(gmioumi4,350,100,100,100); a="5"; } xTime=millis(); y=y+1; if(y<8 && b!=a){ str=str+a; println(str); z=0; }else if(y<8 && z==0 && b==a){ str=str+a; println(str); z=1; } }else if(millis()-xTime>600 && millis()-xTime<800){ fill(0,0,0); rect(0,0,600,400); image(gmioumi1,50,100,100,100); image(gmioumi2,150,100,100,100); image(gmioumi3,250,100,100,100); image(gmioumi4,350,100,100,100); image(gmioumi5,450,100,100,100); } }else if(e==2){ fill(0,0,0); rect(0,0,600,400); image(gmioumi1,50,100,100,100); image(gmioumi2,150,100,100,100); image(gmioumi3,250,100,100,100); image(gmioumi4,350,100,100,100); image(gmioumi5,450,100,100,100); } if(c!=oldstr2){ if( c=="1" || c=="2" || c=="3" || c=="4" || c=="5"){ oldstr2=c; str2=str2+c; println("**"+str2+"**"); } } }else if(choose==5){ //hard if(y<9){ if(millis()-xTime>500){ x=random(5); b=a; nowx=(int)x/1; if(nowx==oldx){ if(nowx==4){ x=1; oldx=(int)x/1; }else if(nowx==5){ x=2; oldx=(int)x/1; }else{ x=x+1; oldx=(int)x/1; } }else oldx=(int)x/1; if(x>0 && x<=1){ fill(0,0,0); rect(0,0,600,400); image(mioumi1,50,100,100,100); image(gmioumi2,150,100,100,100); image(gmioumi3,250,100,100,100); image(gmioumi4,350,100,100,100); image(gmioumi5,450,100,100,100); a="1"; }else if(x>1 && x<=2){ fill(0,0,0); rect(0,0,600,400); image(mioumi2,150,100,100,100); image(gmioumi1,50,100,100,100); image(gmioumi3,250,100,100,100); image(gmioumi4,350,100,100,100); image(gmioumi5,450,100,100,100); a="2"; }else if(x>2 && x<=3){ fill(0,0,0); rect(0,0,600,400); image(mioumi3,250,100,100,100); image(gmioumi1,50,100,100,100); image(gmioumi2,150,100,100,100); image(gmioumi4,350,100,100,100); image(gmioumi5,450,100,100,100); a="3"; }else if(x>3 && x<=4){ fill(0,0,0); rect(0,0,600,400); image(mioumi4,350,100,100,100); image(gmioumi1,50,100,100,100); image(gmioumi2,150,100,100,100); image(gmioumi3,250,100,100,100); image(gmioumi5,450,100,100,100); a="4"; }else if(x>4 && x<=5){ fill(0,0,0); rect(0,0,600,400); image(mioumi5,450,100,100,100); image(gmioumi1,50,100,100,100); image(gmioumi2,150,100,100,100); image(gmioumi3,250,100,100,100); image(gmioumi4,350,100,100,100); a="5"; } xTime=millis(); y=y+1; if(b!=a){ str=str+a; println(str); z=0; }else if(z==0 && b==a){ str=str+a; println(str); z=1; } }else if(millis()-xTime>200 && millis()-xTime<400){ fill(0,0,0); rect(0,0,600,400); image(gmioumi1,50,100,100,100); image(gmioumi2,150,100,100,100); image(gmioumi3,250,100,100,100); image(gmioumi4,350,100,100,100); image(gmioumi5,450,100,100,100); } }else if(e==2){ fill(0,0,0); rect(0,0,600,400); image(gmioumi1,50,100,100,100); image(gmioumi2,150,100,100,100); image(gmioumi3,250,100,100,100); image(gmioumi4,350,100,100,100); image(gmioumi5,450,100,100,100); } if(c!=oldstr2){ if( c=="1" || c=="2" || c=="3" || c=="4" || c=="5"){ oldstr2=c; str2=str2+c; println("**"+str2+"**"); e=3; } } } if(str=="" || str2==""){ str="1"; str2="1"; } f=Integer.parseInt(str); g=Integer.parseInt(str2); //f= new Integer(str).intValue(); //g= new Integer(str2).intValue(); if(c=="6" && e==2){ if(f==g){ image(pass,0,0,600,400); }else if(f!=g){ image(over,0,0,600,400); } }else if(c=="6" && e==3){ if(f==g){ image(win,0,0,600,400); }else{ image(over,0,0,600,400); } } if(mousePressed && mouseX>500 && mouseY>300){ if(choose==1){ choose=3; str=""; str2=""; }else if(choose==3){ choose=5; str=""; str2=""; } e=1; }else if(mousePressed && mouseX<100 && mouseY>300){ image(End,0,0,600,400); c="0"; e=4; } }
五,影片
課堂Demo影片:
這是成功最難的關卡之後的影片和畫面:
是顛倒的,抱歉QQ
六,心得
這次的遊戲,在規則上和設計上其實不難,但是我們寫程式的經驗依然不多,導致在過程中遇到了不少有關判斷式與環境不熟悉的問題,也因為這學期實在太多大型作業擠在一起的關係,看到我們自己與各組的作品完成度都沒有很高,感覺有點失望。
我們也是在考完期末考後的幾天才開始趕工、拚到凌晨,雖然很辛苦,但是也學到不少東西,是個難忘的回憶。對我們來說,這作業不只是學到技術層面的東西,也讓我們學到人與人之間的互先幫助與默契。對我們而言,這才是最可貴的。
程式方面,還是有一些bug未修復,但是,我們想說還是有機會的話能把它解決,讓作品呈現最完美的狀態。最後,還是感謝老師、助教和所以同學對我們作品的幫忙與支持。
謝謝 : D
沒有留言:
張貼留言