Untitled

user_7863373 avatar
user_7863373
plain_text
03/30/2026 3:11 AM
41.1 KB
20
Indexable
// cs_chicken.c
// Written by Akshay Govil z5765346 on <INSERT DATE>
//
// Description: <It follows the instructions provided>

// Provided Libraries
#include <stdio.h>

// Add your own #include statements below this line


// Provided constants
#define COLS 10
#define ROWS 10
#define INITIAL_POINTS 0
#define DEFAULT_POINT_TARGET 20

// Add your own #define constants below this line


// Provided Enums
// Enum for features on the game board
enum entity {
    EMPTY,
    COIN,
    TREE,
    ROAD,
    CAR_FACING_RIGHT,
    CAR_FACING_LEFT,
    HEADLIGHTS,
    KANGAROO,
    WOMBAT_TUNNEL,
    BABY_CHICKEN
};

// Add your own enums below this line


// Represents a tile on the board (you may edit this and add your own fields)
struct tile {
    enum entity entity;
    int original_coin;
    int tunnel_id;
};

// Add your own structs below this line


// Provided Function Prototypes
void print_welcome(void);
void initialise_board(struct tile board[ROWS][COLS]);
void print_board(
    struct tile board[ROWS][COLS], 
    int player_row, 
    int player_col,
    int curr_score,
    int target_score,
    int *is_shocked
);
void print_board_line(void);
void print_board_footer(int curr_score, int target_score);
void print_game_statistics(
    int turns_taken, 
    int step_count, 
    int coins,
    int score
);

// Additional Function Prototypes
void print_game_won(void);
void print_game_lost(void);

// Add your own function prototypes below this line
void setup_player_position(int *row, int *col);
void setup_startup_commands(struct tile board[ROWS][COLS], int player_row, int player_col, int *target_score, int *driving_mode, int *scrolling_mode);
void gameplay_stage(struct tile board[ROWS][COLS], int *player_row, int *player_col, int *score, int *target_score, int *is_shocked, int driving_mode, int scrolling_mode);
void move_cars(struct tile board[ROWS][COLS]);
void scroll_board(struct tile board[ROWS][COLS]);
void restore_top_row(struct tile board[ROWS][COLS]);

//small ones:
int is_on_board(int row, int col);
int is_player_position(
    int row, int col, int player_row, int player_col
);
int is_empty_tile(struct tile board[ROWS][COLS], int row, int col);
int is_kangaroo_jump_command(char command);
int is_car(enum entity entity);
int is_blocking_kangaroo(enum entity entity);
void print_loss_and_exit(
    struct tile board[ROWS][COLS],
    int player_row,
    int player_col,
    int score,
    int target_score,
    int *is_shocked,
    int turns_taken,
    int step_count,
    int coins_collected
);

// Provided sample main() function (you will need to modify this)
int main(void) {
    print_welcome();
    int player_row;
    int player_col;
    int is_shocked = 0;
    int driving_mode = 0;
    int scrolling_mode = 0;
    setup_player_position(&player_row, &player_col);

    struct tile board[ROWS][COLS];
    initialise_board(board);

    print_board(
        board,
        player_row,
        player_col,
        INITIAL_POINTS, 
        DEFAULT_POINT_TARGET,
        &is_shocked
    );

    int target_score = DEFAULT_POINT_TARGET;

    setup_startup_commands(
        board,
        player_row,
        player_col,
        &target_score,
        &driving_mode,
        &scrolling_mode
    );

    print_board(
        board,
        player_row,
        player_col,
        INITIAL_POINTS, 
        target_score,
        &is_shocked
    );

    printf("============ Gameplay Phase =============\n");

    int score = INITIAL_POINTS;
    
    gameplay_stage(
        board,
        &player_row,
        &player_col,
        &score,
        &target_score,
        &is_shocked,
        driving_mode,
        scrolling_mode
    );

    return 0;
}

// Add your function definitions below this line
//first small ones:
int is_on_board(int row, int col) {
    return row >= 0 && row < ROWS && col >= 0 && col < COLS;
}

int is_player_position(
    int row, int col, int player_row, int player_col
) {
    return row == player_row && col == player_col;
}

int is_empty_tile(struct tile board[ROWS][COLS], int row, int col) {
    return board[row][col].entity == EMPTY;
}

int is_kangaroo_jump_command(char command) {
    return command == 'w' || command == 'a' ||
           command == 's' || command == 'd' ||
           command == 'R';
}

int is_car(enum entity entity) {
    return entity == CAR_FACING_LEFT || entity == CAR_FACING_RIGHT;
}

int is_blocking_kangaroo(enum entity entity) {
    return entity == TREE ||
           entity == WOMBAT_TUNNEL ||
           entity == CAR_FACING_LEFT ||
           entity == CAR_FACING_RIGHT;
}

void print_loss_and_exit(
    struct tile board[ROWS][COLS],
    int player_row,
    int player_col,
    int score,
    int target_score,
    int *is_shocked,
    int turns_taken,
    int step_count,
    int coins_collected
) {
    print_board(
        board,
        player_row,
        player_col,
        score,
        target_score,
        is_shocked
    );
    print_game_statistics(
        turns_taken,
        step_count,
        coins_collected,
        score
    );
    print_game_lost();
}

//big ones:
void setup_player_position(int *row, int *col) {
    int valid = 0;
    printf("============== Setup Phase ==============\n");
    while (valid == 0) {
        printf("Enter the starting position: ");
        scanf("%d %d", row, col);
        if (is_on_board(*row, *col)) {
            valid = 1;
        } else {
            printf("Penny the Chicken cannot start here!\n");
        }
    }
}

void setup_startup_commands(struct tile board[ROWS][COLS], 
    int player_row, 
    int player_col, 
    int *target_score,
    int *driving_mode,
    int *scrolling_mode
) {
    char command;
    int row;
    int col;
    char direction;
    char is_letter_t;
    int row_1;
    int col_1;
    int row_2;
    int col_2;
    int number_of_tunnels = 0;

    printf("Enter setup commands:\n");

    while (1) {
        if (scanf(" %c", &command) != 1) break;
        if (command == 'e') break;
        if (command == 'd') {
            *driving_mode = 1;
            break;
        }
        if (command == 's') {
            *scrolling_mode = 1;
            *driving_mode = 1;
            break;
        }
        if (command == 't' || command == 'c') {
            scanf("%d %d", &row, &col);
            if (!is_on_board(row, col)) {
                printf("Invalid location: position is not on map!\n");
                continue;
            }            
            if (is_player_position(row, col, player_row, player_col) ||
                !is_empty_tile(board, row, col)) {
                printf("Invalid location: tile is occupied!\n");
                continue;
            }
            if (command == 't') {
                board[row][col].entity = TREE;
            } else {
                board[row][col].entity = COIN;
                board[row][col].original_coin = 1;
            }
        } else if (command == 'k') {
            scanf("%d %d", &row, &col);
            if (!is_on_board(row, col) ||
                is_player_position(row, col, player_row, player_col) ||
                !is_empty_tile(board, row, col)) {
                printf("Invalid location: kangaroos can't be here!\n");
                continue;
            }
            board[row][col].entity = KANGAROO;
        } else if (command == 'r') {
            scanf("%d", &row);
            if (row < 0 || row >= ROWS) {
                printf("Invalid location: position is not on map!\n");
                continue;
            }
            int has_tree = 0;
            int invalid = 0;
            for (int i = 0; i < COLS; i++) {
                if (row == player_row && i == player_col) {
                    invalid = 1;
                } else if (board[row][i].entity == TREE) {
                    has_tree = 1;
                } else if (board[row][i].entity != EMPTY) {
                    invalid = 1;
                }
            }
            if (invalid) {
                printf("Invalid location: road cannot be built.\n");
                continue;
            }
            if (has_tree) {
                printf("Deforesting.\n");
            }               
            for (int i = 0; i < COLS; i++) {
                board[row][i].entity = ROAD;
            }
        } else if (command == 'v') {
            scanf("%d %d %c", &row, &col, &direction);
            if (!is_on_board(row, col)) {
                printf("Invalid location: position is not on map!\n");
                continue;
            }
            if (board[row][col].entity != ROAD &&
                board[row][col].entity != HEADLIGHTS) {
                printf("Invalid location: car must be on a road.\n");
                continue;
            }
            if (direction == 'l') {
                if (is_car(board[row][col].entity)) {
                    continue;
                }
                board[row][col].entity = CAR_FACING_LEFT;
                if (col - 1 >= 0 && board[row][col - 1].entity == ROAD) {
                    board[row][col - 1].entity = HEADLIGHTS;
                }
            } else if (direction == 'r') {
                if (is_car(board[row][col].entity)) {
                    continue;
                }
                board[row][col].entity = CAR_FACING_RIGHT;
                if (col + 1 < COLS && board[row][col + 1].entity == ROAD) {
                    board[row][col + 1].entity = HEADLIGHTS;
                }
            } else {
                printf("Invalid direction!\n");
                continue;
            }
        } else if (command == 'w') {
            scanf(" %c", &is_letter_t);

            if (is_letter_t == 't') {
                scanf("%d %d %d %d", &row_1, &col_1, &row_2, &col_2);

                if (number_of_tunnels >= 10) {
                    printf("Invalid feature: too many tunnels!\n");
                    continue;
                }

                if (row_1 < 0 || row_1 >= ROWS || col_1 < 0 || col_1 >= COLS ||
                    row_2 < 0 || row_2 >= ROWS || col_2 < 0 || col_2 >= COLS) {
                    printf("Invalid location: wombat couldn't dig a tunnel here!\n");
                    continue;
                }

                if ((row_1 == player_row && col_1 == player_col) || (row_2 == player_row && col_2 == player_col) ||
                    board[row_1][col_1].entity != EMPTY ||
                    board[row_2][col_2].entity != EMPTY) {
                    printf("Invalid location: wombat couldn't dig a tunnel here!\n");
                    continue;
                }

                board[row_1][col_1].entity = WOMBAT_TUNNEL;
                board[row_2][col_2].entity = WOMBAT_TUNNEL;
                board[row_1][col_1].tunnel_id = number_of_tunnels;
                board[row_2][col_2].tunnel_id = number_of_tunnels;
                number_of_tunnels++;
            }
        } else if (command == 'x') {
            int new_target;
            scanf("%d", &new_target);
            if (new_target < 1 || new_target > 99) {
                printf("Target must be between 1 and 99 inclusive.\n");
                continue;
            }
            *target_score = new_target;
        }
    }
}

void gameplay_stage(
    struct tile board[ROWS][COLS], 
    int *player_row, 
    int *player_col, 
    int *score, 
    int *target_score,
    int *is_shocked,
    int driving_mode,
    int scrolling_mode
) {
    char command;
    int turns_taken = 0;
    int step_count = 0;
    int coins_collected = 0;
    int riding_kangaroo = 0;
    int next_jump_distance = 2;

    while (1) {
        if (scanf(" %c", &command) != 1) {
            break;
        }
        if (command == 'q') {
            printf("============= Quitting Game =============\n");
            break;
        }

        int moved_up_for_scroll = 0;
        int row_zero_scroll = 0;
        int move_row = 0;
        int move_col = 0;
        int previous_row = *player_row;
        int previous_col = *player_col;
        int jump_distance = 0;
        int scrolls_to_do = 0;

        if (riding_kangaroo == 1 && is_kangaroo_jump_command(command)) {
            jump_distance = next_jump_distance;
            if (next_jump_distance == 2) {
                next_jump_distance = 3;
            } else {
                next_jump_distance = 2;
            }
        }        

        if (command == 'w') {
            turns_taken++;

            if (riding_kangaroo == 1) {
                int destination_row = *player_row - jump_distance;

                if (destination_row < 0 ||
                    is_blocking_kangaroo(
                        board[destination_row][*player_col].entity
                    )) {
                    riding_kangaroo = 0;
                    move_row = 0;
                    move_col = 0;
                } else {
                    *player_row = destination_row;
                    step_count++;
                    if (scrolling_mode == 1) {
                        scrolls_to_do = jump_distance;
                    }
                }
            } else if (scrolling_mode == 0) {
                if (*player_row > 0 && board[*player_row - 1][*player_col].entity != TREE) {
                    *player_row = *player_row - 1;
                    step_count++;
                    move_row = -1;
                    move_col = 0;
                }
            } else {
                if (*player_row == 0) {
                    row_zero_scroll = 1;
                    move_row = -1;
                    move_col = 0;
                } else if (board[*player_row - 1][*player_col].entity != TREE) {
                    if (*player_row <= 6) {
                        moved_up_for_scroll = 1;
                    }
                    *player_row = *player_row - 1;
                    step_count++;
                    move_row = -1;
                    move_col = 0;
                }
            }
        } else if (command == 'a') {
            turns_taken++;
            if (riding_kangaroo == 1) {
                int destination_col = *player_col - jump_distance;

                if (destination_col < 0 ||
                    is_blocking_kangaroo(
                        board[*player_row][destination_col].entity
                    )) {
                    riding_kangaroo = 0;
                    move_row = 0;
                    move_col = 0;
                } else {
                    *player_col = destination_col;
                    step_count++;
                }
            } else if (*player_col > 0 && board[*player_row][*player_col - 1].entity != TREE) {
                *player_col = *player_col - 1;
                step_count++;
                move_row = 0;
                move_col = -1;
            }
        } else if (command == 's') {
            turns_taken++;
            if (riding_kangaroo == 1) {
                int destination_row = *player_row + jump_distance;

                if (destination_row >= ROWS ||
                    is_blocking_kangaroo(
                        board[destination_row][*player_col].entity
                    )) {
                    riding_kangaroo = 0;
                    move_row = 0;
                    move_col = 0;
                } else {
                    *player_row = destination_row;
                    step_count++;
                }
            } else if (*player_row < ROWS - 1 && board[*player_row + 1][*player_col].entity != TREE) {
                *player_row = *player_row + 1;
                step_count++;
                move_row = 1;
                move_col = 0;
            }
        } else if (command == 'd') {
            turns_taken++;
            if (riding_kangaroo == 1) {
                int destination_col = *player_col + jump_distance;

                if (destination_col >= COLS ||
                    is_blocking_kangaroo(
                        board[*player_row][destination_col].entity
                    )) {
                    riding_kangaroo = 0;
                    move_row = 0;
                    move_col = 0;
                } else {
                    *player_col = destination_col;
                    step_count++;
                }
            } else if (*player_col < COLS - 1 && board[*player_row][*player_col + 1].entity != TREE) {
                *player_col = *player_col + 1;
                step_count++;
                move_row = 0;
                move_col = 1;
            }
        } else if (command == 'R') {
            turns_taken++;
        } else if (command == 'p') {
            print_game_statistics(turns_taken, step_count, coins_collected, *score);
            continue;
        }

        if (board[*player_row][*player_col].entity == WOMBAT_TUNNEL) {
            int tunnel_id = board[*player_row][*player_col].tunnel_id;
            int exit_row = -1;
            int exit_col = -1;

            for (int row = 0; row < ROWS; row++) {
                for (int col = 0; col < COLS; col++) {
                    if (!(row == *player_row && col == *player_col) &&
                        board[row][col].entity == WOMBAT_TUNNEL &&
                        board[row][col].tunnel_id == tunnel_id) {
                        exit_row = row;
                        exit_col = col;
                    }
                }
            }

            int destination_row = exit_row + move_row;
            int destination_col = exit_col + move_col;

            if (destination_row < 0 || destination_row >= ROWS || destination_col < 0 || destination_col >= COLS || board[destination_row][destination_col].entity == TREE) {
                *player_row = previous_row;
                *player_col = previous_col;
                step_count--;
                move_row = 0;
                move_col = 0;
                moved_up_for_scroll = 0;
                row_zero_scroll = 0;
            } else {
                *player_row = destination_row;
                *player_col = destination_col;
                if (scrolling_mode == 1 && move_row == -1 && *player_row > 6) {
                    moved_up_for_scroll = 0;
                }                
            }
        }

        enum entity current = board[*player_row][*player_col].entity;
        if (current == KANGAROO) {
            riding_kangaroo = 1;
            board[*player_row][*player_col].entity = EMPTY;
            current = EMPTY;
        }        

        if (current == COIN) {
            *score = *score + 5;
            coins_collected++;
            board[*player_row][*player_col].entity = EMPTY;
            current = board[*player_row][*player_col].entity;
        }

        if (is_car(current)) {
            if (riding_kangaroo == 1) {
                *is_shocked = 2;
            } else {
                *is_shocked = 1;
            }
            print_board(
                board,
                *player_row,
                *player_col,
                *score,
                *target_score,
                is_shocked
            );
            print_game_statistics(turns_taken, step_count, coins_collected, *score);
            print_game_lost();
            return;
        }

        if (driving_mode == 1) {
            move_cars(board);
        }

        current = board[*player_row][*player_col].entity;
        if (current == KANGAROO) {
            riding_kangaroo = 1;
            board[*player_row][*player_col].entity = EMPTY;
            current = EMPTY;
        }

        if (riding_kangaroo == 1) {
            *is_shocked = 2;
        } else if (current == HEADLIGHTS || current == CAR_FACING_LEFT ||
                   current == CAR_FACING_RIGHT) {
            *is_shocked = 1;
        } else {
            *is_shocked = 0;
        }

        if (is_car(current)) {
            print_board(
                board,
                *player_row,
                *player_col,
                *score,
                *target_score,
                is_shocked
            );
            print_game_statistics(turns_taken, step_count, coins_collected, *score);
            print_game_lost();
            return;
        }

        if (scrolls_to_do > 0) {
            for (int i = 0; i < scrolls_to_do; i++) {
                scroll_board(board);
                *player_row = *player_row + 1;
            }
        } else if (scrolling_mode == 1) {
            if (moved_up_for_scroll) {
                scroll_board(board);
                *player_row = *player_row + 1;
            } else if (row_zero_scroll) {
                if (board[ROWS - 1][*player_col].entity != TREE) {
                    scroll_board(board);
                    *player_row = 0;
                    step_count++;
                }
            }
        }

        if (board[*player_row][*player_col].entity == WOMBAT_TUNNEL) {
            int tunnel_id = board[*player_row][*player_col].tunnel_id;
            int exit_row = -1;
            int exit_col = -1;

            for (int row = 0; row < ROWS; row++) {
                for (int col = 0; col < COLS; col++) {
                    if (!(row == *player_row && col == *player_col) &&
                        board[row][col].entity == WOMBAT_TUNNEL &&
                        board[row][col].tunnel_id == tunnel_id) {
                        exit_row = row;
                        exit_col = col;
                    }
                }
            }

            int destination_row = exit_row + move_row;
            int destination_col = exit_col + move_col;

            if (destination_row < 0 || destination_row >= ROWS ||
                destination_col < 0 || destination_col >= COLS ||
                board[destination_row][destination_col].entity == TREE) {
                *player_row = previous_row;
                *player_col = previous_col;
                step_count--;
                move_row = 0;
                move_col = 0;
                moved_up_for_scroll = 0;
                row_zero_scroll = 0;
            } else {
                *player_row = destination_row;
                *player_col = destination_col;
            }
        }
        
        current = board[*player_row][*player_col].entity;

        if (current == COIN) {
            *score = *score + 5;
            coins_collected++;
            board[*player_row][*player_col].entity = EMPTY;
            current = board[*player_row][*player_col].entity;
        }

        if (is_car(current)) {
            if (riding_kangaroo == 1) {
                *is_shocked = 2;
            } else {
                *is_shocked = 1;
            }
            print_board(
                board,
                *player_row,
                *player_col,
                *score,
                *target_score,
                is_shocked
            );
            print_game_statistics(turns_taken, step_count, coins_collected, *score);
            print_game_lost();
            return;
        }        

        if (*score >= *target_score) {
            print_board(
                board,
                *player_row,
                *player_col,
                *score,
                *target_score,
                is_shocked
            );
            print_game_statistics(turns_taken, step_count, coins_collected, *score);
            print_game_won();
            return;
        }

        print_board(
            board,
            *player_row,
            *player_col,
            *score,
            *target_score,
            is_shocked
        );
    }
}

void move_cars(struct tile board[ROWS][COLS]) {
    enum entity original_cars[ROWS][COLS];

    for (int row = 0; row < ROWS; row++) {
        for (int col = 0; col < COLS; col++) {
            if (board[row][col].entity == CAR_FACING_RIGHT ||
                board[row][col].entity == CAR_FACING_LEFT) {
                original_cars[row][col] = board[row][col].entity;
            } else {
                original_cars[row][col] = EMPTY;
            }
        }
    }

    for (int row = 0; row < ROWS; row++) {
        for (int col = 0; col < COLS; col++) {
            if (board[row][col].entity == HEADLIGHTS) {
                board[row][col].entity = ROAD;
            }
        }
    }

    for (int row = 0; row < ROWS; row++) {
        for (int col = COLS - 1; col >= 0; col--) {
            if (original_cars[row][col] == CAR_FACING_RIGHT) {
                int dest = col + 1;

                if (dest < COLS && board[row][dest].entity == ROAD) {
                    board[row][dest].entity = CAR_FACING_RIGHT;
                    board[row][col].entity = ROAD;
                } else {
                    board[row][col].entity = CAR_FACING_LEFT;
                }
            }
        }
    }

    for (int row = 0; row < ROWS; row++) {
        for (int col = 0; col < COLS; col++) {
            if (original_cars[row][col] == CAR_FACING_LEFT) {
                int dest = col - 1;

                if (dest >= 0 && board[row][dest].entity == ROAD) {
                    board[row][dest].entity = CAR_FACING_LEFT;
                    board[row][col].entity = ROAD;
                } else {
                    board[row][col].entity = CAR_FACING_RIGHT;
                }
            }
        }
    }

    for (int row = 0; row < ROWS; row++) {
        for (int col = 0; col < COLS; col++) {
            if (board[row][col].entity == CAR_FACING_RIGHT) {
                if (col + 1 < COLS && board[row][col + 1].entity == ROAD) {
                    board[row][col + 1].entity = HEADLIGHTS;
                }
            } else if (board[row][col].entity == CAR_FACING_LEFT) {
                if (col - 1 >= 0 && board[row][col - 1].entity == ROAD) {
                    board[row][col - 1].entity = HEADLIGHTS;
                }
            }
        }
    }
}
void restore_top_row(struct tile board[ROWS][COLS]) {
    for (int col = 0; col < COLS; col++) {
        if (board[0][col].original_coin == 1 && board[0][col].entity == EMPTY) {
            board[0][col].entity = COIN;
        }
    }
}

void scroll_board(struct tile board[ROWS][COLS]) {
    struct tile temp[COLS];
    for (int col = 0; col < COLS; col++) {
        temp[col] = board[ROWS - 1][col];
    }
    for (int row = ROWS - 1; row > 0; row--) {
        for (int col = 0; col < COLS; col++) {
            board[row][col] = board[row - 1][col];
        }
    }
    for (int col = 0; col < COLS; col++) {
        board[0][col] = temp[col];
    }
    restore_top_row(board);
}

// =============================================================================
// Provided Helper Functions
// =============================================================================

// Prints the game's welcome banner
void print_welcome(void) {
    printf(
        "_________________________________________   \n"
        "   \\\\                               \\\\  \n"
        "   (o>   !!    Welcome to    !!     (o>     \n"
        "\\\\_//)         CS CHICKEN        \\\\_//) \n"
        " \\_/_)                            \\_/_)   \n"
        "  _|_                              _|_      \n"
        "_________________________________________   \n\n"
    );
}

// Given a 2D board array, initialises all tile entities to EMPTY.
void initialise_board(struct tile board[ROWS][COLS]) {
    for (int row = 0; row < ROWS; row++) {
        for (int col = 0; col < COLS; col++) {
            board[row][col].entity = EMPTY;
            board[row][col].original_coin = 0;
            board[row][col].tunnel_id = -1;
        }
    }
}

// Prints the game board, showing the player's position, current score and target score
void print_board(
    struct tile board[ROWS][COLS], 
    int player_row, 
    int player_col,
    int curr_score,
    int target_score,
    int *is_shocked
) {
    print_board_line();
    printf("|          C S   C H I C K E N          |\n");
    print_board_line();
    
    for (int row = 0; row < ROWS; row++) {
        for (int col = 0; col < COLS; col++) {
            printf("|");
            if (row == player_row && col == player_col) {
                if (*is_shocked == 2) {
                    printf("_B^");
                } else if (*is_shocked == 1) {
                    printf("0_0");
                } else {
                    printf("^_^");
                }
            } else if (board[row][col].entity == EMPTY) {
                printf("   ");
            } else if (board[row][col].entity == COIN) {
                printf(" c ");
            } else if (board[row][col].entity == TREE) {
                printf(" T ");
            } else if (board[row][col].entity == ROAD) {
                printf("___");
            } else if (board[row][col].entity == CAR_FACING_RIGHT) {
                printf("[_0");
            } else if (board[row][col].entity == CAR_FACING_LEFT) {
                printf("0_]");
            } else if (board[row][col].entity == HEADLIGHTS) {
                printf("###");
            } else if (board[row][col].entity == KANGAROO) {
                printf("_b^");
            } else if (board[row][col].entity == WOMBAT_TUNNEL) {
                printf("(%d)", board[row][col].tunnel_id);
            } else {
                printf("   ");
            }
        }
        printf("|\n");
        print_board_line();
    }

    print_board_footer(curr_score, target_score);
    printf("\n");
}

// Helper function to print statistics. 
// Use in Stage 2.3.
void print_game_statistics(
    int turns_taken, 
    int step_count, 
    int coins, 
    int score
) {
    printf( 
        "============ Game Statistics ============\n"
        "          Turns taken: %d\n"
        "           Step count: %d\n"
        "      Coins Collected: %d\n"
        "                Score: %d\n",
        turns_taken, step_count, coins, score
    );
}

// Helper function to print the banner for when the game is won. 
// Use in Stage 2.4
void print_game_won(void) {
    printf(
        "_________________________________________   \n"
        "       Penny the Chicken is happy!          \n"
        "   \\\\                               \\\\  \n"
        "   (o>   !!    Thank  you    !!     (o>     \n"
        "\\\\_//)        for playing!       \\\\_//) \n"
        " \\_/_)                            \\_/_)   \n"
        "  _|_                              _|_      \n"
        "_________________________________________   \n\n"
    );
}

// Helper function to print the banner for when the game is won. 
// Use in Stage 3.1
void print_game_lost(void) {
    printf(
        "_________________________________________   \n"
        "   \\\\                               \\\\  \n"
        "   (x>    !!      Game      !!      (x>     \n"
        "\\\\_//)             Over          \\\\_//) \n"
        " \\_/_)                            \\_/_)   \n"
        "  _|_                              _|_      \n"
        "_________________________________________   \n\n"
    );
}

///////////////////////////////////////////////////////////////////////////////
// Additional Provided Functions
///////////////////////////////////////////////////////////////////////////////

// You don't need to use any of these, or understand howc they work!
// We use them to implement some of the provided helper functions.

// Helper function for print_board(). 
void print_board_footer(int curr_score, int target_score) {
    printf("Score: %-3d                     ", curr_score);
    printf("Target: %-2d", target_score);
}

// Helper function for print_board(). 
void print_board_line(void) {
    printf("+");
    for (int col = 0; col < COLS; col++) {
        printf("---+");
    }
    printf("\n");
}
Editor is loading...
Leave a Comment