void rand_card(void) { while (card_used[current_card]) { current_card = rand() % NUMBER_OF_CARDS; } load_card(); }
void init_cards(Window *main_window, CardBack_t main_card_front, CardBack_t main_card_back) { reset_card_used(); current_card = rand() % NUMBER_OF_CARDS; current_side = FRONT; window = main_window; window_set_background_color(main_window, GColorBlack); card_front = main_card_front; card_back = main_card_back; init_card_text(); GRect bounds = layer_get_bounds(window_get_root_layer(window)); load_card(); }
void init_cards(Window *main_window, GBitmap *main_image_front, BitmapLayer *main_image_layer_front, CardBack_t main_card_back) { reset_card_used(); current_card = rand() % NUMBER_OF_CARDS; current_side = FRONT; window = main_window; image_front = main_image_front; image_layer_front = main_image_layer_front; card_back = main_card_back; init_card_text(); GRect bounds = layer_get_bounds(window_get_root_layer(window)); image_layer_front = bitmap_layer_create(bounds); bitmap_layer_set_alignment(image_layer_front, GAlignCenter); layer_add_child(window_get_root_layer(window), (Layer*)image_layer_front); load_card(); }
/* * Perform the given action. */ static void perform_act(game *g, action a) { player *p, *opp; int old_phase; /* Get player pointers */ p = &g->p[g->turn]; opp = &g->p[!g->turn]; /* Remember current phase */ old_phase = p->phase; /* Switch on action */ switch (a.act) { /* No action, advance phase counter */ case ACT_NONE: { /* Advance phase counter */ p->phase++; /* Take care of bookkeeping */ switch (old_phase) { /* Start of turn */ case PHASE_START: /* Start turn */ start_turn(g); /* Done */ break; /* After support/booster */ case PHASE_AFTER_SB: /* End support phase */ end_support(g); /* Done */ break; /* Refresh hand */ case PHASE_REFRESH: /* Refresh */ refresh_phase(g); /* Done */ break; /* End of turn */ case PHASE_END: /* End current turn */ end_turn(g); /* Done */ break; /* Move to next player */ case PHASE_OVER: /* Player is done */ p->phase = PHASE_NONE; /* Next player */ g->turn = !g->turn; /* Start opponent's turn */ opp->phase = PHASE_START; /* Done (completely) */ return; } /* Clear last played card */ p->last_played = 0; /* Done */ break; } /* Retreat */ case ACT_RETREAT: { /* Retreat */ retreat(g); /* Done */ break; } /* Retrieve a card */ case ACT_RETRIEVE: { /* Set last played */ p->last_played = a.index; /* Retrieve card */ retrieve_card(g, a.arg); /* Done */ break; } /* Play a card */ case ACT_PLAY: { /* Set last played */ p->last_played = a.index; /* Play card */ play_card(g, a.arg, 0, 0); /* Done */ break; } /* Play a card without special effect */ case ACT_PLAY_NO: { /* Set last played */ p->last_played = a.index; /* Play card */ play_card(g, a.arg, 1, 0); /* Done */ break; } /* Announce power */ case ACT_ANN_FIRE: case ACT_ANN_EARTH: { /* Increment phase counter */ p->phase++; /* Announce power */ announce_power(g, a.act - ACT_ANN_FIRE); /* Done */ break; } /* Use card special power */ case ACT_USE: { /* Use card */ use_special(g, a.arg); /* Done */ break; } /* Satisfy opponent's "discard" card */ case ACT_SATISFY: { /* Satisfy requirement */ satisfy_discard(g, a.arg); /* Done */ break; } /* Land a ship */ case ACT_LAND: { /* Set last played */ p->last_played = a.index; /* Land ship */ land_ship(g, a.arg); /* Done */ break; } /* Load a card onto a ship */ case ACT_LOAD: { /* Set last played */ p->last_played = a.index; /* Load card */ load_card(g, a.arg, a.target); /* Done */ break; } /* Play a bluff card */ case ACT_BLUFF: { /* Set last played */ p->last_played = a.index; /* Play bluff */ play_bluff(g, a.arg); /* Done */ break; } /* Reveal a bluff card */ case ACT_REVEAL: { /* Set last played */ p->last_played = a.index; /* Reveal bluff */ reveal_bluff(g, g->turn, a.arg); /* Done */ break; } } }