void main_menu(){ int choice; system("cls"); system("COLOR 1C"); //selecting color of background and text to be displayed printf("\n-----START MENU-----"); printf("\n1 : Play with X"); printf("\n2 : Play with O"); printf("\n3 : Exit"); printf("\nEnter your choice:> "); scanf("%d",&choice); turn = 1; switch (choice){ case 1: player = 1; computer = 0; player_1(); break; case 2: player = 0; computer = 1; begin_game(); break; case 3: exit(1); default: main_menu(); } }
void begin_game(t_env *e) { if (e->my_turn) { gnl_until("0123456"); populate_map(e); } else { e->my_turn = 1; gnl_until("01234"); populate_map(e); } malloc_piece(e); populate_piece(e); if (!make_move(e)) { print_move(0, 0); ft_freemap(e); exit(0); } free_piece(e); e->my_turn = 0; gnl_until("Plateau"); begin_game(e); }
void player_1(){ int pos; tie_checker(); draw_board(); gotoxy(30,18); printf("Your Turn :> "); scanf("%d",&pos); if(panel[pos] != 2) player_1(); if(pos == posswin(player)){ go(pos); draw_board(); gotoxy(30,20); system("cls"); //clearing screen to displa result system("COLOR 1A"); //selecting color of panel showing result printf("\t\t\t\tPlayer Wins\n\t\t\t -----GAME OVER-----"); getch(); exit(0); } go(pos); draw_board(); begin_game(); }
/* * Play a number of training games. */ int main(int argc, char *argv[]) { game my_game; int i, j, n = 100; int num_players = 3; int expansion = 0, advanced = 0, promo = 0; char buf[1024], *names[MAX_PLAYER]; double factor = 1.0; /* Set random seed */ my_game.random_seed = time(NULL); /* Read card database */ if (read_cards(NULL) < 0) { /* Exit */ exit(1); } /* Parse arguments */ for (i = 1; i < argc; i++) { /* Check for verbosity */ if (!strcmp(argv[i], "-v")) { /* Set verbose flag */ verbose++; } /* Check for number of players */ else if (!strcmp(argv[i], "-p")) { /* Set number of players */ num_players = atoi(argv[++i]); } /* Check for advanced game */ else if (!strcmp(argv[i], "-a")) { /* Set advanced flag */ advanced = 1; } /* Check for expansion level */ else if (!strcmp(argv[i], "-e")) { /* Set expansion level */ expansion = atoi(argv[++i]); } /* Check for promo cards */ else if (!strcmp(argv[i], "-o")) { /* Set promo cards */ promo = 1; } /* Check for number of games */ else if (!strcmp(argv[i], "-n")) { /* Set number of games */ n = atoi(argv[++i]); } /* Check for random seed */ else if (!strcmp(argv[i], "-r")) { /* Set random seed */ my_game.random_seed = atoi(argv[++i]); } /* Check for alpha factor */ else if (!strcmp(argv[i], "-f")) { /* Set factor */ factor = atof(argv[++i]); } } /* Set number of players */ my_game.num_players = num_players; /* Set expansion level */ my_game.expanded = expansion; /* Set advanced flag */ my_game.advanced = advanced; /* Set promo flag */ my_game.promo = promo; /* Assume no options disabled */ my_game.goal_disabled = 0; my_game.takeover_disabled = 0; /* No campaign selected */ my_game.camp = NULL; /* Call initialization functions */ for (i = 0; i < num_players; i++) { /* Create player name */ sprintf(buf, "Player %d", i); /* Set player name */ my_game.p[i].name = strdup(buf); names[i] = my_game.p[i].name; /* Set player interfaces to AI functions */ my_game.p[i].control = &ai_func; /* Initialize AI */ my_game.p[i].control->init(&my_game, i, factor); /* Create choice log for player */ my_game.p[i].choice_log = (int *)malloc(sizeof(int) * 4096); /* Clear choice log size and position */ my_game.p[i].choice_size = 0; my_game.p[i].choice_pos = 0; } /* Play a number of games */ for (i = 0; i < n; i++) { /* Initialize game */ init_game(&my_game); printf("Start seed: %u\n", my_game.start_seed); /* Begin game */ begin_game(&my_game); /* Play game rounds until finished */ while (game_round(&my_game)); /* Score game */ score_game(&my_game); /* Print result */ for (j = 0; j < num_players; j++) { /* Print score */ printf("%s: %d\n", my_game.p[j].name, my_game.p[j].end_vp); } /* Declare winner */ declare_winner(&my_game); /* Call player game over functions */ for (j = 0; j < num_players; j++) { /* Call game over function */ my_game.p[j].control->game_over(&my_game, j); /* Clear choice log */ my_game.p[j].choice_size = 0; my_game.p[j].choice_pos = 0; } /* Reset player names */ for (j = 0; j < num_players; j++) { /* Reset name */ my_game.p[j].name = names[j]; } } /* Call interface shutdown functions */ for (i = 0; i < num_players; i++) { /* Call shutdown function */ my_game.p[i].control->shutdown(&my_game, i); } /* Done */ return 0; }