final project

Dependencies:   4DGL-uLCD-SE PinDetect SDFileSystem mbed

Committer:
bkf34
Date:
Wed Apr 22 03:19:32 2015 +0000
Revision:
1:fa18b47052d2
Parent:
0:73f971fb7401
final

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bkf34 0:73f971fb7401 1
bkf34 0:73f971fb7401 2 #include "mbed.h"
bkf34 0:73f971fb7401 3 #include "PinDetect.h"
bkf34 0:73f971fb7401 4 #include "uLCD_4DGL.h"
bkf34 0:73f971fb7401 5 #include <string>
bkf34 0:73f971fb7401 6 #include "SDFileSystem.h"
bkf34 0:73f971fb7401 7
bkf34 0:73f971fb7401 8 SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
bkf34 0:73f971fb7401 9 uLCD_4DGL lcd(p28, p27, p30);
bkf34 0:73f971fb7401 10 DigitalOut myled(LED1);
bkf34 0:73f971fb7401 11 PinDetect pb1(p9);
bkf34 0:73f971fb7401 12 PinDetect pb2(p10);
bkf34 0:73f971fb7401 13 PinDetect pb3(p11);
bkf34 0:73f971fb7401 14 PinDetect pb4(p12);
bkf34 0:73f971fb7401 15
bkf34 0:73f971fb7401 16 int randseed = 0; // seed for random number generator
bkf34 0:73f971fb7401 17
bkf34 0:73f971fb7401 18 int bet = 0;// initial bet
bkf34 0:73f971fb7401 19 int dollars = 100; // money your wife let you take to the casino
bkf34 0:73f971fb7401 20
bkf34 0:73f971fb7401 21 string playerblackjackstring = "";
bkf34 0:73f971fb7401 22 string dealerblackjackstring = "";
bkf34 0:73f971fb7401 23 int playercardnumbers[26] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // initial player hand matrix
bkf34 0:73f971fb7401 24 int dealercardnumbers[26]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // inital dealer hand matrix
bkf34 0:73f971fb7401 25 string playercardstring[26] = {"","","","","","","","","","","","","","","","","","","","","","","","","",""}; // string array for printing letters/numbers on cards
bkf34 0:73f971fb7401 26 string dealercardstring[26] = {"","","","","","","","","","","","","","","","","","","","","","","","","",""}; // see above
bkf34 0:73f971fb7401 27 int playerindex = 0;
bkf34 0:73f971fb7401 28 int dealerindex = 0;
bkf34 0:73f971fb7401 29
bkf34 0:73f971fb7401 30 string winloss = "";
bkf34 0:73f971fb7401 31 int holdvalue =0;
bkf34 0:73f971fb7401 32 int numberofaces = 0;// for calculating whether ace is 1 or 11
bkf34 0:73f971fb7401 33 int cardindex;// These lines are for
bkf34 0:73f971fb7401 34 string cardstring = "";// the drawcard
bkf34 0:73f971fb7401 35 int cardnumber;// function
bkf34 0:73f971fb7401 36 int playersum = 0; // for testing player conditions
bkf34 0:73f971fb7401 37 int dealersum = 0; // for testing dealer conditions
bkf34 0:73f971fb7401 38
bkf34 0:73f971fb7401 39 string playagainstring = "yes";
bkf34 0:73f971fb7401 40 string choice = ""; // this is for the hit or stand function
bkf34 0:73f971fb7401 41
bkf34 0:73f971fb7401 42 void printdealercards(int a)
bkf34 0:73f971fb7401 43 {
bkf34 0:73f971fb7401 44 for (int i = 0; i < a +1; i++)
bkf34 0:73f971fb7401 45 printf(" %d ", dealercardnumbers[i]);
bkf34 0:73f971fb7401 46 }
bkf34 0:73f971fb7401 47 void createtable()
bkf34 0:73f971fb7401 48 {
bkf34 0:73f971fb7401 49 lcd.background_color(BLACKJACKRED);
bkf34 0:73f971fb7401 50 lcd.cls();
bkf34 0:73f971fb7401 51 lcd.color(WHITE);
bkf34 0:73f971fb7401 52 lcd.textbackground_color(BLACKJACKRED);
bkf34 0:73f971fb7401 53 lcd.circle(62,60,11,WHITE);
bkf34 0:73f971fb7401 54 lcd.locate(0,14);
bkf34 0:73f971fb7401 55 lcd.printf("%d", dollars);
bkf34 0:73f971fb7401 56 }
bkf34 0:73f971fb7401 57 void betprint(int x)
bkf34 0:73f971fb7401 58 {
bkf34 0:73f971fb7401 59 lcd.locate(8,7);
bkf34 0:73f971fb7401 60 lcd.set_font_size(.5,.5);
bkf34 0:73f971fb7401 61 lcd.printf("%d",x);
bkf34 0:73f971fb7401 62 }
bkf34 0:73f971fb7401 63 void createdealercards()
bkf34 0:73f971fb7401 64 {
bkf34 0:73f971fb7401 65 lcd.filled_rectangle(25,0,55,36,RED);
bkf34 0:73f971fb7401 66 lcd.filled_rectangle(40,0,70,36,WHITE);
bkf34 0:73f971fb7401 67
bkf34 0:73f971fb7401 68 }
bkf34 0:73f971fb7401 69 void createplayercards()
bkf34 0:73f971fb7401 70 {
bkf34 0:73f971fb7401 71 lcd.filled_rectangle(25,125,60,84,WHITE);
bkf34 0:73f971fb7401 72 lcd.filled_rectangle(50,125,70,84,WHITE);
bkf34 0:73f971fb7401 73 lcd.line(40,125,40,84,BLACK);
bkf34 0:73f971fb7401 74 }
bkf34 0:73f971fb7401 75 void additionalplayercards(int a)
bkf34 0:73f971fb7401 76 {
bkf34 0:73f971fb7401 77 switch(a) {
bkf34 0:73f971fb7401 78 case 2:
bkf34 0:73f971fb7401 79 lcd.filled_rectangle(60,125,80,84,WHITE);
bkf34 0:73f971fb7401 80 lcd.line(52,125,52,84,BLACK);
bkf34 0:73f971fb7401 81 break;
bkf34 0:73f971fb7401 82 case 3:
bkf34 0:73f971fb7401 83 lcd.filled_rectangle(75,125,95,84,WHITE);
bkf34 0:73f971fb7401 84 lcd.line(65,125,65,84,BLACK);
bkf34 0:73f971fb7401 85 break;
bkf34 0:73f971fb7401 86 case 4:
bkf34 0:73f971fb7401 87 lcd.filled_rectangle(90,125,110,84,WHITE);
bkf34 0:73f971fb7401 88 lcd.line(80,125,80,84,BLACK);
bkf34 0:73f971fb7401 89 break;
bkf34 0:73f971fb7401 90
bkf34 0:73f971fb7401 91 }
bkf34 0:73f971fb7401 92 }
bkf34 0:73f971fb7401 93 void printflippedcard()
bkf34 0:73f971fb7401 94 {
bkf34 0:73f971fb7401 95 lcd.filled_rectangle(25,0,55,36,WHITE);
bkf34 0:73f971fb7401 96 lcd.filled_rectangle(40,0,70,36,WHITE);
bkf34 0:73f971fb7401 97 lcd.line(40,0,40,36,BLACK);
bkf34 0:73f971fb7401 98 lcd.locate(4,0);
bkf34 0:73f971fb7401 99 lcd.printf("%s",dealercardstring[0]);
bkf34 0:73f971fb7401 100 lcd.locate(6,0);
bkf34 0:73f971fb7401 101 lcd.printf("%s",dealercardstring[1]);
bkf34 0:73f971fb7401 102
bkf34 0:73f971fb7401 103 }
bkf34 0:73f971fb7401 104 void additionaldealercard(int a)
bkf34 0:73f971fb7401 105 {
bkf34 0:73f971fb7401 106 switch(a) {
bkf34 0:73f971fb7401 107 case 2:
bkf34 0:73f971fb7401 108 lcd.filled_rectangle(60,0,85,36,WHITE);
bkf34 0:73f971fb7401 109 lcd.line(55,0,55,36,BLACK);
bkf34 0:73f971fb7401 110 break;
bkf34 0:73f971fb7401 111
bkf34 0:73f971fb7401 112 case 3:
bkf34 0:73f971fb7401 113 lcd.filled_rectangle(75,0,95,36,WHITE);
bkf34 0:73f971fb7401 114 lcd.line(65,125,65,84,BLACK);
bkf34 0:73f971fb7401 115 break;
bkf34 0:73f971fb7401 116 case 4:
bkf34 0:73f971fb7401 117 lcd.filled_rectangle(90,0,110,36,WHITE);
bkf34 0:73f971fb7401 118 lcd.line(80,125,80,84,BLACK);
bkf34 0:73f971fb7401 119 break;
bkf34 0:73f971fb7401 120
bkf34 0:73f971fb7401 121 }
bkf34 0:73f971fb7401 122 }
bkf34 0:73f971fb7401 123 void betfunction()
bkf34 0:73f971fb7401 124 {
bkf34 0:73f971fb7401 125 while(pb1 && pb2) {}
bkf34 0:73f971fb7401 126 if(!pb1) {
bkf34 0:73f971fb7401 127 bet = 10;
bkf34 0:73f971fb7401 128 //printf("%d\n",bet);
bkf34 0:73f971fb7401 129 }
bkf34 0:73f971fb7401 130 if(!pb2) {
bkf34 0:73f971fb7401 131 bet = 50;
bkf34 0:73f971fb7401 132 //printf("%d\n",bet);
bkf34 0:73f971fb7401 133 }
bkf34 0:73f971fb7401 134 }
bkf34 0:73f971fb7401 135 void drawcard()
bkf34 0:73f971fb7401 136 {
bkf34 0:73f971fb7401 137 cardindex = 1 + rand()%13;
bkf34 0:73f971fb7401 138
bkf34 0:73f971fb7401 139 switch(cardindex) {
bkf34 0:73f971fb7401 140 case 1:
bkf34 0:73f971fb7401 141 cardstring = "2";
bkf34 0:73f971fb7401 142 cardnumber = 2;
bkf34 0:73f971fb7401 143 break;
bkf34 0:73f971fb7401 144 case 2:
bkf34 0:73f971fb7401 145 cardstring = "3";
bkf34 0:73f971fb7401 146 cardnumber = 3;
bkf34 0:73f971fb7401 147 break;
bkf34 0:73f971fb7401 148 case 3:
bkf34 0:73f971fb7401 149 cardstring = "4";
bkf34 0:73f971fb7401 150 cardnumber = 4;
bkf34 0:73f971fb7401 151 break;
bkf34 0:73f971fb7401 152 case 4:
bkf34 0:73f971fb7401 153 cardstring = "5";
bkf34 0:73f971fb7401 154 cardnumber = 5;
bkf34 0:73f971fb7401 155 break;
bkf34 0:73f971fb7401 156 case 5:
bkf34 0:73f971fb7401 157 cardstring = "6";
bkf34 0:73f971fb7401 158 cardnumber = 6;
bkf34 0:73f971fb7401 159 break;
bkf34 0:73f971fb7401 160 case 6:
bkf34 0:73f971fb7401 161 cardstring = "7";
bkf34 0:73f971fb7401 162 cardnumber = 7;
bkf34 0:73f971fb7401 163 break;
bkf34 0:73f971fb7401 164 case 7:
bkf34 0:73f971fb7401 165 cardstring = "8";
bkf34 0:73f971fb7401 166 cardnumber = 8;
bkf34 0:73f971fb7401 167 break;
bkf34 0:73f971fb7401 168 case 8:
bkf34 0:73f971fb7401 169 cardstring = "9";
bkf34 0:73f971fb7401 170 cardnumber = 9;
bkf34 0:73f971fb7401 171 break;
bkf34 0:73f971fb7401 172 case 9:
bkf34 0:73f971fb7401 173 cardstring = "10";
bkf34 0:73f971fb7401 174 cardnumber = 10;
bkf34 0:73f971fb7401 175 break;
bkf34 0:73f971fb7401 176 case 10:
bkf34 0:73f971fb7401 177 cardstring = "J";
bkf34 0:73f971fb7401 178 cardnumber = 10;
bkf34 0:73f971fb7401 179 break;
bkf34 0:73f971fb7401 180 case 11:
bkf34 0:73f971fb7401 181 cardstring = "Q";
bkf34 0:73f971fb7401 182 cardnumber = 10;
bkf34 0:73f971fb7401 183 break;
bkf34 0:73f971fb7401 184 case 12:
bkf34 0:73f971fb7401 185 cardstring = "K";
bkf34 0:73f971fb7401 186 cardnumber = 10;
bkf34 0:73f971fb7401 187 break;
bkf34 0:73f971fb7401 188 case 13:
bkf34 0:73f971fb7401 189 cardstring = "A";
bkf34 0:73f971fb7401 190 cardnumber = 11;
bkf34 0:73f971fb7401 191 numberofaces = numberofaces + 1;
bkf34 0:73f971fb7401 192 break;
bkf34 0:73f971fb7401 193 }
bkf34 0:73f971fb7401 194
bkf34 0:73f971fb7401 195
bkf34 0:73f971fb7401 196 }
bkf34 0:73f971fb7401 197 void hitorstand()
bkf34 0:73f971fb7401 198 {
bkf34 0:73f971fb7401 199 printf("Hit or Stand? \n");
bkf34 0:73f971fb7401 200 while(pb3 && pb4) {}
bkf34 0:73f971fb7401 201
bkf34 0:73f971fb7401 202 if(!pb3) {
bkf34 0:73f971fb7401 203 choice = "hit";
bkf34 0:73f971fb7401 204
bkf34 0:73f971fb7401 205
bkf34 0:73f971fb7401 206 }
bkf34 0:73f971fb7401 207 if(!pb4) {
bkf34 0:73f971fb7401 208 choice = "stand";
bkf34 0:73f971fb7401 209 }
bkf34 0:73f971fb7401 210 printf("Choice: %s",choice);
bkf34 0:73f971fb7401 211
bkf34 0:73f971fb7401 212
bkf34 0:73f971fb7401 213 }
bkf34 0:73f971fb7401 214 void initializegame()
bkf34 0:73f971fb7401 215 {
bkf34 0:73f971fb7401 216 drawcard();
bkf34 0:73f971fb7401 217 playerindex++;
bkf34 0:73f971fb7401 218 playercardnumbers[0] = cardnumber;
bkf34 0:73f971fb7401 219 playercardstring[0] = cardstring;
bkf34 0:73f971fb7401 220 drawcard();
bkf34 0:73f971fb7401 221 dealerindex++;
bkf34 0:73f971fb7401 222 dealercardnumbers[0] = cardnumber;
bkf34 0:73f971fb7401 223 dealercardstring[0] = cardstring;
bkf34 0:73f971fb7401 224 drawcard();
bkf34 0:73f971fb7401 225 playerindex++;
bkf34 0:73f971fb7401 226 playercardnumbers[1] = cardnumber;
bkf34 0:73f971fb7401 227 playercardstring[1] = cardstring;
bkf34 0:73f971fb7401 228 drawcard();
bkf34 0:73f971fb7401 229 dealerindex++;
bkf34 0:73f971fb7401 230 dealercardnumbers[1] = cardnumber;
bkf34 0:73f971fb7401 231 dealercardstring[1] = cardstring;
bkf34 0:73f971fb7401 232
bkf34 0:73f971fb7401 233
bkf34 0:73f971fb7401 234 }
bkf34 0:73f971fb7401 235 void playsum()
bkf34 0:73f971fb7401 236 {
bkf34 0:73f971fb7401 237 playersum = 0;
bkf34 0:73f971fb7401 238 for(int i = 0; i < 26; i++) {
bkf34 0:73f971fb7401 239
bkf34 0:73f971fb7401 240 playersum = playercardnumbers[i] + playersum;
bkf34 0:73f971fb7401 241 }
bkf34 0:73f971fb7401 242
bkf34 0:73f971fb7401 243 }
bkf34 0:73f971fb7401 244
bkf34 0:73f971fb7401 245 void dealsum()
bkf34 0:73f971fb7401 246 {
bkf34 0:73f971fb7401 247 dealersum = 0;
bkf34 0:73f971fb7401 248 for(int i = 0; i < 26; i++) {
bkf34 0:73f971fb7401 249
bkf34 0:73f971fb7401 250 dealersum = dealercardnumbers[i] + dealersum;
bkf34 0:73f971fb7401 251 }
bkf34 0:73f971fb7401 252
bkf34 0:73f971fb7401 253 }
bkf34 0:73f971fb7401 254
bkf34 0:73f971fb7401 255
bkf34 0:73f971fb7401 256 void printinitialcardvalues(string a, string b, string c)
bkf34 0:73f971fb7401 257 {
bkf34 0:73f971fb7401 258 lcd.color(BLACK);
bkf34 0:73f971fb7401 259 lcd.textbackground_color(WHITE);
bkf34 0:73f971fb7401 260 lcd.locate(4,11);
bkf34 0:73f971fb7401 261 lcd.printf("%s",a);
bkf34 0:73f971fb7401 262 lcd.locate(6,11);
bkf34 0:73f971fb7401 263 lcd.printf("%s",b);
bkf34 0:73f971fb7401 264 lcd.locate(6,0);
bkf34 0:73f971fb7401 265 lcd.printf("%s",c);
bkf34 0:73f971fb7401 266
bkf34 0:73f971fb7401 267
bkf34 0:73f971fb7401 268 }
bkf34 0:73f971fb7401 269 void printaddtionalplayervalues(string a, int b)
bkf34 0:73f971fb7401 270 {
bkf34 0:73f971fb7401 271 switch(b) {
bkf34 0:73f971fb7401 272 case 2:
bkf34 0:73f971fb7401 273 lcd.locate(8,11);
bkf34 0:73f971fb7401 274 lcd.printf("%s",a);
bkf34 0:73f971fb7401 275 break;
bkf34 0:73f971fb7401 276 case 3:
bkf34 0:73f971fb7401 277 lcd.locate(10,11);
bkf34 0:73f971fb7401 278 lcd.printf("%s",a);
bkf34 0:73f971fb7401 279 break;
bkf34 0:73f971fb7401 280 case 4:
bkf34 0:73f971fb7401 281 lcd.locate(12,11);
bkf34 0:73f971fb7401 282 lcd.printf("%s",a);
bkf34 0:73f971fb7401 283 break;
bkf34 0:73f971fb7401 284
bkf34 0:73f971fb7401 285 }
bkf34 0:73f971fb7401 286 }
bkf34 0:73f971fb7401 287 void printaddtionaldealervalues(string a, int b)
bkf34 0:73f971fb7401 288
bkf34 0:73f971fb7401 289 {
bkf34 0:73f971fb7401 290 switch(b) {
bkf34 0:73f971fb7401 291 case 2:
bkf34 0:73f971fb7401 292 lcd.locate(8,0);
bkf34 0:73f971fb7401 293 lcd.printf("%s",a);
bkf34 0:73f971fb7401 294 break;
bkf34 0:73f971fb7401 295 }
bkf34 0:73f971fb7401 296 }
bkf34 0:73f971fb7401 297 void playagain()
bkf34 0:73f971fb7401 298 {
bkf34 0:73f971fb7401 299 lcd.cls();
bkf34 0:73f971fb7401 300 lcd.locate(4,8);
bkf34 0:73f971fb7401 301 lcd.textbackground_color(BLACKJACKRED);
bkf34 0:73f971fb7401 302 lcd.color(WHITE);
bkf34 0:73f971fb7401 303 lcd.printf("Play Again?");
bkf34 0:73f971fb7401 304 while(pb3 && pb4)
bkf34 0:73f971fb7401 305 if(!pb3) {
bkf34 0:73f971fb7401 306 playagainstring = "yes";
bkf34 0:73f971fb7401 307 printf("%s",playagainstring);
bkf34 0:73f971fb7401 308 }
bkf34 0:73f971fb7401 309 if(!pb4) {
bkf34 0:73f971fb7401 310 playagainstring ="no";
bkf34 0:73f971fb7401 311 printf("%s",playagainstring);
bkf34 0:73f971fb7401 312 }
bkf34 0:73f971fb7401 313 }
bkf34 0:73f971fb7401 314 void resetplayerarray()
bkf34 0:73f971fb7401 315 {
bkf34 0:73f971fb7401 316 for(int i = 0; i <26; i++) {
bkf34 0:73f971fb7401 317 playercardnumbers[i] =0;
bkf34 0:73f971fb7401 318 playercardstring[i]= "";
bkf34 0:73f971fb7401 319 }
bkf34 0:73f971fb7401 320 }
bkf34 0:73f971fb7401 321 void resetdealerarray()
bkf34 0:73f971fb7401 322 {
bkf34 0:73f971fb7401 323 for(int i = 0; i <26; i++) {
bkf34 0:73f971fb7401 324 dealercardnumbers[i] =0;
bkf34 0:73f971fb7401 325 dealercardstring[i]= "";
bkf34 0:73f971fb7401 326 }
bkf34 0:73f971fb7401 327 }
bkf34 0:73f971fb7401 328
bkf34 0:73f971fb7401 329 int main()
bkf34 0:73f971fb7401 330 {
bkf34 0:73f971fb7401 331
bkf34 0:73f971fb7401 332 // setup pushbutton functionality
bkf34 0:73f971fb7401 333 pb1.mode(PullUp);
bkf34 0:73f971fb7401 334 pb2.mode(PullUp);
bkf34 0:73f971fb7401 335 pb3.mode(PullUp);
bkf34 0:73f971fb7401 336 pb4.mode(PullUp);
bkf34 0:73f971fb7401 337 wait(.1);
bkf34 0:73f971fb7401 338 mkdir("/sd/mydir", 0777);
bkf34 0:73f971fb7401 339 while(playagainstring == "yes") {
bkf34 0:73f971fb7401 340 playersum = 0;
bkf34 0:73f971fb7401 341 playerindex= 0;
bkf34 0:73f971fb7401 342 dealersum = 0;
bkf34 0:73f971fb7401 343 dealerindex = 0;
bkf34 0:73f971fb7401 344 playerblackjackstring = "";
bkf34 0:73f971fb7401 345 dealerblackjackstring = "";
bkf34 0:73f971fb7401 346 winloss = "";
bkf34 0:73f971fb7401 347 holdvalue = 0;
bkf34 0:73f971fb7401 348 resetplayerarray();
bkf34 0:73f971fb7401 349 resetdealerarray();
bkf34 0:73f971fb7401 350 srand(randseed);
bkf34 0:73f971fb7401 351 // wait for pushbutton initialization
bkf34 0:73f971fb7401 352 createtable(); // this function draws the table maroon background with player betting circle
bkf34 0:73f971fb7401 353 betfunction();
bkf34 0:73f971fb7401 354 betprint(bet);
bkf34 0:73f971fb7401 355 createdealercards();//
bkf34 0:73f971fb7401 356 createplayercards();
bkf34 0:73f971fb7401 357 initializegame();
bkf34 0:73f971fb7401 358 printinitialcardvalues(playercardstring[0],playercardstring[1],dealercardstring[1]);
bkf34 0:73f971fb7401 359 dealsum();
bkf34 0:73f971fb7401 360 playsum();
bkf34 0:73f971fb7401 361 if(playersum == 21 && dealersum != 21) {
bkf34 0:73f971fb7401 362 wait(2);
bkf34 0:73f971fb7401 363 dollars = dollars + (1.5*bet);
bkf34 0:73f971fb7401 364 winloss = "win";
bkf34 0:73f971fb7401 365 lcd.cls();
bkf34 0:73f971fb7401 366 lcd.locate(2,8);
bkf34 0:73f971fb7401 367 lcd.textbackground_color(BLACKJACKRED);
bkf34 0:73f971fb7401 368 lcd.color(WHITE);
bkf34 0:73f971fb7401 369 lcd.printf("PLAYER BLACKJACK");
bkf34 0:73f971fb7401 370 playerblackjackstring = "blackjack";
bkf34 0:73f971fb7401 371 } else if(dealersum == 21 && playersum != 21) {
bkf34 0:73f971fb7401 372 wait(2);
bkf34 0:73f971fb7401 373 dollars = dollars - bet;
bkf34 0:73f971fb7401 374 winloss = "loss";
bkf34 0:73f971fb7401 375 lcd.cls();
bkf34 0:73f971fb7401 376 lcd.locate(2,8);
bkf34 0:73f971fb7401 377 lcd.textbackground_color(BLACKJACKRED);
bkf34 0:73f971fb7401 378 lcd.color(WHITE);
bkf34 0:73f971fb7401 379 lcd.printf("DEALER BLACKJACK");
bkf34 0:73f971fb7401 380 dealerblackjackstring = "blackjack";
bkf34 0:73f971fb7401 381 } else if ( playersum != 21 && dealersum != 21) {
bkf34 0:73f971fb7401 382 hitorstand();
bkf34 0:73f971fb7401 383 while(choice == "hit") {
bkf34 0:73f971fb7401 384 wait(1);
bkf34 0:73f971fb7401 385 drawcard();
bkf34 0:73f971fb7401 386 playercardnumbers[playerindex] = cardnumber;
bkf34 0:73f971fb7401 387 playercardstring[playerindex] = cardstring;
bkf34 0:73f971fb7401 388 additionalplayercards(playerindex);
bkf34 0:73f971fb7401 389 printaddtionalplayervalues(playercardstring[playerindex],playerindex);
bkf34 0:73f971fb7401 390 playerindex++;
bkf34 0:73f971fb7401 391 printf("Player Index : %d", playerindex);
bkf34 0:73f971fb7401 392 wait(1);
bkf34 0:73f971fb7401 393 playsum();
bkf34 0:73f971fb7401 394
bkf34 0:73f971fb7401 395 if(playersum > 21 && numberofaces == 0) {
bkf34 0:73f971fb7401 396 wait(2);
bkf34 0:73f971fb7401 397 dollars = dollars - bet;
bkf34 0:73f971fb7401 398 lcd.cls();
bkf34 0:73f971fb7401 399 lcd.locate(4,8);
bkf34 0:73f971fb7401 400 lcd.textbackground_color(BLACKJACKRED);
bkf34 0:73f971fb7401 401 lcd.color(WHITE);
bkf34 0:73f971fb7401 402 lcd.printf("BUST");
bkf34 0:73f971fb7401 403 winloss = "loss";
bkf34 0:73f971fb7401 404 break;
bkf34 0:73f971fb7401 405 }
bkf34 0:73f971fb7401 406 else if(playersum == 21 && numberofaces >= 1){
bkf34 0:73f971fb7401 407 numberofaces = numberofaces - 1;
bkf34 0:73f971fb7401 408 playersum = playersum - 10;
bkf34 0:73f971fb7401 409 }
bkf34 0:73f971fb7401 410 else if(playersum < 21) {
bkf34 0:73f971fb7401 411 hitorstand();
bkf34 0:73f971fb7401 412 if(choice == "stand") {
bkf34 0:73f971fb7401 413 break;
bkf34 0:73f971fb7401 414 }
bkf34 0:73f971fb7401 415 }
bkf34 0:73f971fb7401 416 }
bkf34 0:73f971fb7401 417 if(choice == "stand") {
bkf34 0:73f971fb7401 418 holdvalue = playersum;
bkf34 0:73f971fb7401 419 printflippedcard();
bkf34 0:73f971fb7401 420 printdealercards(25);
bkf34 0:73f971fb7401 421 dealsum();
bkf34 0:73f971fb7401 422 printf("Dealer Sum : %d\n ",dealersum);
bkf34 0:73f971fb7401 423 wait(.5);
bkf34 0:73f971fb7401 424 while(dealersum < 17) {
bkf34 0:73f971fb7401 425 drawcard();
bkf34 0:73f971fb7401 426 dealercardnumbers[dealerindex] = cardnumber;
bkf34 0:73f971fb7401 427 printf(" New Card IS : %d",dealercardnumbers[dealerindex]);
bkf34 0:73f971fb7401 428 dealercardstring[dealerindex] = cardstring;
bkf34 0:73f971fb7401 429 additionaldealercard(dealerindex);
bkf34 0:73f971fb7401 430 printaddtionaldealervalues(dealercardstring[dealerindex],dealerindex);
bkf34 0:73f971fb7401 431 printdealercards(25);
bkf34 0:73f971fb7401 432 dealsum();
bkf34 0:73f971fb7401 433 dealerindex++;
bkf34 0:73f971fb7401 434 if(dealersum > 21) {
bkf34 0:73f971fb7401 435 wait(2);
bkf34 0:73f971fb7401 436 dollars = dollars + bet;
bkf34 0:73f971fb7401 437 lcd.cls();
bkf34 0:73f971fb7401 438 lcd.locate(4,8);
bkf34 0:73f971fb7401 439 lcd.textbackground_color(BLACKJACKRED);
bkf34 0:73f971fb7401 440 lcd.color(WHITE);
bkf34 0:73f971fb7401 441 lcd.printf(" DEALER BUST");
bkf34 0:73f971fb7401 442 winloss = "win";
bkf34 0:73f971fb7401 443 break;
bkf34 0:73f971fb7401 444 }
bkf34 0:73f971fb7401 445
bkf34 0:73f971fb7401 446 }//stand while
bkf34 0:73f971fb7401 447 }//stand if
bkf34 0:73f971fb7401 448 }//end else
bkf34 0:73f971fb7401 449 dealsum();
bkf34 0:73f971fb7401 450 playsum();
bkf34 0:73f971fb7401 451 //printf("Players Sum : %d Dealer Sum: %d", playersum, dealersum);
bkf34 0:73f971fb7401 452 if((playersum > dealersum) && playerblackjackstring != "blackjack" && playersum <=21) {
bkf34 0:73f971fb7401 453 wait(2);
bkf34 0:73f971fb7401 454 dollars = dollars + bet;
bkf34 0:73f971fb7401 455 lcd.cls();
bkf34 0:73f971fb7401 456 lcd.locate(4,8);
bkf34 0:73f971fb7401 457 lcd.textbackground_color(BLACKJACKRED);
bkf34 0:73f971fb7401 458 lcd.color(WHITE);
bkf34 0:73f971fb7401 459 lcd.printf(" You Win");
bkf34 0:73f971fb7401 460 winloss = "win";
bkf34 0:73f971fb7401 461 wait(1);
bkf34 0:73f971fb7401 462
bkf34 0:73f971fb7401 463 } else if (dealersum > playersum && dealerblackjackstring != "blackjack" && dealersum <= 21) {
bkf34 0:73f971fb7401 464 wait(2);
bkf34 0:73f971fb7401 465 dollars = dollars - bet;
bkf34 0:73f971fb7401 466 lcd.cls();
bkf34 0:73f971fb7401 467 lcd.locate(4,8);
bkf34 0:73f971fb7401 468 lcd.textbackground_color(BLACKJACKRED);
bkf34 0:73f971fb7401 469 lcd.color(WHITE);
bkf34 0:73f971fb7401 470 lcd.printf(" You Lose ");
bkf34 0:73f971fb7401 471 winloss = "loss";
bkf34 0:73f971fb7401 472 wait(1);
bkf34 0:73f971fb7401 473 }
bkf34 0:73f971fb7401 474 holdvalue = playersum;
bkf34 0:73f971fb7401 475 FILE *fp = fopen("/sd/mydir/stats.txt", "a");
bkf34 0:73f971fb7401 476 if(fp == NULL) {
bkf34 0:73f971fb7401 477 error("Could not open file for write\n");
bkf34 0:73f971fb7401 478 }
bkf34 0:73f971fb7401 479 fprintf(fp, "%d\t%s \r\n",holdvalue,winloss);
bkf34 0:73f971fb7401 480 printf("%d\t%s \r\n",holdvalue,winloss);
bkf34 0:73f971fb7401 481 fclose(fp);
bkf34 0:73f971fb7401 482
bkf34 0:73f971fb7401 483
bkf34 0:73f971fb7401 484 wait(3);
bkf34 0:73f971fb7401 485 playagain();
bkf34 0:73f971fb7401 486 randseed++;
bkf34 0:73f971fb7401 487 }// first while loop
bkf34 0:73f971fb7401 488
bkf34 0:73f971fb7401 489 }