CheckersBoard::CheckersBoard() 
{
    /*
     * In ASCII
     * 46 == '.'
     * 88 == 'X'
     * 79 == 'O'
     */
    positions_ = { 
    {1,  46}, {2,  88}, {3,  46}, {4,  88}, {5,  46}, {6,  88}, {7,  46}, {8,  88},
    {9,  88}, {10, 46}, {11, 88}, {12, 46}, {13, 88}, {14, 46}, {15, 88}, {16, 46},
    {17, 46}, {18, 88}, {19, 46}, {20, 88}, {21, 46}, {22, 88}, {23, 46}, {24, 88},
    {25, 46}, {26, 46}, {27, 46}, {28, 46}, {29, 46}, {30, 46}, {31, 46}, {32, 46},
    {33, 46}, {34, 46}, {35, 46}, {36, 46}, {37, 46}, {38, 46}, {39, 46}, {40, 46},
    {41, 79}, {42, 46}, {43, 79}, {44, 46}, {45, 79}, {46, 46}, {47, 79}, {48, 46},
    {49, 46}, {50, 79}, {51, 46}, {52, 79}, {53, 46}, {54, 79}, {55, 46}, {56, 79},
    {57, 79}, {58, 46}, {59, 79}, {60, 46}, {61, 79}, {62, 46}, {63, 79}, {64, 46}};
    displayRules();
    displayBoard();
}
Beispiel #2
0
int main(int argc, char* argv[]) {
    printf("Choose your difficulty: (e)asy or (n)ormal.\n");
    char buffer[1];
    int difficulty;
    bool entered_command = false, play_again = true;
    for(unsigned int bufIndex = 0; bufIndex < sizeof(buffer); bufIndex++) {
        memset(&buffer[bufIndex], 0, sizeof(buffer[bufIndex]));  // empty buffer
    }

    while( (buffer[0] != 'e') && (buffer[0] != 'n') ) {
        if(entered_command) {printf("Invalid Command.\n");}
        printf("> ");
        for(unsigned int bufIndex = 0; bufIndex < sizeof(buffer); bufIndex++) {
            memset(&buffer[bufIndex], 0, sizeof(buffer[bufIndex]));  // empty buffer
        }
        fgets(buffer, 15, stdin);
        entered_command = true;
    }

    if(buffer[0] == 'e') {difficulty = 1;}
    else {difficulty = 2;}
    for(unsigned int bufIndex = 0; bufIndex < sizeof(buffer); bufIndex++) {
        memset(&buffer[bufIndex], 0, sizeof(buffer[bufIndex]));  // empty buffer
    }
    printf("Welcome to tic-tac-toe! You'll play as 'x'.\n");
    printf("If you need to hear the rules for the game, press r and hit enter.\n");
    printf("Otherwise, press s and hit enter to start a new game.\n");
    entered_command = false;

    while( (buffer[0] != 'r') && (buffer[0] != 's') ) {
        if(entered_command) {printf("Invalid Command.\n");}
        printf("> ");
        for(unsigned int bufIndex = 0; bufIndex < sizeof(buffer); bufIndex++) {
            memset(&buffer[bufIndex], 0, sizeof(buffer[bufIndex]));  // empty buffer
        }
        fgets(buffer, 15, stdin);
        entered_command = true;
    }

    if(buffer[0] == 'r') {
        displayRules();
        printf("Now starting game.\n");
    }

    displayInstructions();
    while(play_again) {
        beginNewGame(difficulty);
        entered_command = false;
        buffer[0] = 'i';

        while( (buffer[0] != 'y') && (buffer[0] != 'n') ) {
            if(entered_command) {printf("Invalid Command.\n");}
            printf("Play Again? (y)es/(n)o > ");
            for(unsigned int bufIndex = 0; bufIndex < sizeof(buffer); bufIndex++) {
                memset(&buffer[bufIndex], 0, sizeof(buffer[bufIndex]));  // empty buffer
            }
            fgets(buffer, 15, stdin);
            entered_command = true;
        }
        if(buffer[0] == 'n') {play_again = false;}
    }
    return 0;
}