void game_display(struct game* game) { assert(game); int map_w, map_h; window_clear(); if(game->nb_player == 1) { map_w = map_get_width(level_get_curr_map(game->curr_level)); map_h = map_get_height(level_get_curr_map(game->curr_level)); for(int i = 0; i < map_w; i++) for(int j = 0; j < map_h+2; j++) window_display_image(sprite_get_empty(), i * SIZE_BLOC, j * SIZE_BLOC); } level_display(game_get_curr_level(game)); monster_display(level_get_curr_map(game->curr_level)); bomb_display(game, level_get_curr_map(game->curr_level)); game_banner_display(game); if(game->nb_player == 1) { // Single player struct player* player = game->players[0]; // Always display player_display(player); if(game->game_state == PLAYING) { player_move(game, player, level_get_curr_map(game->curr_level)); monster_move(game, level_get_curr_map(game->curr_level), player); player_update(player); monster_update(level_get_curr_map(game->curr_level)); } } else { // Multi player struct player* players_in_order[game->nb_player]; for(int i=0; i<game->nb_player; i++) players_in_order[i] = game->players[i]; game_order_players_array(game, players_in_order); for(int i = 0; i < game->nb_player; i++) { player_display(players_in_order[i]); if(game->game_state == PLAYING) { player_move(game, players_in_order[i], level_get_curr_map(game->curr_level)); player_update(players_in_order[i]); } } // end for each player } // end Multi player if(game->game_state == PLAYING) { bomb_update(level_get_curr_map(game->curr_level)); } else if(game->game_state == PAUSED) { map_w = map_get_width(level_get_curr_map(game->curr_level)); map_h = map_get_height(level_get_curr_map(game->curr_level)); int mid_w = map_w / 2 * SIZE_BLOC + map_w%2 * SIZE_BLOC / 2; int mid_h = map_h / 2 * SIZE_BLOC + map_h%2 * SIZE_BLOC / 2; menu_display(mid_w, mid_h); } window_refresh(); }
/* This function prompts the players including AI players for exchanging the cards */ int prompt_for_exchange(Player *players, Deck *d, int godmode, int iteration){ int i, bet, bet_sum, cur_bet = 0; char *choice; /* choice is represented with a string of maximal length 5 */ choice = malloc(6*sizeof(char)); bet_sum = 0; /* first deals with AI players */ for(i = 0; i < 4; ++i){ /* prompt for players if he/she is an alive AI player */ if((players+i)->isAI == 1 && (players+i)->alive == 1){ printf("%s is thinking...\n",(players+i)->name); if(godmode == 1){ printf("%s's cards before exchanging:",(players+i)->name); player_display(players+i); } /* use MC advisor to find out the best move */ choice = MC((players+i)->hand,godmode,iteration); printf("\n%s decides to exchange card %s \n",(players+i)->name,choice); parse_exchange(choice, (players+i)->hand, d); if(godmode == 1){ printf("%s's cards after exchanging:",(players+i)->name); player_display(players+i); } printf("\n"); /* generate the bet for AI players based on their hand value plus some randome variations. */ bet = hand_value((players+i)->hand) + rand() % 10 + i * 10; /* small chance of doubling */ if(rand() % 13 == 0) bet *= 2; /* if the bet is greater than the remaining chips for the player */ if(bet <= (players+i)->chip && bet >= cur_bet){ cur_bet = bet; (players+i)->chip -= bet; printf("[%s is betting %d on his/her hand.]\n\n", (players+i)->name, bet); } /* Bet all the chips */ else if(bet > (players+i)->chip && (players+i)->chip >= cur_bet){ bet = (players+i)->chip; cur_bet = bet; printf("[%s is betting %d on his/her hand.]\n\n", (players+i)->name, bet); } else{ printf("[%s folds.]\n\n",(players+i)->name); (players+i)->fold = 1; bet = 0; } bet_sum += bet; } } /* prompt for exchange for the live player */ printf("********************************************************************************\n"); printf(" Your current hand:\n "); /*player_display(players);*/ hand_value(players->hand); hand_display(players->hand); printf("********************************************************************************\n"); choice = MC(players->hand,godmode,iteration); printf("\nMC simulator suggest exchanging card %s\n\n",choice); printf("%s, please enter the card you want to exchange\n(e.g. To exchange the first card, enter 1; To exchange the second and the fifth card, enter 25;\nIf you do not want to exchange any card, enter 0):",(players)->name); scanf("%s",choice); /* if the player enters a string other than "0", parse the string and exchange the cards */ if(strcmp(choice,"0") != 0){ parse_exchange(choice, players->hand, d); printf("********************************************************************************\n"); printf("Your hand after exchanging:\n"); /*player_display(players);*/ hand_value(players->hand); hand_display(players->hand); printf("********************************************************************************\n"); printf("\n"); } /* no cards is exchanged if the player enters "0" */ else{ printf("No card exchanged for %s.\n",players->name); } /* evaluate the value */ hand_value((players)->hand); printf("Current highest bet: %d.\nPlease enter the amount you want to bet. (Enter 0 to fold)\n",cur_bet); scanf("%d",&bet); while( (bet > (players)->chip || bet < cur_bet) && bet != 0 ){ if(bet > (players)->chip) printf("You current chip is %d, you do not have enough chip, try again with a smaller amount.\n",players->chip); else printf("Please enter a number bigger than the current bet(%d).\n",cur_bet); scanf("%d",&bet); } if(bet == 0) players->fold = 1; players->chip -= bet; bet_sum += bet; cur_bet = bet; return bet_sum; }
void multi_display(struct game* game) { assert(game); struct map* map = NULL; int w, h; int* scores; switch(game_get_state(game)) { case PLAYING: case PAUSED: game_display(game); if(player_get_nb_player_alive(game) == 1) multi_change_state(game, SCORE); break; case CHOOSE_MAP: map = level_get_curr_map(game_get_curr_level(game)); w = 10 + 15 + sprite_get_max_width() + 50 + SIZE_BLOC * map_get_width(map); h = max(30 * (sprite_get_nb_map_multi() + 1), SIZE_BLOC * map_get_height(map)); window_resize( w, h); window_clear(); for(int i = 0; i < sprite_get_nb_map_multi(); i++) { window_display_image( sprite_get_map_multi(i), 10 + 15, 15 + 30 * i); } window_display_image(sprite_get_menu(M_S_SELECT_BLACK), 10, 15 + 30 * game_get_pos(game)); map_display( map, 10 + 15 + sprite_get_max_width() + 50, (h-(SIZE_BLOC * map_get_height(map))) / 2); window_refresh(); break; case SCORE: window_clear(); level_display(game_get_curr_level(game)); bomb_display(game, level_get_curr_map(game_get_curr_level(game))); for(int i = 0; i < game_get_nb_player(game); i++) player_display(game_get_player(game, i+1)); int map_w = map_get_width(level_get_curr_map(game_get_curr_level(game))); int map_h = map_get_height(level_get_curr_map(game_get_curr_level(game))); int mid_w = map_w / 2 * SIZE_BLOC + map_w%2 * SIZE_BLOC / 2; int mid_h = map_h / 2 * SIZE_BLOC + map_h%2 * SIZE_BLOC / 2; window_display_image( sprite_get_menu(M_BG_GREY), mid_w - 240, mid_h - 262); window_display_image( sprite_get_score(player_get_id_player_alive(game)), mid_w - 200, mid_h - 222); scores = game_get_scores(game); for(int i = 0; i < game_get_nb_player(game); i++) { window_display_sprite( sprite_get_players(i+1), sprite_get_rect_player_anim(0, i+1, SOUTH), mid_w - 200, mid_h - 222 + 80 + 80 * i); window_display_image( sprite_get_number_white(scores[i]), mid_w - 140, mid_h - 222 + 100 + 80 * i); } window_refresh(); break; } }