예제 #1
0
 /**
 * This function shows the possible game modes of
 * the PvP mode and allows the user to pick one
 *
 * @v info_s
 * @return	none
 * @date	2014-05-20
 * @author	Gabriel Rodrigues
 **/
void show_pvp_mode()
{

    int menu_choose;
    int control; // to verify if it is not a char!

    do
    {
        clearscr();
        printf("Triplets Game\n\n");
        printf("Choose the PvP Mode:\n");
        printf("1. Normal Mode. \n");
        printf("2. Column Mode (it's a challenge!). \n\n");
        printf("(Choose an option and press enter): ");

        control=scanf("%d",&menu_choose);
        clean_buffer_keyboard();
    }
    while(menu_choose<1 || menu_choose>2 || control == 0);

    switch(menu_choose)
    {

    case 1:
        G_current_game.pvp_mode = normal;
        break;
    case 2:
        G_current_game.pvp_mode = column;
        break;
    }
}
예제 #2
0
 /**
 * This function shows the possible interfaces of
 * the gameplay and allows the user to pick one
 *
 * @v info_s
 * @return	none
 * @date	2014-05-21
 * @author	Gabriel Rodrigues
 **/
void choose_interface(){
    int menu_choose;
    int control; // to verify if it is not a char!

    do
    {
        printf("Triplets Game\n\n");
        printf("Choose the Gameplay interface: \n");
        printf("1. HTML: \n");
        printf("2. Console: \n\n");
        printf("(Choose an option and press enter): ");

        control=scanf("%d",&menu_choose);
        clean_buffer_keyboard();
    }
    while(menu_choose<1 || menu_choose>2 || control == 0);

    switch(menu_choose)
    {

    case 1:
        G_current_game.interface_mode = html;
        break;
    case 2:
        G_current_game.interface_mode = console;
        break;
    }
}
예제 #3
0
 /**
 * This function shows the possible difficulties of
 * the CPU and allows the user to pick one
 *
 * @v info_s
 * @return	none
 * @date	2014-05-13
 * @author	Gabriel Rodrigues
 **/
void show_difficulty()
{

    int menu_choose;
    int control; // to verify if it is not a char!

    do
    {
        clearscr();
        printf("Triplets Game\n\n");
        printf("Choose the CPU difficulty:\n");
        printf("1. Player vs Computer: (EASY)\n");
        printf("2. Player vs Computer: (HARD)\n\n");
        printf("(Choose an option and press enter): ");

        control=scanf("%d",&menu_choose);
        clean_buffer_keyboard();
    }
    while(menu_choose<1 || menu_choose>2 || control == 0);

    switch(menu_choose)
    {

    case 1:
        G_current_game.cpu_mode = easy;
        break;
    case 2:
        G_current_game.cpu_mode = hard;
        break;
    }
}
예제 #4
0
 /**
 * This function shows and allows to pick the
 * player who is going to play first
 *
 * @v info_s
 * @return	none
 * @date	2014-04-22
 * @author	PL Team
 **/
void show_who_first()

{
    int control;
    int who_first_start_game;

    do
    {
        clearscr();
        printf("Triplets - %s vs %s\n\n", G_players[0].name, G_players[1].name);
        printf("Select who goes first:\n1. %s\n2. %s\n3. Random\n(Choose an option and press enter): ",G_players[0].name,G_players[1].name);
        control=scanf("%d",&who_first_start_game);
        if (who_first_start_game==3)
        {
            who_first_start_game=rand()%2 + 1;
        }
        clean_buffer_keyboard();
    }
    while (who_first_start_game<1 || who_first_start_game>2 || control==0);
    switch(who_first_start_game)
    {
    case 1:
        G_current_game.player_first= 1;
        G_players[0].number=1;
        G_players[1].number=2;
        break;
    case 2:
        G_current_game.player_first= 0;
        G_players[0].number=2;
        G_players[1].number=1;
        break;
    }
    clearscr();
}
예제 #5
0
void read_move1(position_t *pos)
{

    /* Maximum size for the buffer to read a move: 3 characters + 1 \n + 1 \0 => 5 */
#define READ_MOVE_MAX_BUFF_LEN      (5)

    int dimension = board_get_size();

    //The move_in_board (being the move read from the user) is 5 to verify the length of the input
//    char move_in_board[READ_MOVE_MAX_BUFF_LEN];
    char move_in_board[READ_MOVE_MAX_BUFF_LEN];

    // Maximum number of characters we want to read with fgets (includes '\n' and '\0')
    int maxLength = READ_MOVE_MAX_BUFF_LEN; //This allows one more character in order to verify the length of the input

    // Keep the number of char in the move_in_board string
    size_t move_in_board_strlen;

    do
    {
        do
        {
            printf("Write your move [3 characters max]: ");
            fgets(move_in_board, maxLength, stdin);    //gets in the string move_in_board a maximum of maxLength characters coming from the STDIN
            /* Terminate the string at the first \n */
            terminate_string_at_first_slash_n(move_in_board);

            /* Compute # of chars in move_in_board */
            move_in_board_strlen = strlen(move_in_board);

            if( move_in_board_strlen > 3)
            {
                clean_buffer_keyboard();
                printf("The move has a maximum of three characters!\n");
            }

        }
        while(move_in_board_strlen > 3);

        pos->X = input_is_digit(move_in_board);
        pos->Y = input_is_char(move_in_board);
        pos->Y = toupper(pos->Y);
        pos->Y_int = board_col_to_matrix_idx(pos->Y);
        //extern int board_col_to_matrix_idx(char col);

        if(pos->X < 1 || pos->X > dimension)
        {
            printf("Invalid number!\nThe number has to be between 1 - %d\n\n", dimension);
        }
        if(pos->Y_int == -1 || pos->Y_int >= dimension)
        {
            printf("Invalid letter!\nIt has to be between A - %c\n\n", 64+dimension);
        }

    }
    while(pos->Y_int == -1 || pos->Y_int >= dimension || pos->X < 1 || pos->X > dimension);

    printf("Part of the board! \n");

}
예제 #6
0
 /**
 * This function shows the menu to pick the size of the board
 *
 * @v info_s
 * @return	none
 * @date	2014-04-18
 * @author	PL Team
 **/
void choose_board()
{
    int control; // to verify if it is not a char!
    int size_board;
    do
    {
        //clearscr();
        printf("\nChoose board size:\n");
        printf("1. Small board (%dx%d)\n", BOARD_SMALL, BOARD_SMALL);
        printf("2. Medium board (%dx%d)\n", BOARD_MEDIUM, BOARD_MEDIUM);
        printf("3. Big board (%dx%d)\n", BOARD_BIG, BOARD_BIG);
        printf("4. Large board (%dx%d)\n\n", BOARD_LARGE, BOARD_LARGE);
        printf("(Choose an option and press enter): ");

        control=scanf("%d",&size_board);
        clean_buffer_keyboard();

    }
    while (size_board<1 || size_board>4 || control ==0);

    switch(size_board)
    {
    case 1:
        board_set_size(BOARD_SMALL);
        G_current_game.board_columns=BOARD_SMALL;
        G_current_game.board_rows=BOARD_SMALL;
        break;
    case 2:
        board_set_size(BOARD_MEDIUM);
        G_current_game.board_columns=BOARD_MEDIUM;
        G_current_game.board_rows=BOARD_MEDIUM;
        break;
    case 3:
        board_set_size(BOARD_BIG);
        G_current_game.board_columns=BOARD_BIG;
        G_current_game.board_rows=BOARD_BIG;
        break;
    case 4:
        board_set_size(BOARD_LARGE);
        G_current_game.board_columns=BOARD_LARGE;
        G_current_game.board_rows=BOARD_LARGE;
        break;
    default:
        clearscr();
        choose_board();
        break;
    }
}
/**
 * This function reads a number from the user
 * that represents the row in the board
 *
 * @v info_s	Just to play the column mode
 * @return  void
 * @date	2014-05-20
 * @author	Gabriel Rodrigues (PT Team)
 **/
void read_row(position_t *pos){

    int control;
    int dimension = board_get_size();
    do
    {
        printf("Write your move: %c", pos->Y);
        control = scanf("%d", &pos->X);

        if(pos->X < 1 || pos->X > dimension || control == 0)
        {
            printf("Invalid number!\nThe number has to be between 1 - %d\n", dimension);
        }
        clean_buffer_keyboard();
    }
    while(pos->X < 1 || pos->X > dimension || control == 0);

//    if the move reach this point is because is -> printf("Part of the board! \n");

}
void replay_menu()
{
    int gameCounter=get_game_counter();
    int control;
    int i;
    int option;

    if (gameCounter==0)
    {
        printf("There are no games available.\n");
        printf("Press any key to go back to main menu...");
        readchar();
    }
    else
    {
        do
        {
            printf("\nGames available to replay:\n\n");

            for (i=1; i<=gameCounter; i++)
            {
                print_game_information(i);
            }

            printf("\n(Choose an option and press enter).\nInsert 0 to return to main menu: ");

            control=scanf("%d",&option);
            clean_buffer_keyboard();

        }
        while (control ==0 || option<0 || option>gameCounter);
        if (option!=0)
        {
            loadLogs(option);
        }
    }
}
예제 #9
0
파일: PL_ui.c 프로젝트: drajvver/triplets
void show_menu()
{
    int who_first_start_game;
    int menu_choose;
    int control; // to verify if it is not a char!

    do
    {
        clearscr();
        printf("Triplets Game\n\n");
        printf("1. Play : Player vs Computer (PvC)\n");
        printf("2. Play : Player vs Player (PvP)\n");
        printf("3. Game rules\n");
        printf("4. High scores\n");
        printf("5. Credits\n\n");
        printf("6. Exit Game.\n\n");
        printf("(Choose an option and press enter): ");



        control=scanf("%d",&menu_choose);
        clean_buffer_keyboard();


    }
    while (menu_choose<1 || menu_choose>6 || control == 0);


    switch(menu_choose)
    {

    case 1:
        G_current_game.game_mode=pvc;
        clearscr();
        printf("Triplets - Player vs Computer\n\n");
        printf("Enter your name: ");
        scanf("%s",G_players[0].name);
        strcpy(G_players[1].name, "CPU");// G_players[1] is cpu player
        choose_board();


        do
        {
            clearscr();
            printf("Triplets - %s vs %s\n\n", G_players[0].name, G_players[1].name);
            printf("Select who goes first:\n1. %s\n2. %s\n\n(Choose an option and press enter): ",G_players[0].name,G_players[1].name);
            control=scanf("%d",&who_first_start_game);
            clean_buffer_keyboard();

        }
        while (who_first_start_game<1 || who_first_start_game>2 || control==0);

        switch(who_first_start_game)
        {
        case 1:
            G_current_game.player_first= 1;
            break;
        case 2:
            G_current_game.player_first= 0;
            break;
        }

        clearscr();
        break;
    case 2:
        G_current_game.game_mode=pvp;
        clearscr();
        printf("Triplets - Player vs Player\n");
        printf("Enter the name of player 1: ");
        scanf("%s",G_players[0].name);
        printf("\nEnter the name of player 2: ");
        scanf("%s",G_players[1].name);
        choose_board();

        do
        {
            clearscr();
            printf("Triplets - %s vs %s\n\n", G_players[0].name, G_players[1].name);
            printf("Select who goes first:\n1. %s\n2. %s\n\n(Choose an option and press enter): ",G_players[0].name,G_players[1].name);
            control=scanf("%d",&who_first_start_game);
            clean_buffer_keyboard();
        }
        while (who_first_start_game<1 || who_first_start_game>2 || control==0);
        switch(who_first_start_game)
        {
        case 1:
            G_current_game.player_first= 1;
            break;
        case 2:
            G_current_game.player_first= 0;
            break;
        }
        clearscr();
        break;

    case 3:
        show_game_rules();
        show_menu();
        break;
    case 4:
        //show High scores//
        show_highscores();
        show_menu();
        break;
    case 5:
        show_credits();
        show_menu();
        break;
    case 6:
        exit(0);
        break;
    default:
        clearscr();
        show_menu();
        break;
    }
}
예제 #10
0
 /**
 * This function shows the main menu
 *
 * @v info_s
 * @return	none
 * @date	2014-04-14
 * @author	PL Team
 **/
void show_menu()
{
    int menu_choose;
    int control; // to verify if it is not a char!
    char player1nameAux[MAX_PLAYERNAME_LENGTH]="";
    char player2nameAux[MAX_PLAYERNAME_LENGTH]="";

    do
    {
        clearscr();
        printf("Triplets Game\n\n");
        printf("1. Play : Player vs Computer (PvC)\n");
        printf("2. Play : Player vs Player (PvP)\n");
        printf("3. Game rules\n");
        printf("4. High scores\n");
        printf("5. Replay game\n");
        printf("6. Credits\n\n");
        printf("7. Exit Game.\n\n");
        printf("(Choose an option and press enter): ");



        control=scanf("%d",&menu_choose);
        clean_buffer_keyboard();


    }
    while (menu_choose<1 || menu_choose>7 || control == 0);


    switch(menu_choose)
    {

    case 1:
        G_current_game.game_mode=pvc;
        G_current_game.pvp_mode = notpvp;
        show_difficulty();
        choose_interface();
        clearscr();
        printf("Triplets - Player vs Computer \n\n");
        do
        {
            printf("Enter your name: ");
            fgets(G_players[0].name, MAX_PLAYERNAME_LENGTH, stdin);
            terminate_string_at_first_slash_n(G_players[0].name);
            strcpy(player1nameAux,G_players[0].name);
            string_to_lower(player1nameAux);

            if (!strcmp(player1nameAux,"cpu"))
            {
                printf("Invalid name.\n");
            }
        }
        while (!strcmp(player1nameAux,"cpu"));
        strcpy(G_players[1].name, "CPU");// G_players[1] is cpu player
        choose_board();


        show_who_first();

        break;

    case 2:
        G_current_game.game_mode=pvp;
        G_current_game.cpu_mode = none;
        clearscr();
        printf("Triplets - Player vs Player\n");
        do
        {
            printf("Enter the name of player 1: ");
            fgets(G_players[0].name, MAX_PLAYERNAME_LENGTH, stdin);
            terminate_string_at_first_slash_n(G_players[0].name);
            strcpy(player1nameAux,G_players[0].name);
            string_to_lower(player1nameAux);

            if (!(strcmp(player1nameAux,"cpu")))
            {
                printf("Invalid name.\n");
            }
        }
        while (!(strcmp(player1nameAux,"cpu")));
        do
        {
            printf("\nEnter the name of player 2: ");
            fgets(G_players[1].name, MAX_PLAYERNAME_LENGTH, stdin);
            terminate_string_at_first_slash_n(G_players[1].name);
            strcpy(player2nameAux,G_players[1].name);
            string_to_lower(player2nameAux);

            if (!(strcmp(player2nameAux,"cpu")) || !(strcmp(player2nameAux,player1nameAux)))
            {
                printf("Invalid name.\n");
            }
        }
        while (!(strcmp(player2nameAux,"cpu")) || !(strcmp(player2nameAux,player1nameAux)));

        show_pvp_mode();
        if (G_current_game.pvp_mode == normal)
        {
            choose_interface();
        }
        else
        {
            G_current_game.interface_mode = console;
        }
        choose_board();
        show_who_first();

        break;

    case 3:
        show_game_rules();
        show_menu();
        break;
    case 4:
        //show High scores//
        show_highscores();
        show_menu();
        break;
    case 5:
        replay_menu(); // this is in PT_save_read_moves.c
        show_menu();
        break;
    case 6:
        show_credits();
        show_menu();
        break;
    case 7:
        exit(0);
        break;
    default:
        clearscr();
        show_menu();
        break;
    }
}