A retro gaming programme, designed for use on a portable embedded system. Incorporates power saving techniques.

Dependencies:   ConfigFile N5110 PowerControl beep mbed

Files at this revision

API Documentation at this revision

Comitter:
el13drt
Date:
Mon Apr 20 17:23:59 2015 +0000
Parent:
24:eb80956e2e95
Child:
26:83e181f04c9a
Commit message:
pre initial store

Changed in this revision

tower.h Show annotated file Show diff for this revision Revisions of this file
--- a/tower.h	Mon Apr 20 15:28:01 2015 +0000
+++ b/tower.h	Mon Apr 20 17:23:59 2015 +0000
@@ -47,13 +47,19 @@
 // boundary conditions
 int cells [84][48];
 
-// player's score
+// player's score (in game)
 int score = 0;
 
-int highScore1 = 5;
-int highScore2 = 3;
+//high score details
+int highScore1 = 10;
+int highScore2 = 1;
 int highScore3 = 0;
 
+//player initials
+char player1initials[3];
+char player2initials[3];
+char player3initials[3];
+
 // difficulty - number of pixels hazards incrememnt by
 int fall = 2;
 
@@ -85,7 +91,9 @@
 
 // struct for choosing initials
 struct State {
-    char output;
+    char output1;
+    char output2;
+    char output3;
     int nextState[2];
 };
 typedef const struct State STYP;
@@ -97,32 +105,32 @@
 
     //output//nextstate//previousstate//
 
-    {'A',{1,25}},
-    {'B',{2,0}},
-    {'C',{3,1}},
-    {'D',{4,2}},
-    {'E',{5,3}},
-    {'F',{6,4}},
-    {'G',{7,5}},
-    {'H',{8,6}},
-    {'I',{9,7}},
-    {'J',{10,8}},
-    {'K',{11,9}},
-    {'L',{12,10}},
-    {'M',{13,11}},
-    {'N',{14,12}},
-    {'O',{15,13}},
-    {'P',{16,14}},
-    {'Q',{17,15}},
-    {'R',{18,16}},
-    {'S',{19,17}},
-    {'T',{20,18}},
-    {'U',{21,19}},
-    {'V',{22,20}},
-    {'W',{23,21}},
-    {'X',{24,22}},
-    {'Y',{25,23}},
-    {'Z',{0,24}},
+    {'A','A','A',{1,25}},
+    {'B','B','B',{2,0}},
+    {'C','C','C',{3,1}},
+    {'D','D','D',{4,2}},
+    {'E','E','E',{5,3}},
+    {'F','F','F',{6,4}},
+    {'G','G','G',{7,5}},
+    {'H','H','H',{8,6}},
+    {'I','I','I',{9,7}},
+    {'J','J','J',{10,8}},
+    {'K','K','K',{11,9}},
+    {'L','L','L',{12,10}},
+    {'M','M','M',{13,11}},
+    {'N','N','N',{14,12}},
+    {'O','O','O',{15,13}},
+    {'P','P','P',{16,14}},
+    {'Q','Q','Q',{17,15}},
+    {'R','R','R',{18,16}},
+    {'S','S','S',{19,17}},
+    {'T','T','T',{20,18}},
+    {'U','U','U',{21,19}},
+    {'V','V','V',{22,20}},
+    {'W','W','W',{23,21}},
+    {'X','X','X',{24,22}},
+    {'Y','Y','Y',{25,23}},
+    {'Z','Z','Z',{0,24}},
 };
 
 // function prototypes
@@ -866,8 +874,8 @@
         lcd.printString("High Score!!",7,0);//title
         lcd.printString("Enter ID",19,4);//title
         int n;//local variable used for storing temporary global variable
-        int initial = 0;
-
+        int initial = 0;//used for isolating which initial is being selected
+        
         // if player beats High Score 3, replace it with new score
         if(score >= highScore3) {
             n = score;
@@ -881,7 +889,6 @@
         }
         // if player beats High Score 1, 2 and 3, replace highScore1 with new score
         if(score >= highScore1) {
-
             highScore3 = highScore2;
             highScore2 = highScore1;
             n = score;
@@ -894,7 +901,6 @@
             // joystick selection
             if (printFlag) {//if flag set, clear flag,print joystick values
                 printFlag = 0;
-
                 // option up
                 if (joystick.direction == UP) {
                     serial.printf(" UP\n");
@@ -929,28 +935,49 @@
             char buffer1[14];//create buffer for strings
             char buffer2[14];
             char buffer3[14];
-
+            
+            // if initial 3 display selected character
             if (initial == 0) {
-                int initial1 = sprintf(buffer1,"%c",fsm[state].output);//insert scores}
+                int initial1 = sprintf(buffer1,"%c",fsm[state].output1);//insert scores}
                 if (initial1 <= 14)  //ensure length is smaller than screen
                     lcd.printString(buffer1,25,26);//display
             }
+            // if initial 1 display selected character
             if(initial == 1) {
-                int initial2 = sprintf(buffer2,"%c",fsm[state].output);//into buffers
+                int initial2 = sprintf(buffer2,"%c",fsm[state].output2);//into buffers
                 if (initial2 <= 14)  //ensure length is smaller than screen
                     lcd.printString(buffer2,37,26);//display
             }
+            // if initial 2 display selected character
             if(initial == 2) {
-                int initial3 = sprintf(buffer3,"%c",fsm[state].output);
+                int initial3 = sprintf(buffer3,"%c",fsm[state].output3);
                 if (initial3 <= 14)  //ensure length is smaller than screen
                     lcd.printString(buffer3,49,26);//display
             }
             //inwhile
+            if(buttonFlagA) {
+                buttonFlagA = 0;
+                buttonFlagB = 0;
+                char x = fsm[state].output1;
+                char y = fsm[state].output2;
+                char z = fsm[state].output3;
 
+    
+                    int insert = sprintf (player1initials, "1.%c%c%c.....%i",x,y,z,highScore1);
+                
+                //if(score>=highScore2) {
+//                    int insert = sprintf (player2initials, "1.%c%c%c.....%i",x,y,z,highScore2);
+//                }
+//                if(score >= highScore3) {
+//                    int insert = sprintf (player3initials, "1.%c%c%c.....%i",x,y,z,highScore3);
+//                }
+                break;
+            }
         }
     }
 }
 
+
 // actual game
 void game(int& exitFlag, int& exitOption)
 {
@@ -1093,20 +1120,18 @@
     lcd.clear();//clear screen
     backGround();//set background
     lcd.printString("High Scores",10,0);//title
-    
+
     // players high scores - highest first
     char buffer1[14];//create buffer for strings
     char buffer2[14];
     char buffer3[14];
-    
-    char name1 = 'D';
 
-    int player1 = sprintf(buffer1,"1.%c.....%i",name1,highScore1);//insert scores
-    int player2 = sprintf(buffer2,"2.NRG.....%i",highScore2);//into buffers
-    int player3 = sprintf(buffer3,"3.GRT.....%i",highScore3);
+    int player1 = sprintf(buffer1,"1.%c......%i",player1initials,highScore1);//insert scores
+    int player2 = sprintf(buffer2,"2.%c......%i",player2initials,highScore2);//and names in 
+    int player3 = sprintf(buffer3,"3.%c......%i",player3initials,highScore3);//to the buffer
 
     if (player1 <= 14)  //ensure length is smaller than screen
-        lcd.printString(buffer1,5,2);//display
+        lcd.printString(player1initials,5,2);//display
     if (player2 <= 14)  //ensure length is smaller than screen
         lcd.printString(buffer2,5,3);//display
     if (player3 <= 14)  //ensure length is smaller than screen
@@ -1117,7 +1142,8 @@
 
         // back to menu
         if(buttonFlagB) {
-            buttonFlagB = 0;//reset flag
+            buttonFlagA = 0;//reset flags
+            buttonFlagB = 0;
             lcd.clear();
             break;
         }