A Card Matching Game using uLCD and Touchpad
Dependencies: 4DGL-uLCD-SE mbed-rtos mbed
match.cpp@0:d77e1909cdc7, 2014-10-22 (annotated)
- Committer:
- mtaylor33
- Date:
- Wed Oct 22 00:12:42 2014 +0000
- Revision:
- 0:d77e1909cdc7
Card Match Game
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mtaylor33 | 0:d77e1909cdc7 | 1 | #include "mbed.h" |
mtaylor33 | 0:d77e1909cdc7 | 2 | //#include "cstdlib.h" |
mtaylor33 | 0:d77e1909cdc7 | 3 | //#include "rtos.h" |
mtaylor33 | 0:d77e1909cdc7 | 4 | #include "uLCD_4DGL.h" |
mtaylor33 | 0:d77e1909cdc7 | 5 | #include <string> |
mtaylor33 | 0:d77e1909cdc7 | 6 | #include <list> |
mtaylor33 | 0:d77e1909cdc7 | 7 | #include <mpr121.h> |
mtaylor33 | 0:d77e1909cdc7 | 8 | |
mtaylor33 | 0:d77e1909cdc7 | 9 | #define YELLOW 0xFFFF00 |
mtaylor33 | 0:d77e1909cdc7 | 10 | #define PURPLE 0x800080 |
mtaylor33 | 0:d77e1909cdc7 | 11 | #define ORANGE 0xFFA500 |
mtaylor33 | 0:d77e1909cdc7 | 12 | #define Color1 RED |
mtaylor33 | 0:d77e1909cdc7 | 13 | #define Color2 BLUE |
mtaylor33 | 0:d77e1909cdc7 | 14 | #define Color3 ORANGE |
mtaylor33 | 0:d77e1909cdc7 | 15 | #define Color4 GREEN |
mtaylor33 | 0:d77e1909cdc7 | 16 | #define Color5 PURPLE |
mtaylor33 | 0:d77e1909cdc7 | 17 | #define Color6 YELLOW |
mtaylor33 | 0:d77e1909cdc7 | 18 | |
mtaylor33 | 0:d77e1909cdc7 | 19 | |
mtaylor33 | 0:d77e1909cdc7 | 20 | uLCD_4DGL uLCD(p28, p27, p29); // create a global lcd object |
mtaylor33 | 0:d77e1909cdc7 | 21 | |
mtaylor33 | 0:d77e1909cdc7 | 22 | DigitalOut led1(LED1); |
mtaylor33 | 0:d77e1909cdc7 | 23 | DigitalOut led2(LED2); |
mtaylor33 | 0:d77e1909cdc7 | 24 | DigitalOut led3(LED3); |
mtaylor33 | 0:d77e1909cdc7 | 25 | DigitalOut led4(LED4); |
mtaylor33 | 0:d77e1909cdc7 | 26 | |
mtaylor33 | 0:d77e1909cdc7 | 27 | |
mtaylor33 | 0:d77e1909cdc7 | 28 | // Create the interrupt receiver object on pin 26 |
mtaylor33 | 0:d77e1909cdc7 | 29 | InterruptIn interrupt(p26); |
mtaylor33 | 0:d77e1909cdc7 | 30 | |
mtaylor33 | 0:d77e1909cdc7 | 31 | // Setup the Serial to the PC for debugging |
mtaylor33 | 0:d77e1909cdc7 | 32 | //Serial pc(USBTX, USBRX); |
mtaylor33 | 0:d77e1909cdc7 | 33 | |
mtaylor33 | 0:d77e1909cdc7 | 34 | // Setup the i2c bus on pins 28 and 27 |
mtaylor33 | 0:d77e1909cdc7 | 35 | I2C i2c(p9, p10); |
mtaylor33 | 0:d77e1909cdc7 | 36 | |
mtaylor33 | 0:d77e1909cdc7 | 37 | // Setup the Mpr121: |
mtaylor33 | 0:d77e1909cdc7 | 38 | // constructor(i2c object, i2c address of the mpr121) |
mtaylor33 | 0:d77e1909cdc7 | 39 | Mpr121 mpr121(&i2c, Mpr121::ADD_VSS); |
mtaylor33 | 0:d77e1909cdc7 | 40 | |
mtaylor33 | 0:d77e1909cdc7 | 41 | volatile int keypress; |
mtaylor33 | 0:d77e1909cdc7 | 42 | |
mtaylor33 | 0:d77e1909cdc7 | 43 | void fallInterrupt() { |
mtaylor33 | 0:d77e1909cdc7 | 44 | int key_code=0; |
mtaylor33 | 0:d77e1909cdc7 | 45 | int i=0; |
mtaylor33 | 0:d77e1909cdc7 | 46 | int value=mpr121.read(0x00); |
mtaylor33 | 0:d77e1909cdc7 | 47 | value +=mpr121.read(0x01)<<8; |
mtaylor33 | 0:d77e1909cdc7 | 48 | // LED demo mod by J. Hamblen |
mtaylor33 | 0:d77e1909cdc7 | 49 | //pc.printf("MPR value: %x \r\n", value); |
mtaylor33 | 0:d77e1909cdc7 | 50 | i=0; |
mtaylor33 | 0:d77e1909cdc7 | 51 | // puts key number out to LEDs for demo |
mtaylor33 | 0:d77e1909cdc7 | 52 | for (i=0; i<12; i++) { |
mtaylor33 | 0:d77e1909cdc7 | 53 | if (((value>>i)&0x01)==1) key_code=i+1; |
mtaylor33 | 0:d77e1909cdc7 | 54 | } |
mtaylor33 | 0:d77e1909cdc7 | 55 | // led4=key_code & 0x01; |
mtaylor33 | 0:d77e1909cdc7 | 56 | // led3=(key_code>>1) & 0x01; |
mtaylor33 | 0:d77e1909cdc7 | 57 | // led2=(key_code>>2) & 0x01; |
mtaylor33 | 0:d77e1909cdc7 | 58 | // led1=(key_code>>3) & 0x01; |
mtaylor33 | 0:d77e1909cdc7 | 59 | keypress = key_code; |
mtaylor33 | 0:d77e1909cdc7 | 60 | |
mtaylor33 | 0:d77e1909cdc7 | 61 | } |
mtaylor33 | 0:d77e1909cdc7 | 62 | |
mtaylor33 | 0:d77e1909cdc7 | 63 | |
mtaylor33 | 0:d77e1909cdc7 | 64 | typedef struct Card |
mtaylor33 | 0:d77e1909cdc7 | 65 | { |
mtaylor33 | 0:d77e1909cdc7 | 66 | int Color; |
mtaylor33 | 0:d77e1909cdc7 | 67 | int x; |
mtaylor33 | 0:d77e1909cdc7 | 68 | int y; |
mtaylor33 | 0:d77e1909cdc7 | 69 | int Matched; |
mtaylor33 | 0:d77e1909cdc7 | 70 | }Card; |
mtaylor33 | 0:d77e1909cdc7 | 71 | |
mtaylor33 | 0:d77e1909cdc7 | 72 | typedef struct Deck |
mtaylor33 | 0:d77e1909cdc7 | 73 | { |
mtaylor33 | 0:d77e1909cdc7 | 74 | Card Cards[12]; |
mtaylor33 | 0:d77e1909cdc7 | 75 | }Deck; |
mtaylor33 | 0:d77e1909cdc7 | 76 | |
mtaylor33 | 0:d77e1909cdc7 | 77 | |
mtaylor33 | 0:d77e1909cdc7 | 78 | |
mtaylor33 | 0:d77e1909cdc7 | 79 | int Score1,Score2; |
mtaylor33 | 0:d77e1909cdc7 | 80 | int Used[] = {255,255,255,255,255,255,255,255,255,255,255,255}; |
mtaylor33 | 0:d77e1909cdc7 | 81 | |
mtaylor33 | 0:d77e1909cdc7 | 82 | int RColor(){ |
mtaylor33 | 0:d77e1909cdc7 | 83 | return rand()%16777215; |
mtaylor33 | 0:d77e1909cdc7 | 84 | } |
mtaylor33 | 0:d77e1909cdc7 | 85 | |
mtaylor33 | 0:d77e1909cdc7 | 86 | void Print_Card(int x, int y, int Color){ |
mtaylor33 | 0:d77e1909cdc7 | 87 | uLCD.filled_rectangle(x,y,x+15,y+20,Color); |
mtaylor33 | 0:d77e1909cdc7 | 88 | uLCD.rectangle(x,y,x+15,y+20,DGREY); |
mtaylor33 | 0:d77e1909cdc7 | 89 | //wait(.07); |
mtaylor33 | 0:d77e1909cdc7 | 90 | } |
mtaylor33 | 0:d77e1909cdc7 | 91 | |
mtaylor33 | 0:d77e1909cdc7 | 92 | |
mtaylor33 | 0:d77e1909cdc7 | 93 | void Shuffle(int count){ |
mtaylor33 | 0:d77e1909cdc7 | 94 | for(int i = 0; i<count; i++){ |
mtaylor33 | 0:d77e1909cdc7 | 95 | Print_Card(16,32,RColor()); |
mtaylor33 | 0:d77e1909cdc7 | 96 | Print_Card(43,32,RColor()); |
mtaylor33 | 0:d77e1909cdc7 | 97 | Print_Card(70,32,RColor()); |
mtaylor33 | 0:d77e1909cdc7 | 98 | Print_Card(97,32,RColor()); |
mtaylor33 | 0:d77e1909cdc7 | 99 | Print_Card(16,64,RColor()); |
mtaylor33 | 0:d77e1909cdc7 | 100 | Print_Card(43,64,RColor()); |
mtaylor33 | 0:d77e1909cdc7 | 101 | Print_Card(70,64,RColor()); |
mtaylor33 | 0:d77e1909cdc7 | 102 | Print_Card(97,64,RColor()); |
mtaylor33 | 0:d77e1909cdc7 | 103 | Print_Card(16,96,RColor()); |
mtaylor33 | 0:d77e1909cdc7 | 104 | Print_Card(43,96,RColor()); |
mtaylor33 | 0:d77e1909cdc7 | 105 | Print_Card(70,96,RColor()); |
mtaylor33 | 0:d77e1909cdc7 | 106 | Print_Card(97,96,RColor()); |
mtaylor33 | 0:d77e1909cdc7 | 107 | wait(.25); |
mtaylor33 | 0:d77e1909cdc7 | 108 | } |
mtaylor33 | 0:d77e1909cdc7 | 109 | } |
mtaylor33 | 0:d77e1909cdc7 | 110 | |
mtaylor33 | 0:d77e1909cdc7 | 111 | int ColorAssigner(int i){ |
mtaylor33 | 0:d77e1909cdc7 | 112 | int color = (i%6)+1; |
mtaylor33 | 0:d77e1909cdc7 | 113 | if(color == 6) return Color6; |
mtaylor33 | 0:d77e1909cdc7 | 114 | if(color == 1) return Color1; |
mtaylor33 | 0:d77e1909cdc7 | 115 | if(color == 2) return Color2; |
mtaylor33 | 0:d77e1909cdc7 | 116 | if(color == 3) return Color3; |
mtaylor33 | 0:d77e1909cdc7 | 117 | if(color == 4) return Color4; |
mtaylor33 | 0:d77e1909cdc7 | 118 | if(color == 5) return Color5; |
mtaylor33 | 0:d77e1909cdc7 | 119 | return BLACK; |
mtaylor33 | 0:d77e1909cdc7 | 120 | } |
mtaylor33 | 0:d77e1909cdc7 | 121 | |
mtaylor33 | 0:d77e1909cdc7 | 122 | |
mtaylor33 | 0:d77e1909cdc7 | 123 | void Setup(){ |
mtaylor33 | 0:d77e1909cdc7 | 124 | Score1 = 0; |
mtaylor33 | 0:d77e1909cdc7 | 125 | Score2 = 0; |
mtaylor33 | 0:d77e1909cdc7 | 126 | uLCD.filled_rectangle(0,20,127,127,LGREY); |
mtaylor33 | 0:d77e1909cdc7 | 127 | uLCD.filled_rectangle(0,0,127,19,DGREY); |
mtaylor33 | 0:d77e1909cdc7 | 128 | uLCD.color(PURPLE); |
mtaylor33 | 0:d77e1909cdc7 | 129 | uLCD.locate(1,0); |
mtaylor33 | 0:d77e1909cdc7 | 130 | uLCD.printf("Turns = %d ", Score1); |
mtaylor33 | 0:d77e1909cdc7 | 131 | uLCD.color(ORANGE); |
mtaylor33 | 0:d77e1909cdc7 | 132 | uLCD.locate(1,1); |
mtaylor33 | 0:d77e1909cdc7 | 133 | uLCD.printf("Matchs = %d ", Score2); |
mtaylor33 | 0:d77e1909cdc7 | 134 | Shuffle((rand()%5)); |
mtaylor33 | 0:d77e1909cdc7 | 135 | Shuffle(1); |
mtaylor33 | 0:d77e1909cdc7 | 136 | Print_Card(16,32,LGREY); |
mtaylor33 | 0:d77e1909cdc7 | 137 | Print_Card(43,32,LGREY); |
mtaylor33 | 0:d77e1909cdc7 | 138 | Print_Card(70,32,LGREY); |
mtaylor33 | 0:d77e1909cdc7 | 139 | Print_Card(97,32,LGREY); |
mtaylor33 | 0:d77e1909cdc7 | 140 | Print_Card(16,64,LGREY); |
mtaylor33 | 0:d77e1909cdc7 | 141 | Print_Card(43,64,LGREY); |
mtaylor33 | 0:d77e1909cdc7 | 142 | Print_Card(70,64,LGREY); |
mtaylor33 | 0:d77e1909cdc7 | 143 | Print_Card(97,64,LGREY); |
mtaylor33 | 0:d77e1909cdc7 | 144 | Print_Card(16,96,LGREY); |
mtaylor33 | 0:d77e1909cdc7 | 145 | Print_Card(43,96,LGREY); |
mtaylor33 | 0:d77e1909cdc7 | 146 | Print_Card(70,96,LGREY); |
mtaylor33 | 0:d77e1909cdc7 | 147 | Print_Card(97,96,LGREY); |
mtaylor33 | 0:d77e1909cdc7 | 148 | |
mtaylor33 | 0:d77e1909cdc7 | 149 | } |
mtaylor33 | 0:d77e1909cdc7 | 150 | |
mtaylor33 | 0:d77e1909cdc7 | 151 | void Update_Score(){ |
mtaylor33 | 0:d77e1909cdc7 | 152 | uLCD.color(PURPLE); |
mtaylor33 | 0:d77e1909cdc7 | 153 | uLCD.locate(1,0); |
mtaylor33 | 0:d77e1909cdc7 | 154 | uLCD.printf("Turns = %d ", Score1); |
mtaylor33 | 0:d77e1909cdc7 | 155 | uLCD.color(ORANGE); |
mtaylor33 | 0:d77e1909cdc7 | 156 | uLCD.locate(1,1); |
mtaylor33 | 0:d77e1909cdc7 | 157 | uLCD.printf("Matchs = %d ", Score2); |
mtaylor33 | 0:d77e1909cdc7 | 158 | // uLCD.color(GREEN); |
mtaylor33 | 0:d77e1909cdc7 | 159 | // uLCD.locate(1,4); |
mtaylor33 | 0:d77e1909cdc7 | 160 | // uLCD.printf("Key Code %d ", keypress); |
mtaylor33 | 0:d77e1909cdc7 | 161 | } |
mtaylor33 | 0:d77e1909cdc7 | 162 | |
mtaylor33 | 0:d77e1909cdc7 | 163 | volatile int count = 0; |
mtaylor33 | 0:d77e1909cdc7 | 164 | |
mtaylor33 | 0:d77e1909cdc7 | 165 | void Flush(){ |
mtaylor33 | 0:d77e1909cdc7 | 166 | for(int i = 0; i<12; i++){ |
mtaylor33 | 0:d77e1909cdc7 | 167 | Used[i] = 255; |
mtaylor33 | 0:d77e1909cdc7 | 168 | } |
mtaylor33 | 0:d77e1909cdc7 | 169 | srand(count); |
mtaylor33 | 0:d77e1909cdc7 | 170 | } |
mtaylor33 | 0:d77e1909cdc7 | 171 | |
mtaylor33 | 0:d77e1909cdc7 | 172 | Deck Deal(Deck deck){ |
mtaylor33 | 0:d77e1909cdc7 | 173 | int temp; |
mtaylor33 | 0:d77e1909cdc7 | 174 | int tempc; |
mtaylor33 | 0:d77e1909cdc7 | 175 | Flush(); |
mtaylor33 | 0:d77e1909cdc7 | 176 | tempc = rand(); |
mtaylor33 | 0:d77e1909cdc7 | 177 | //go = 1; |
mtaylor33 | 0:d77e1909cdc7 | 178 | for(int i = 0; i<12; i++){ |
mtaylor33 | 0:d77e1909cdc7 | 179 | srand(tempc*count); |
mtaylor33 | 0:d77e1909cdc7 | 180 | tempc = tempc + rand(); |
mtaylor33 | 0:d77e1909cdc7 | 181 | temp = rand()%12; |
mtaylor33 | 0:d77e1909cdc7 | 182 | for(int k = i; k>=0; k--){ |
mtaylor33 | 0:d77e1909cdc7 | 183 | if(temp == Used[k]){ |
mtaylor33 | 0:d77e1909cdc7 | 184 | temp = rand()%12; |
mtaylor33 | 0:d77e1909cdc7 | 185 | k = i; |
mtaylor33 | 0:d77e1909cdc7 | 186 | } |
mtaylor33 | 0:d77e1909cdc7 | 187 | } |
mtaylor33 | 0:d77e1909cdc7 | 188 | Used[i] = temp; |
mtaylor33 | 0:d77e1909cdc7 | 189 | } |
mtaylor33 | 0:d77e1909cdc7 | 190 | for(int c = 0; c<12; c++){ |
mtaylor33 | 0:d77e1909cdc7 | 191 | deck.Cards[c].Color = ColorAssigner(Used[c]+1); |
mtaylor33 | 0:d77e1909cdc7 | 192 | // uLCD.color(RED); |
mtaylor33 | 0:d77e1909cdc7 | 193 | // uLCD.locate(2,c+2); |
mtaylor33 | 0:d77e1909cdc7 | 194 | // uLCD.printf( "%d",Used[c]+1 ); |
mtaylor33 | 0:d77e1909cdc7 | 195 | // uLCD.color(BLUE); |
mtaylor33 | 0:d77e1909cdc7 | 196 | //uLCD.locate(5,c+2); |
mtaylor33 | 0:d77e1909cdc7 | 197 | //uLCD.printf( "%d",((Used[c]+1)%6)+1 ); |
mtaylor33 | 0:d77e1909cdc7 | 198 | |
mtaylor33 | 0:d77e1909cdc7 | 199 | |
mtaylor33 | 0:d77e1909cdc7 | 200 | |
mtaylor33 | 0:d77e1909cdc7 | 201 | } |
mtaylor33 | 0:d77e1909cdc7 | 202 | deck.Cards[0].x = 16; |
mtaylor33 | 0:d77e1909cdc7 | 203 | deck.Cards[0].y = 32; |
mtaylor33 | 0:d77e1909cdc7 | 204 | deck.Cards[0].Matched = 0; |
mtaylor33 | 0:d77e1909cdc7 | 205 | deck.Cards[1].x = 43; |
mtaylor33 | 0:d77e1909cdc7 | 206 | deck.Cards[1].y = 32; |
mtaylor33 | 0:d77e1909cdc7 | 207 | deck.Cards[1].Matched = 0; |
mtaylor33 | 0:d77e1909cdc7 | 208 | deck.Cards[2].x = 70; |
mtaylor33 | 0:d77e1909cdc7 | 209 | deck.Cards[2].y = 32; |
mtaylor33 | 0:d77e1909cdc7 | 210 | deck.Cards[2].Matched = 0; |
mtaylor33 | 0:d77e1909cdc7 | 211 | deck.Cards[3].x = 97; |
mtaylor33 | 0:d77e1909cdc7 | 212 | deck.Cards[3].y = 32; |
mtaylor33 | 0:d77e1909cdc7 | 213 | deck.Cards[3].Matched = 0; |
mtaylor33 | 0:d77e1909cdc7 | 214 | deck.Cards[4].x = 16; |
mtaylor33 | 0:d77e1909cdc7 | 215 | deck.Cards[4].y = 64; |
mtaylor33 | 0:d77e1909cdc7 | 216 | deck.Cards[4].Matched = 0; |
mtaylor33 | 0:d77e1909cdc7 | 217 | deck.Cards[5].x = 43; |
mtaylor33 | 0:d77e1909cdc7 | 218 | deck.Cards[5].y = 64; |
mtaylor33 | 0:d77e1909cdc7 | 219 | deck.Cards[5].Matched = 0; |
mtaylor33 | 0:d77e1909cdc7 | 220 | deck.Cards[6].x = 70; |
mtaylor33 | 0:d77e1909cdc7 | 221 | deck.Cards[6].y = 64; |
mtaylor33 | 0:d77e1909cdc7 | 222 | deck.Cards[6].Matched = 0; |
mtaylor33 | 0:d77e1909cdc7 | 223 | deck.Cards[7].x = 97; |
mtaylor33 | 0:d77e1909cdc7 | 224 | deck.Cards[7].y = 64; |
mtaylor33 | 0:d77e1909cdc7 | 225 | deck.Cards[7].Matched = 0; |
mtaylor33 | 0:d77e1909cdc7 | 226 | deck.Cards[8].x = 16; |
mtaylor33 | 0:d77e1909cdc7 | 227 | deck.Cards[8].y = 96; |
mtaylor33 | 0:d77e1909cdc7 | 228 | deck.Cards[8].Matched = 0; |
mtaylor33 | 0:d77e1909cdc7 | 229 | deck.Cards[9].x = 43; |
mtaylor33 | 0:d77e1909cdc7 | 230 | deck.Cards[9].y = 96; |
mtaylor33 | 0:d77e1909cdc7 | 231 | deck.Cards[9].Matched = 0; |
mtaylor33 | 0:d77e1909cdc7 | 232 | deck.Cards[10].x = 70; |
mtaylor33 | 0:d77e1909cdc7 | 233 | deck.Cards[10].y = 96; |
mtaylor33 | 0:d77e1909cdc7 | 234 | deck.Cards[10].Matched = 0; |
mtaylor33 | 0:d77e1909cdc7 | 235 | deck.Cards[11].x = 97; |
mtaylor33 | 0:d77e1909cdc7 | 236 | deck.Cards[11].y = 96; |
mtaylor33 | 0:d77e1909cdc7 | 237 | deck.Cards[11].Matched = 0; |
mtaylor33 | 0:d77e1909cdc7 | 238 | return deck; |
mtaylor33 | 0:d77e1909cdc7 | 239 | } |
mtaylor33 | 0:d77e1909cdc7 | 240 | |
mtaylor33 | 0:d77e1909cdc7 | 241 | |
mtaylor33 | 0:d77e1909cdc7 | 242 | //Deck New_deck; |
mtaylor33 | 0:d77e1909cdc7 | 243 | |
mtaylor33 | 0:d77e1909cdc7 | 244 | |
mtaylor33 | 0:d77e1909cdc7 | 245 | int main() { |
mtaylor33 | 0:d77e1909cdc7 | 246 | |
mtaylor33 | 0:d77e1909cdc7 | 247 | interrupt.fall(&fallInterrupt); |
mtaylor33 | 0:d77e1909cdc7 | 248 | interrupt.mode(PullUp); |
mtaylor33 | 0:d77e1909cdc7 | 249 | uLCD.baudrate(3000000); |
mtaylor33 | 0:d77e1909cdc7 | 250 | |
mtaylor33 | 0:d77e1909cdc7 | 251 | |
mtaylor33 | 0:d77e1909cdc7 | 252 | int Turn = 0; |
mtaylor33 | 0:d77e1909cdc7 | 253 | int Reset = 0; |
mtaylor33 | 0:d77e1909cdc7 | 254 | Deck deck; |
mtaylor33 | 0:d77e1909cdc7 | 255 | int showing = 0; |
mtaylor33 | 0:d77e1909cdc7 | 256 | int show1 = 0; |
mtaylor33 | 0:d77e1909cdc7 | 257 | int show2 = 0; |
mtaylor33 | 0:d77e1909cdc7 | 258 | int tempress = 0; |
mtaylor33 | 0:d77e1909cdc7 | 259 | while(1) { |
mtaylor33 | 0:d77e1909cdc7 | 260 | |
mtaylor33 | 0:d77e1909cdc7 | 261 | if(Turn == 0 | Reset == 1){ |
mtaylor33 | 0:d77e1909cdc7 | 262 | |
mtaylor33 | 0:d77e1909cdc7 | 263 | Setup(); |
mtaylor33 | 0:d77e1909cdc7 | 264 | Turn =0; |
mtaylor33 | 0:d77e1909cdc7 | 265 | } |
mtaylor33 | 0:d77e1909cdc7 | 266 | if(Turn == 0){ |
mtaylor33 | 0:d77e1909cdc7 | 267 | |
mtaylor33 | 0:d77e1909cdc7 | 268 | deck = Deal(deck); |
mtaylor33 | 0:d77e1909cdc7 | 269 | Turn++; |
mtaylor33 | 0:d77e1909cdc7 | 270 | } |
mtaylor33 | 0:d77e1909cdc7 | 271 | |
mtaylor33 | 0:d77e1909cdc7 | 272 | if (Score2 == 6 and keypress != 0) {count=count+Turn; Turn = 0; Score2 = 0;} |
mtaylor33 | 0:d77e1909cdc7 | 273 | if (Score2 <6){ |
mtaylor33 | 0:d77e1909cdc7 | 274 | Score1 = Turn; |
mtaylor33 | 0:d77e1909cdc7 | 275 | Update_Score(); |
mtaylor33 | 0:d77e1909cdc7 | 276 | // if(Turn == 5){ |
mtaylor33 | 0:d77e1909cdc7 | 277 | // for(int i = 0; i < 12; i++){ |
mtaylor33 | 0:d77e1909cdc7 | 278 | // if(deck.Cards[0].Matched == 0){ |
mtaylor33 | 0:d77e1909cdc7 | 279 | // Print_Card(deck.Cards[i].x,deck.Cards[i].y,deck.Cards[i].Color); |
mtaylor33 | 0:d77e1909cdc7 | 280 | |
mtaylor33 | 0:d77e1909cdc7 | 281 | // } |
mtaylor33 | 0:d77e1909cdc7 | 282 | // }wait(3);} |
mtaylor33 | 0:d77e1909cdc7 | 283 | |
mtaylor33 | 0:d77e1909cdc7 | 284 | // uLCD.color(PURPLE); |
mtaylor33 | 0:d77e1909cdc7 | 285 | // uLCD.locate(1,14); |
mtaylor33 | 0:d77e1909cdc7 | 286 | //uLCD.printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", Used[0],Used[1],Used[2],Used[3],Used[4],Used[5],Used[6],Used[7],Used[8],Used[9],Used[10],Used[11]); |
mtaylor33 | 0:d77e1909cdc7 | 287 | //while(1); |
mtaylor33 | 0:d77e1909cdc7 | 288 | //Score2 = Turn/3; |
mtaylor33 | 0:d77e1909cdc7 | 289 | |
mtaylor33 | 0:d77e1909cdc7 | 290 | /* uLCD.color(GREEN); |
mtaylor33 | 0:d77e1909cdc7 | 291 | uLCD.locate(1,7); |
mtaylor33 | 0:d77e1909cdc7 | 292 | uLCD.printf( "%d", showing); |
mtaylor33 | 0:d77e1909cdc7 | 293 | // wait(.5); |
mtaylor33 | 0:d77e1909cdc7 | 294 | uLCD.locate(1,8); |
mtaylor33 | 0:d77e1909cdc7 | 295 | uLCD.printf( "%d", show1); |
mtaylor33 | 0:d77e1909cdc7 | 296 | // wait(.5); |
mtaylor33 | 0:d77e1909cdc7 | 297 | uLCD.locate(1,9); |
mtaylor33 | 0:d77e1909cdc7 | 298 | uLCD.printf( "%d", show2); |
mtaylor33 | 0:d77e1909cdc7 | 299 | // wait(.5); */ |
mtaylor33 | 0:d77e1909cdc7 | 300 | /* uLCD.color(GREEN); |
mtaylor33 | 0:d77e1909cdc7 | 301 | uLCD.locate(1,11); |
mtaylor33 | 0:d77e1909cdc7 | 302 | uLCD.printf( "show 1 %d",show1 ); |
mtaylor33 | 0:d77e1909cdc7 | 303 | uLCD.locate(1,12); |
mtaylor33 | 0:d77e1909cdc7 | 304 | uLCD.printf( "show 2 %d",show2 ); |
mtaylor33 | 0:d77e1909cdc7 | 305 | uLCD.locate(1,13); |
mtaylor33 | 0:d77e1909cdc7 | 306 | uLCD.printf( "showing %d",showing ); |
mtaylor33 | 0:d77e1909cdc7 | 307 | uLCD.locate(1,10); |
mtaylor33 | 0:d77e1909cdc7 | 308 | uLCD.printf( "Key %d",keypress ); |
mtaylor33 | 0:d77e1909cdc7 | 309 | uLCD.locate(1,9); |
mtaylor33 | 0:d77e1909cdc7 | 310 | uLCD.printf( "Last Key %d",tempress ); |
mtaylor33 | 0:d77e1909cdc7 | 311 | */ |
mtaylor33 | 0:d77e1909cdc7 | 312 | |
mtaylor33 | 0:d77e1909cdc7 | 313 | |
mtaylor33 | 0:d77e1909cdc7 | 314 | |
mtaylor33 | 0:d77e1909cdc7 | 315 | if(showing < 2 and tempress != keypress){ |
mtaylor33 | 0:d77e1909cdc7 | 316 | if(keypress !=0 ){ |
mtaylor33 | 0:d77e1909cdc7 | 317 | if(deck.Cards[keypress-1].Matched == 0){ |
mtaylor33 | 0:d77e1909cdc7 | 318 | if (show1 != keypress){ |
mtaylor33 | 0:d77e1909cdc7 | 319 | Print_Card(deck.Cards[keypress-1].x,deck.Cards[keypress-1].y,deck.Cards[keypress-1].Color); |
mtaylor33 | 0:d77e1909cdc7 | 320 | showing++; |
mtaylor33 | 0:d77e1909cdc7 | 321 | if(show1 != 0 ) show2 = keypress; |
mtaylor33 | 0:d77e1909cdc7 | 322 | if(show1 == 0 )show1 = keypress; |
mtaylor33 | 0:d77e1909cdc7 | 323 | Update_Score(); |
mtaylor33 | 0:d77e1909cdc7 | 324 | } |
mtaylor33 | 0:d77e1909cdc7 | 325 | } |
mtaylor33 | 0:d77e1909cdc7 | 326 | } |
mtaylor33 | 0:d77e1909cdc7 | 327 | } |
mtaylor33 | 0:d77e1909cdc7 | 328 | |
mtaylor33 | 0:d77e1909cdc7 | 329 | |
mtaylor33 | 0:d77e1909cdc7 | 330 | |
mtaylor33 | 0:d77e1909cdc7 | 331 | // Update_Score(); |
mtaylor33 | 0:d77e1909cdc7 | 332 | if(showing == 2){ |
mtaylor33 | 0:d77e1909cdc7 | 333 | wait(.3); |
mtaylor33 | 0:d77e1909cdc7 | 334 | if(deck.Cards[show1-1].Color == deck.Cards[show2-1].Color){ |
mtaylor33 | 0:d77e1909cdc7 | 335 | deck.Cards[show1-1].Matched = 1; |
mtaylor33 | 0:d77e1909cdc7 | 336 | deck.Cards[show2-1].Matched = 1; |
mtaylor33 | 0:d77e1909cdc7 | 337 | Print_Card(deck.Cards[show1-1].x,deck.Cards[show1-1].y,DGREY); |
mtaylor33 | 0:d77e1909cdc7 | 338 | wait(.1); |
mtaylor33 | 0:d77e1909cdc7 | 339 | Print_Card(deck.Cards[show2-1].x,deck.Cards[show2-1].y,DGREY); |
mtaylor33 | 0:d77e1909cdc7 | 340 | Score2++; |
mtaylor33 | 0:d77e1909cdc7 | 341 | }else{ |
mtaylor33 | 0:d77e1909cdc7 | 342 | Print_Card(deck.Cards[show1-1].x,deck.Cards[show1-1].y,LGREY); |
mtaylor33 | 0:d77e1909cdc7 | 343 | wait(.1); |
mtaylor33 | 0:d77e1909cdc7 | 344 | Print_Card(deck.Cards[show2-1].x,deck.Cards[show2-1].y,LGREY); |
mtaylor33 | 0:d77e1909cdc7 | 345 | } |
mtaylor33 | 0:d77e1909cdc7 | 346 | show1 = 0; |
mtaylor33 | 0:d77e1909cdc7 | 347 | show2 = 0; |
mtaylor33 | 0:d77e1909cdc7 | 348 | showing = 0; |
mtaylor33 | 0:d77e1909cdc7 | 349 | Turn++; |
mtaylor33 | 0:d77e1909cdc7 | 350 | Update_Score(); |
mtaylor33 | 0:d77e1909cdc7 | 351 | wait(.3); |
mtaylor33 | 0:d77e1909cdc7 | 352 | } |
mtaylor33 | 0:d77e1909cdc7 | 353 | |
mtaylor33 | 0:d77e1909cdc7 | 354 | //if(Turn== 25)Turn=0; |
mtaylor33 | 0:d77e1909cdc7 | 355 | //uLCD.filled_rectangle(4,4,19,24,DGREY); |
mtaylor33 | 0:d77e1909cdc7 | 356 | tempress=keypress; |
mtaylor33 | 0:d77e1909cdc7 | 357 | count++; |
mtaylor33 | 0:d77e1909cdc7 | 358 | }else Shuffle(rand()%3); |
mtaylor33 | 0:d77e1909cdc7 | 359 | } |
mtaylor33 | 0:d77e1909cdc7 | 360 | } |