Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.08 KB | None | 0 0
  1. /*
  2.  * File:   main.c
  3.  * Author: andrew
  4.  *
  5.  * Created on June 28, 2011, 9:22 AM
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include "gba_drivers.h"
  11. #include "LinkedLists.h"
  12. #include "CMemLeak.h"
  13. #include "cards.h"
  14.  
  15. #define BLACK_NDX 0
  16. #define WHITE_NDX 1
  17. #define RED_NDX 2
  18. #define GREEN_NDX 3
  19. #define BLUE_NDX 4
  20. #define YELLOW_NDX 5
  21. #define MAGENTA_NDX 6
  22. #define CYAN_NDX 7
  23. #define GRAY_NDX 8
  24. #define CLR_LEN 9
  25.  
  26. typedef enum {
  27.     START, SHUFFLE, GAMEPLAY, WIN, LOSE
  28. } STATES;
  29.  
  30.  
  31. void displayCards(LinkedList* deck, int row) {
  32.     LLNode* phere = deck->head;
  33.     int i = 0;
  34.     while (phere->next != NULL) {
  35.         drawCard(row, 39 + 22 + i, phere->data.suit, phere->data.rank, 0, 2, 1);
  36.         phere = phere->next;
  37.         i++;
  38.     }
  39. }
  40.  
  41. void rankClassify(LinkedList* playerhand) {
  42.     int points = 0;
  43.     LLNode* phere = playerhand->head;
  44.     while (phere->next != NULL) {
  45.         points = points + phere->data.rank;
  46.         phere = phere->next;
  47.     }
  48. }
  49.  
  50. int main() {
  51.     setup();
  52.     u16 pal_clrs[CLR_LEN] = {BLACK, WHITE, RED, GREEN, BLUE, YELLOW, MAGENTA, CYAN, GRAY};
  53.     load_palette(pal_clrs, CLR_LEN);
  54.     int seed = 0;
  55.     //int rand = rand(seed);
  56.     int i, j;
  57.     int cnt = (cnt - 1) % 10;
  58.     int ccol, crow, dpoints, ppoints;
  59.     CARD cards[52];
  60.     LinkedList* deck = LLnew();
  61.     LinkedList* dealerhand = LLnew();
  62.     LinkedList* playerhand = LLnew();
  63.     STATES trans = START;
  64.     setup();
  65.     while (keepGoing()) {
  66.         waitForScan();
  67.         flipPage();
  68.         ++seed;
  69.         switch (trans) {
  70.             case START:
  71.                 fillBackGround(0);
  72.                 drawCard(40, 60, 4, 2, GREEN_NDX, RED_NDX, WHITE_NDX);
  73.                 drawCard(40, 90, 4, 2, YELLOW_NDX, RED_NDX, WHITE_NDX);
  74.                 drawCard(40, 120, 4, 2, RED_NDX, RED_NDX, WHITE_NDX);
  75.                 drawCard(40, 150, 4, 2, BLUE_NDX, RED_NDX, WHITE_NDX);
  76.                 drawString(13, 80, "BLACK JACK", WHITE_NDX);
  77.                 drawRect(10, 70, 15, 80, 1);
  78.                 drawString(60, 80, "Press Start", WHITE_NDX);
  79.                 drawString(80, 65, "***DIRECTIONS***", YELLOW_NDX);
  80.                 drawString(120, 45, "Hit Me! -------> Press A", YELLOW_NDX);
  81.                 drawString(140, 45, "Fold! ---------> Press B", YELLOW_NDX);
  82.                 if (check_key(BUTTON_NDX_START) == KEY_ON) {
  83.                     trans = SHUFFLE;
  84.                     //drawCard(20, 60, 4,2, BLACK_NDX, RED_NDX, WHITE_NDX);
  85.                 }
  86.                 break;
  87.             case SHUFFLE:
  88.  
  89.                 srand(seed);
  90.                 for (i = 0; i < NUM_SUITS; i++) {//initializing the 52 card deck
  91.                     for (j = 1; j < NUM_RANKS + 1; j++) {
  92.                         CARD card;
  93.                         card.suit = i;
  94.                         card.rank = j;
  95.                         addToHead(deck, card); //plist is now the deck
  96.                     }
  97.                 }
  98.                 //phere is deck->head
  99.  
  100.  
  101.  
  102.                 /*now shuffle the nodes*/
  103.                 //you need a node like a phere that tells you where you curently are
  104.                 //Take card
  105.                 //  Select a card
  106.                 LLNode* temp = deck->head; //temp is our selector
  107.                 for (i = 0; i < (rand() % 52); i++) {
  108.                     temp = temp->next;
  109.                 }
  110.                 //  Grab a card
  111.                 temp = LLcut(deck, temp);
  112.                 //put it back in the deck
  113.                 LLinsert(deck, deck->head, temp);
  114.  
  115.                 if (check_key(BUTTON_NDX_START) == KEY_ON) {
  116.                     trans = GAMEPLAY;
  117.                 }
  118.                 break;
  119.             case GAMEPLAY:
  120.                 fillBackGround(GREEN_NDX);
  121.                 drawRect(5, 5, 150, 230, 1);
  122.                 displayCards(deck, 20);
  123.                 displayCards(deck, 120);
  124.                 if (check_key(BUTTON_NDX_A) == KEY_ON) {
  125.                     temp = LLcut(deck, deck->head);
  126.                     addToTail(playerhand, temp->data);
  127.                 }
  128.  
  129.                 if (check_key(BUTTON_NDX_B) == KEY_ON) {
  130.  
  131.                     dpoints = rankClassify(dealerhand);
  132.                     ppoints = rankClassify(playerhand);
  133.                     while (dpoints < 17) {
  134.                         temp = LLcut(deck, deck->head);
  135.                         addToTail(dealerhand, temp->data);
  136.                         dpoints = rankClassify(dealerhand);
  137.                     }
  138.                 }
  139.  
  140.                 displayCards(dealerhand, 11);
  141.  
  142.                 if (check_key(BUTTON_NDX_START) == KEY_ON) {
  143.                     trans = GAMEPLAY;
  144.                 }
  145.                 if(ppoints <= 21 && ppoints > dpoints) trans = WIN;
  146.                 else if(ppoints > 21 || ppoints<= dpoints) trans = LOSE;
  147.                 //while --> for dealer
  148.                 //while --> for player
  149.                 break;
  150.             case WIN:
  151.                 fillBackGround(3);
  152.                 break;
  153.             case LOSE:
  154.                 fillBackGround(4);
  155.                 break;
  156.  
  157.         }
  158.  
  159.  
  160.     }
  161.     finish();
  162.     return (EXIT_SUCCESS);
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement