Prachi Kulkarni / Mbed 2 deprecated RPS-Player2

Dependencies:   4DGL-uLCD-SE PinDetect SDFileSystem mbed wave_player

Files at this revision

API Documentation at this revision

Comitter:
pkulkarni34
Date:
Wed Oct 21 23:41:47 2015 +0000
Parent:
1:5841ff349aae
Child:
3:fb5a647123cb
Commit message:
Player 2 before copy pasting

Changed in this revision

PinDetect.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PinDetect.lib	Wed Oct 21 23:41:47 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/AjK/code/PinDetect/#cb3afc45028b
--- a/main.cpp	Mon Oct 19 07:58:09 2015 +0000
+++ b/main.cpp	Wed Oct 21 23:41:47 2015 +0000
@@ -5,8 +5,13 @@
 #include "uLCD_4DGL.h"
 #include "SDFileSystem.h"
 #include "wave_player.h"
- 
+//#include "beep.h"
+
+DigitalOut myled(LED1);
+DigitalOut myled2(LED2);
 SDFileSystem sd(p5, p6, p7, p8, "sd");
+//AnalogOut DACout(p18);
+//Beep DACout(p18);
 AnalogOut DACout(p18);
 wave_player waver(&DACout); // Wave Player
 
@@ -16,9 +21,9 @@
 DigitalIn pb2(p19); //Pushbutton 2
 DigitalIn pb3(p20); //Pushbutton 3
 
-PwmOut led1(p21); //led 1
-PwmOut led2(p22); //led2
-PwmOut led3(p23); //led3
+//PwmOut led1(p21); //led 1
+//PwmOut led2(p22); //led2
+//PwmOut led3(p23); //led3
 
 //shiftbrite
 DigitalOut latch(p15);
@@ -29,8 +34,8 @@
 //Choice = 1 for rock
 //Choice = 2 for paper
 //Choice = 3 for scissors
-int choice1 = 0; //Player 1's choice
-int choice2 = 0; //Player 2's choice
+char choice1; //Player 1's choice
+char choice2; //Player 2's choice
 
 //Points
 int p1 = 0; //Player 1's points
@@ -51,8 +56,15 @@
 }
 
 
+// Serial
+Serial player2(p9, p10);
+
+
 int main() {
-    L1:
+
+    //Serial
+    player2.baud(9600);
+        
     spi.format(16,0);
     spi.frequency(500000);
     enable=0;
@@ -65,37 +77,70 @@
     wait(0.001);
     
     //Display 
-    lcd.locate(0,0);
-    //lcd_mutex.lock();
-    lcd.printf("Rock Paper Scissor");
-    lcd.locate(0,4);
-    lcd.printf("Button 1 for Rocks");
-    lcd.locate(0,6);
-    lcd.printf("Button 2 for Paper");
-    lcd.locate(0,8);
-    lcd.printf("Button 3 for Scissors\n\n");
-    lcd.printf("Press 1 to continue");
-    wait(2);
+    
+    lcd.locate(1,2);
+    //Screen 1 shows the name of the game
+    lcd.rectangle(0,0,125,125,WHITE); //Draw white border
+    lcd.color(BLUE); //Set font color to blue
+    lcd.text_bold(ON); //Bold the text
+    lcd.text_width(2);
+    lcd.text_height(2);
+    lcd.printf("  Rock\n");
+    lcd.printf("  Paper\n\n");
+    lcd.printf(" Scissor\n\n");
+    //DACout.beep(1000,0.5);
+    wait(5);
+    
+    //Screen 2 shows pushbutton options
+    L1:
+    lcd.cls();
+    lcd.rectangle(0,0,125,125,WHITE); //Draw white border
+    lcd.color(GREEN); //Set font color to green
+    lcd.locate(0,2);
+    lcd.printf(" Button Options\n\n");
+    lcd.locate(0,5);
+    lcd.text_underline(OFF);
+    lcd.printf("  1 for Rocks");
+    lcd.locate(0,7);
+    lcd.printf("  2 for Paper");
+    lcd.locate(0,9);
+    lcd.printf("  3 for Scissors\n\n\n");
+    lcd.text_bold(ON); //Bold the text
+    lcd.printf(" Press 1 to start!");
+    wait(1);
     
     while(1){
     //If push button 1 is pressed, start the game!
     if(pb1 != 1){
-    L3:
+        //Play button select
+            FILE *wave_file;
+             printf("\n\n\nHello, wave world!\n");
+            wave_file=fopen("/sd/mydir/select.wav","r");
+            waver.play(wave_file);
+            wait(1);
+            printf("ok!!");
+            fclose(wave_file);
+    //L3:
     lcd.cls(); //Clear screen
-    
+    lcd.rectangle(0,0,125,125,WHITE); //Draw white border
     //Tell player 1 that she/he has 5 seconds to chose between rock,paper and scissors
     lcd.locate(0,4);
-    lcd.printf("     Player 1 \n\n\n");
+    lcd.color(BLUE); //Set font color to yellow
+    lcd.printf("     Player 2 \n\n\n");
+    lcd.locate(0,6);
+    lcd.color(GREEN); //Set font color to green
     lcd.printf("You have 5 seconds");
     lcd.printf("    to choose\n");
     lcd.printf("    an option!\n");
-    wait(2);
+    wait(5);
     
 
     //Start timer for 5 seconds
-    int i;
+    int i = 5;
     int red = 1;
-    for(i = 5; i > -1 ; i--){
+    //for(i = 5; i > -1 ; i--){
+        while(i > -1){
+        
         lcd.cls();
         lcd.locate(4,4); //Place text in the center of the screen
         lcd.text_width(8); //Set tet width
@@ -107,73 +152,170 @@
         wait(1);
         //Press pushbutton 1 to choose rock
         if(pb1 != 1) {
+            
             lcd.cls();
-            choice1 = 1;
-            lcd.printf("You chose rock!");
+            choice2 = 'R';
+            lcd.rectangle(0,0,125,125,WHITE); //Draw white border
+            lcd.locate(0,1);
+            lcd.printf("  You chose rock");
+            
+             //Play button select
+            FILE *wave_file;
+             printf("\n\n\nHello, wave world!\n");
+            wave_file=fopen("/sd/mydir/select.wav","r");
+            waver.play(wave_file);
+            wait(1);
+            printf("ok!!");
+            fclose(wave_file);
             lcd.circle(60, 60, 30,WHITE);
-            wait(2);
+            wait(3);
             lcd.cls();
             break;
         }
         //Press pushbutton 2 to choose paper
-         if(pb2 != 1) {
+         else if(pb2 != 1) {
             lcd.cls();
-            choice1 = 2;
-            lcd.printf("You chose paper!");
-            lcd.rectangle(40, 60, 80,100,WHITE);
-            wait(2);
+            choice2 = 'P';
+            lcd.rectangle(0,0,125,125,WHITE); //Draw white border
+            
+            lcd.locate(0,1);
+            lcd.printf("  You chose paper");
+            
+             //Play button select
+            FILE *wave_file;
+             printf("\n\n\nHello, wave world!\n");
+            wave_file=fopen("/sd/mydir/select.wav","r");
+            waver.play(wave_file);
+          
+            printf("ok!!");
+            fclose(wave_file);
+            
+            lcd.filled_rectangle(50, 45, 80,90,WHITE);
+            wait(3);
             lcd.cls();
             break;
         }
         //Press pushbutton 3 to choose scissor
-           if(pb3 != 1) {
+           else if(pb3 != 1) {
             lcd.cls();
-            choice1 = 3;
-            lcd.printf("You chose scissors!");
+            choice2 = 'S';
+            lcd.rectangle(0,0,125,125,WHITE); //Draw white border
+            lcd.locate(0,1);
+            lcd.printf("You chose scissors");
+             //Play button select
+            FILE *wave_file;
+             printf("\n\n\nHello, wave world!\n");
+            wave_file=fopen("/sd/mydir/select.wav","r");
+            waver.play(wave_file);
+            wait(1);
+            printf("ok!!");
+            fclose(wave_file);
             lcd.circle(50, 60, 10,WHITE);
             lcd.circle(50, 80, 10,WHITE);
             lcd.line(62, 61, 90, 85, WHITE);
             lcd.line(62, 81, 90, 55, WHITE);
-            wait(2);
+            wait(3);
             lcd.cls();
             break;
         }
+        i--;
+        
         }
+        
+        
         RGB_LED(0,0,0); // Reset shitbrite color
+        
+ //-------------------------------------------------------------------------------------------------------------------------------------
+ //                                          TIME-OUT
+ //------------------------------------------------------------------------------------------------------------------------------------       
           
         //If user doesn't choose an option, show "Time Out" message and restart game
         if(i == -1){
             lcd.cls();
-            lcd.printf("Your time is up"); 
-            wait(5);
+            lcd.rectangle(0,0,125,125,WHITE); //Draw white border
+            lcd.locate(0,5);
+            lcd.color(RED);
+            lcd.printf(" Your time is up!"); 
+            lcd.color(GREEN);
+              //Play time up tune
+            FILE *wave_file;
+             printf("\n\n\nHello, wave world!\n");
+            wave_file=fopen("/sd/mydir/timeup.wav","r");
+            waver.play(wave_file);
+            
+            printf("ok!!");
+            fclose(wave_file);
+            wait(3);
             goto L1; //Starts the game again
             }  
             
-    lcd.cls(); //Clear screen
-    wait(2);
+ //--------------------------------------------------------------------------------------------------------------------------------------           
+  
+    //data = 'u';
+    //data = btserial.getc();
+    
+    player2.printf("%c",choice2);
+    myled = 1;
+    wait(1);
+    
+        while(1){
+    if(player2.readable()){
+        choice1 = player2.getc();
+        myled2 = 1;
+        break;
+        } 
+        }
+    
+    
+            
+   // lcd.cls(); //Clear screen
+   // wait(2);
+  /*
+  //--------------------------------------------------------------------------------------------------------------------------------  
+ //------------------------------- PLAYER 2 -------------------------------------------------------------------------------------- 
+ //-------------------------------------------------------------------------------------------------------------------------------  
     
     //Check to see if Player 2 is ready to play
-    lcd.printf("Press 1 if P2 is  ready");
+    lcd.rectangle(0,0,125,125,WHITE); //Draw white border
+    lcd.locate(0,5);
+    lcd.printf("  Press 1 if P2\n\n    is ready");
     
     //Start timer for player 2 if player 2 presses pushbutton 1
     while(1){
-        if(pb1 != 1) break;
+        if(pb1 != 1) 
+        {    //Play button select
+            FILE *wave_file;
+             printf("\n\n\nHello, wave world!\n");
+            wave_file=fopen("/sd/mydir/select.wav","r");
+            waver.play(wave_file);
+          
+            printf("ok!!");
+            fclose(wave_file);
+            break;
+            }
         }
     lcd.cls();
     wait(1);
     
+    lcd.rectangle(0,0,125,125,WHITE); //Draw white border
+    //Tell player 1 that she/he has 5 seconds to chose between rock,paper and scissors
     lcd.locate(0,4);
+    lcd.color(BLUE); //Set font color to yellow
     lcd.printf("     Player 2 \n\n\n");
+    lcd.locate(0,6);
+    lcd.color(GREEN); //Set font color to green  
     lcd.printf("You have 5 seconds");
     lcd.printf("    to choose\n");
     lcd.printf("    an option!\n");
-    wait(5);
+    wait(4);
+    
     
 
     
     int j;
     int blue = 1;
     for(j = 5; j > -1 ; j--){
+       
         lcd.cls();
         lcd.locate(4,4);
         lcd.text_width(8);
@@ -187,9 +329,19 @@
         if(pb1 != 1) {
             lcd.cls();
             choice2 = 1;
-            lcd.printf("You chose rock!");
+            lcd.rectangle(0,0,125,125,WHITE); //Draw white border
+            lcd.locate(0,1);
+            lcd.printf("  You chose rock!");
+             //Play button select
+            FILE *wave_file;
+             printf("\n\n\nHello, wave world!\n");
+            wave_file=fopen("/sd/mydir/select.wav","r");
+            waver.play(wave_file);
+            
+            printf("ok!!");
+            fclose(wave_file);
             lcd.circle(60, 60, 30,WHITE);
-            wait(2);
+            wait(3);
             lcd.cls();
             break;
         }
@@ -197,9 +349,19 @@
          if(pb2 != 1) {
             lcd.cls();
             choice2 = 2;
-            lcd.printf("You chose paper!");
-            lcd.rectangle(40, 60, 80,100,WHITE);
-            wait(2);
+            lcd.rectangle(0,0,125,125,WHITE); //Draw white border
+            lcd.locate(0,1);
+            lcd.printf("  You chose paper");
+             //Play button select
+            FILE *wave_file;
+             printf("\n\n\nHello, wave world!\n");
+            wave_file=fopen("/sd/mydir/select.wav","r");
+            waver.play(wave_file);
+         
+            printf("ok!!");
+            fclose(wave_file);
+            lcd.filled_rectangle(50, 45, 80,90,WHITE);
+            wait(3);
             lcd.cls();
             break;
         }
@@ -207,39 +369,72 @@
            if(pb3 != 1) {
             lcd.cls();
             choice2 = 3;
-            lcd.printf("You chose scissors!");
+            lcd.rectangle(0,0,125,125,WHITE); //Draw white border
+            lcd.locate(0,1);
+            lcd.printf("You chose scissors");
+             //Play button select
+            FILE *wave_file;
+             printf("\n\n\nHello, wave world!\n");
+            wave_file=fopen("/sd/mydir/select.wav","r");
+            waver.play(wave_file);
+          
+            printf("ok!!");
+            fclose(wave_file);
             lcd.circle(50, 60, 10,WHITE);
             lcd.circle(50, 80, 10,WHITE);
             lcd.line(62, 61, 90, 85, WHITE);
             lcd.line(62, 81, 90, 55, WHITE);
-            wait(2);
+            wait(3);
             lcd.cls();
             break;
         }
         }   
         
+//----------------------------------------------------------------------------------------------------------------------------------------
+//                                          TIME-OUT
+//----------------------------------------------------------------------------------------------------------------------------------------        
         //Time out message
         if(j == -1){
             lcd.cls();
-            lcd.printf("Your time is up"); 
-            wait(5);
+            lcd.rectangle(0,0,125,125,WHITE); //Draw white border
+            lcd.locate(0,5);
+            lcd.color(RED);
+            lcd.printf(" Your time is up!"); 
+            lcd.color(GREEN);
+            //Play time up tune
+            FILE *wave_file;
+             printf("\n\n\nHello, wave world!\n");
+            wave_file=fopen("/sd/mydir/timeup.wav","r");
+            waver.play(wave_file);
+            
+            printf("ok!!");
+            fclose(wave_file);
+            wait(3);
             goto L1;
             }  
          RGB_LED(0,0,0);   
-            
-    
+  */
+  
+ 
+//-------------------------------------------------------------------------------------------------------------------------------------    
         //Check to see who won
         
         //Case 1 : Both players choose same option        
-        if(choice1 == 1 && choice2 == 1 ||
-            choice1== 2 && choice2 == 2 || 
-            choice1 == 3 && choice2 == 3 ) {
+        if(choice1 == 'R' && choice2 == 'R' ||
+            choice1== 'P' && choice2 == 'P'|| 
+            choice1 == 'S' && choice2 == 'S' ) {
                 lcd.cls();
-                lcd.printf("It's a draw!");
+                lcd.rectangle(0,0,125,125,WHITE); //Draw white border
+                lcd.locate(1,2);
+                lcd.printf("  It's a draw!");
                 wait(4);
                 lcd.cls();
-                lcd.printf("Press 1 to continue\n\n");
-                lcd.printf("Press 2 to end\n\n");
+                lcd.locate(1,4);
+                lcd.rectangle(0,0,125,125,WHITE); //Draw white border
+                lcd.printf(" P1 Score : %d\n",p1);
+                lcd.printf("  P2 Score : %d\n\n\n\n",p2);
+                lcd.printf("  1 to continue\n\n");
+                lcd.printf("  2 to end\n\n");
                 
                 while(1){
                     if(pb1 != 1) {
@@ -252,19 +447,26 @@
           //Case 2:
           //Player 1 : Rock
           //Player 2 : Paper      
-          else if(choice1 == 1 && choice2 == 2){
+          else if(choice1 == 'R' && choice2 == 'P'){
               
                 lcd.cls();
-                lcd.printf("Player 1 chose Rock\n");
-                lcd.printf("Player 2 chose Paper\n\n");
+                lcd.rectangle(0,0,125,125,WHITE); //Draw white border
                 
-                lcd.printf("Player 2 wins!");
-                lcd.rectangle(40, 60, 80,100,WHITE);
+                lcd.locate(1,2);
+                lcd.printf(" P1 chose Rock\n");
+                lcd.printf("  P2 chose Paper\n\n\n\n");
+                lcd.locate(1,5);
+                lcd.printf(" Player 2 wins!");
+                lcd.filled_rectangle(50, 60, 80,90,WHITE);
                 p2++;
                 wait(4);
                 lcd.cls();
-                lcd.printf("Press 1 to continue\n\n");
-                lcd.printf("Press 2 to end\n\n");
+                lcd.locate(1,4);
+                lcd.rectangle(0,0,125,125,WHITE); //Draw white border
+                lcd.printf(" P1 Score : %d\n",p1);
+                lcd.printf("  P2 Score : %d\n\n\n\n",p2);
+                lcd.printf("  1 to continue\n\n");
+                lcd.printf("  2 to end\n\n");
                 
                 while(1){
                     if(pb1 != 1) {
@@ -273,24 +475,29 @@
                     }
                     else if(pb2 != 1) goto L2;
                 }
-               }}
+               }
            //Case 3:
           //Player 1 : Paper
           //Player 2 : Rock
-            else if(choice2== 1 && choice1== 2){
+            else if(choice2== 'P' && choice1== 'R'){
               
                 lcd.cls();
+                lcd.rectangle(0,0,125,125,WHITE); //Draw white border
+                lcd.locate(1,2);
                 lcd.printf("P1 chose Paper\n");
-                lcd.printf("P2 chose Rock\n\n");
+                lcd.printf(" P2 chose Rock\n\n");
+                lcd.locate(1,5);
                 lcd.printf("P1 wins!");
-                lcd.rectangle(40, 60, 80,100,WHITE);
+                lcd.filled_rectangle(50, 60, 80,90,WHITE);
                 p1++;
                 wait(5);
                 lcd.cls();
-                lcd.printf("P1 Score : %d\n",p1);
-                lcd.printf("P2 Score : %d\n\n",p2);
-                lcd.printf("Press 1 to continue\n\n");
-                lcd.printf("Press 2 to end\n\n");
+                lcd.locate(1,4);
+                lcd.rectangle(0,0,125,125,WHITE); //Draw white border
+                lcd.printf(" P1 Score : %d\n",p1);
+                lcd.printf("  P2 Score : %d\n\n\n\n",p2);
+                lcd.printf("  1 to continue\n\n");
+                lcd.printf("  2 to end\n\n");
                 
                 while(1){
                     if(pb1 != 1) {
@@ -305,13 +512,14 @@
           //Player 1 : Paper
           //Player 2 : Scissor
     
-            else if(choice1 == 2 && choice2 == 3){
+            else if(choice1 == 'P' && choice2 == 'S'){
               
                 lcd.cls();
+                lcd.locate(1,1);
                 lcd.printf("P1 chose Paper\n");
-                lcd.printf("P2 chose Scissors\n\n");
-                
-                lcd.printf("Player 2 wins!");
+                lcd.printf(" P2 chose Scissors\n\n");
+                lcd.locate(1,4);
+                lcd.printf("P2 wins!");
                 p2++;
                 lcd.circle(50, 60, 10,WHITE);
                 lcd.circle(50, 80, 10,WHITE);
@@ -319,10 +527,12 @@
                 lcd.line(62, 81, 90, 55, WHITE);
                 wait(5);
                 lcd.cls();
-                lcd.printf("P1 Score : %d\n",p1);
-                lcd.printf("P2 Score : %d\n\n",p2);
-                lcd.printf("Press 1 to continue\n\n");
-                lcd.printf("Press 2 to end\n\n");
+                lcd.locate(1,4);
+                lcd.rectangle(0,0,125,125,WHITE); //Draw white border
+                lcd.printf(" P1 Score : %d\n",p1);
+                lcd.printf("  P2 Score : %d\n\n\n\n",p2);
+                lcd.printf("  1 to continue\n\n");
+                lcd.printf("  2 to end\n\n");
                 
                 while(1){
                     if(pb1 != 1) {
@@ -335,13 +545,13 @@
     //Case 5:
     //Player 1 : Scissor
     //Player 2 : Paper
-    else if(choice1 == 3 && choice2 == 2){
+    else if(choice1 == 'S' && choice2 == 'P'){
               
                 lcd.cls();
-            
+                lcd.locate(1,1);
                 lcd.printf("P1 chose Scissors\n");
-                lcd.printf("P2 chose Paper\n\n");
-                
+                lcd.printf(" P2 chose Paper\n\n");
+                lcd.locate(1,4);
                 lcd.printf("P1 wins!");
                 p1++;
                 lcd.circle(50, 60, 10,WHITE);
@@ -350,10 +560,12 @@
                 lcd.line(62, 81, 90, 55, WHITE);
                 wait(5);
                 lcd.cls();
-                lcd.printf("P1 Score : %d\n",p1);
-                lcd.printf("P2 Score : %d\n\n",p2);
-                lcd.printf("Press 1 to continue\n\n");
-                lcd.printf("Press 2 to end\n\n");
+                lcd.locate(1,4);
+                lcd.rectangle(0,0,125,125,WHITE); //Draw white border
+                lcd.printf(" P1 Score : %d\n",p1);
+                lcd.printf("  P2 Score : %d\n\n\n\n",p2);
+                lcd.printf("  1 to continue\n\n");
+                lcd.printf("  2 to end\n\n");
                 
                 while(1){
                     if(pb1 != 1) {
@@ -366,21 +578,24 @@
     //Case 6:
     //Player 1 : Rock
     //Player 2 : Scissors
-    else if(choice1 == 1 && choice2 == 3){
+    else if(choice1 == 'R' && choice2 == 'S'){
               
                 lcd.cls();
+                lcd.locate(1,1);
                 lcd.printf("P1 chose Rock\n");
-                lcd.printf("P2 chose Scissors\n\n");
-                
+                lcd.printf(" P2 chose Scissors\n\n");
+                lcd.locate(1,3);
                 lcd.printf("P1 wins!");
                 p1++;
-                lcd.circle(60, 60, 30,WHITE);
+                lcd.circle(60, 70, 30,WHITE);
                 wait(5);
                 lcd.cls();
-                lcd.printf("P1 Score : %d\n",p1);
-                lcd.printf("P2 Score : %d\n\n",p2);
-                lcd.printf("Press 1 to continue\n\n");
-                lcd.printf("Press 2 to end\n\n");
+                lcd.locate(1,4);
+                lcd.rectangle(0,0,125,125,WHITE); //Draw white border
+                lcd.printf(" P1 Score : %d\n",p1);
+                lcd.printf("  P2 Score : %d\n\n\n\n",p2);
+                lcd.printf("  1 to continue\n\n");
+                lcd.printf("  2 to end\n\n");
                 
                 while(1){
                     if(pb1 != 1) {
@@ -394,21 +609,24 @@
     //Player 1 : Scissors
     //Player 2 : Rock      
                
-    else if(choice1 == 3 && choice2 == 1){
+    else if(choice1 == 'S' && choice2 == 'R'){
               
                 lcd.cls();
+                lcd.locate(1,1);
                 lcd.printf("P1 chose Scissors\n");
-                lcd.printf("P2 chose Rock\n\n");
-                
+                lcd.printf(" P2 chose Rock\n\n");
+                lcd.locate(1,3);
                 lcd.printf("P2 wins!");
                 p2++;
-                lcd.circle(60, 60, 30,WHITE);
+                lcd.circle(60, 70, 30,WHITE);
                 wait(5);
                 lcd.cls();
-                lcd.printf("P1 Score : %d\n",p1);
-                lcd.printf("P2 Score : %d\n\n",p2);
-                lcd.printf("Press 1 to continue\n\n");
-                lcd.printf("Press 2 to end\n\n");
+                lcd.locate(1,4);
+                lcd.rectangle(0,0,125,125,WHITE); //Draw white border
+                lcd.printf(" P1 Score : %d\n",p1);
+                lcd.printf("  P2 Score : %d\n\n\n\n",p2);
+                lcd.printf("  1 to continue\n\n");
+                lcd.printf("  2 to end\n\n");
                 
                 while(1){
                     if(pb1 != 1) {
@@ -426,25 +644,26 @@
     
     
     // Code to play a wave file
-    /* FILE *wave_file;
+    FILE *wave_file;
     printf("\n\n\nHello, wave world!\n");
     wave_file=fopen("/sd/mydir/HG.wav","r");
     waver.play(wave_file);
     wait(5);
     printf("ok!!");
     fclose(wave_file);
-    */
     
     
+  
 //If game ends :
 L2:
-lcd.cls();
+                        lcd.cls();
 
 
                         //Create animation of two bouncing balls
-                        float fx=50.0,fy=21.0,vx=5.0,vy=0.4,vx2=5,fx2=40.0;
+                        float fx=50.0,fy=21.0,vx=5.0,vy=0.4,vx2=2,fx2=40.0;
                         int x=50,y=21,radius=4;
                         int x2 = 30, y2 = 10;
+                        //lcd.rectangle(0,0,125,125,GREEN); //Draw green border
                         //draw walls
                         wait(2);
                         //If Player 1's score is higher than Player 2's score
@@ -460,6 +679,14 @@
                         //lcd.printf("Player 2 wins!");
                        lcd.text_string("Player 2 Wins!", 2, 4, FONT_7X8, WHITE);
                        
+                        // Play winning tune
+                        FILE *wave_file;
+                        printf("\n\n\nHello, wave world!\n");
+                        wave_file=fopen("/sd/mydir/win.wav","r");
+                        waver.play(wave_file);
+                     
+                        printf("ok!!");
+                        fclose(wave_file);
                        
                             for (int i=0; i<100; i++) {
                                 //draw ball
@@ -496,9 +723,8 @@
                                 x2=(int)fx2;
                                 y2=(int)fy;
                                 }
-wait(3);
-lcd.cls();
-lcd.printf("End!");
-wait(3);
-lcd.cls();
-}
\ No newline at end of file
+lcd.cls();     
+                    
+
+
+}