Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: main.c
- * Author: andrew
- *
- * Created on June 28, 2011, 9:22 AM
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include "gba_drivers.h"
- #include "LinkedLists.h"
- #include "CMemLeak.h"
- #include "cards.h"
- #define BLACK_NDX 0
- #define WHITE_NDX 1
- #define RED_NDX 2
- #define GREEN_NDX 3
- #define BLUE_NDX 4
- #define YELLOW_NDX 5
- #define MAGENTA_NDX 6
- #define CYAN_NDX 7
- #define GRAY_NDX 8
- #define CLR_LEN 9
- typedef enum {
- START, SHUFFLE, GAMEPLAY, WIN, LOSE
- } STATES;
- void displayCards(LinkedList* deck, int row) {
- LLNode* phere = deck->head;
- int i = 0;
- while (phere->next != NULL) {
- drawCard(row, 39 + 22 + i, phere->data.suit, phere->data.rank, 0, 2, 1);
- phere = phere->next;
- i++;
- }
- }
- void rankClassify(LinkedList* playerhand) {
- int points = 0;
- LLNode* phere = playerhand->head;
- while (phere->next != NULL) {
- points = points + phere->data.rank;
- phere = phere->next;
- }
- }
- int main() {
- setup();
- u16 pal_clrs[CLR_LEN] = {BLACK, WHITE, RED, GREEN, BLUE, YELLOW, MAGENTA, CYAN, GRAY};
- load_palette(pal_clrs, CLR_LEN);
- int seed = 0;
- //int rand = rand(seed);
- int i, j;
- int cnt = (cnt - 1) % 10;
- int ccol, crow, dpoints, ppoints;
- CARD cards[52];
- LinkedList* deck = LLnew();
- LinkedList* dealerhand = LLnew();
- LinkedList* playerhand = LLnew();
- STATES trans = START;
- setup();
- while (keepGoing()) {
- waitForScan();
- flipPage();
- ++seed;
- switch (trans) {
- case START:
- fillBackGround(0);
- drawCard(40, 60, 4, 2, GREEN_NDX, RED_NDX, WHITE_NDX);
- drawCard(40, 90, 4, 2, YELLOW_NDX, RED_NDX, WHITE_NDX);
- drawCard(40, 120, 4, 2, RED_NDX, RED_NDX, WHITE_NDX);
- drawCard(40, 150, 4, 2, BLUE_NDX, RED_NDX, WHITE_NDX);
- drawString(13, 80, "BLACK JACK", WHITE_NDX);
- drawRect(10, 70, 15, 80, 1);
- drawString(60, 80, "Press Start", WHITE_NDX);
- drawString(80, 65, "***DIRECTIONS***", YELLOW_NDX);
- drawString(120, 45, "Hit Me! -------> Press A", YELLOW_NDX);
- drawString(140, 45, "Fold! ---------> Press B", YELLOW_NDX);
- if (check_key(BUTTON_NDX_START) == KEY_ON) {
- trans = SHUFFLE;
- //drawCard(20, 60, 4,2, BLACK_NDX, RED_NDX, WHITE_NDX);
- }
- break;
- case SHUFFLE:
- srand(seed);
- for (i = 0; i < NUM_SUITS; i++) {//initializing the 52 card deck
- for (j = 1; j < NUM_RANKS + 1; j++) {
- CARD card;
- card.suit = i;
- card.rank = j;
- addToHead(deck, card); //plist is now the deck
- }
- }
- //phere is deck->head
- /*now shuffle the nodes*/
- //you need a node like a phere that tells you where you curently are
- //Take card
- // Select a card
- LLNode* temp = deck->head; //temp is our selector
- for (i = 0; i < (rand() % 52); i++) {
- temp = temp->next;
- }
- // Grab a card
- temp = LLcut(deck, temp);
- //put it back in the deck
- LLinsert(deck, deck->head, temp);
- if (check_key(BUTTON_NDX_START) == KEY_ON) {
- trans = GAMEPLAY;
- }
- break;
- case GAMEPLAY:
- fillBackGround(GREEN_NDX);
- drawRect(5, 5, 150, 230, 1);
- displayCards(deck, 20);
- displayCards(deck, 120);
- if (check_key(BUTTON_NDX_A) == KEY_ON) {
- temp = LLcut(deck, deck->head);
- addToTail(playerhand, temp->data);
- }
- if (check_key(BUTTON_NDX_B) == KEY_ON) {
- dpoints = rankClassify(dealerhand);
- ppoints = rankClassify(playerhand);
- while (dpoints < 17) {
- temp = LLcut(deck, deck->head);
- addToTail(dealerhand, temp->data);
- dpoints = rankClassify(dealerhand);
- }
- }
- displayCards(dealerhand, 11);
- if (check_key(BUTTON_NDX_START) == KEY_ON) {
- trans = GAMEPLAY;
- }
- if(ppoints <= 21 && ppoints > dpoints) trans = WIN;
- else if(ppoints > 21 || ppoints<= dpoints) trans = LOSE;
- //while --> for dealer
- //while --> for player
- break;
- case WIN:
- fillBackGround(3);
- break;
- case LOSE:
- fillBackGround(4);
- break;
- }
- }
- finish();
- return (EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement