Created
November 4, 2012 10:03
-
-
Save pureexe/4011147 to your computer and use it in GitHub Desktop.
"song of memories" ver.ipst 01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| Project Name :: Song Of Memories | |
| Author :: ? | |
| LC :: ? | |
| Description :: BringLed is game :D | |
| System Requirement :: | |
| Device :: IPSTmicrobox | |
| Compiler :: AVR16mhz | |
| Device Module :: | |
| 4 Button (Port A0,A1,A2,A3,A4) | |
| 4 LED (Port D0,D1,D2,D3,D4) | |
| 1 LCD_Displat IO | |
| **/ | |
| #include<ipst.h> | |
| #include<stdlib.h> | |
| #include<time.h> | |
| int *tab; | |
| int level; | |
| int round; | |
| int score=0; | |
| int waitkey(){ | |
| while(1) | |
| { | |
| if(in_a(0)) | |
| return 0; | |
| if(in_a(1)) | |
| return 1; | |
| if(in_a(2)); | |
| return 2; | |
| if(in_a(3)) | |
| return 3; | |
| if(in_a(4)) | |
| return 4; | |
| } | |
| } | |
| int getcountkey(){ | |
| int counting=0; | |
| while(1) | |
| { | |
| if(waitkey()==1) | |
| { | |
| return counting; | |
| } | |
| counting++; | |
| } | |
| } | |
| void bringled(){ | |
| int i; | |
| srand(time(NULL)); | |
| for(i=0;i<level;i++) | |
| { | |
| tab[i]=rand()%4; | |
| out_d(tab[i],1); | |
| sleep(1000); | |
| out_d(tab[i],0); | |
| sleep(500); | |
| } | |
| lcd("#c"); | |
| lcd("Wait Button input"); | |
| } | |
| int listener() | |
| { | |
| int ans=1,ct=0; | |
| char x; | |
| while(ct<level) | |
| { | |
| if(waitkey()!=tab[ct]) | |
| { | |
| ans=0; | |
| } | |
| ct++; | |
| } | |
| return ans; | |
| } | |
| int playing(){ | |
| int i; | |
| tab=(int*)malloc(sizeof(int)*level); | |
| for(i=0;i<round;i++) | |
| { | |
| bringled(); | |
| score+=listener(); | |
| if(i<round-1) | |
| { | |
| lcd("#c"); | |
| lcd("Wait 2 second for next round"); | |
| sleep(2000); | |
| } | |
| } | |
| lcd("#c"); | |
| lcd("Your Hit Rate = %.2f%%",((float)score/round)*100); | |
| } | |
| int main(){ | |
| lcd("#c"); | |
| lcd("Press button for Round you want play!"); | |
| round=getcountkey(); | |
| lcd("#c"); | |
| lcd("Round to play is set to %d round",round); | |
| sleep(2000); | |
| lcd("#c"); | |
| lcd("Press button for Level you want play!"); | |
| level=getcountkey(); | |
| lcd("#c"); | |
| lcd("Level to play is set to %d",level); | |
| playing(); | |
| sleep(5000); | |
| lcd("#c"); | |
| lcd("Terminate !!! You need to restart machine to Continue playing"); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment