Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create a simple C Program game that implements using these griddisplay files and also create a makefile that will run with the griddisplay and the
Create a simple C Program game that implements using these griddisplay files and also create a makefile that will run with the griddisplay and the game. and if possible display a snapshot of the program that excuted. HELP PLEASE !
Griddisplay.c:
#include#include #include "griddisplay.h" #define NUM_PRINT_LINES 10 #define MAX_PRINT_LINE_LENGTH 120 #define TITLE "Grid Display" #define DEBUG void update_display_selected_clear_title(const char *, char *, int, int, int, int, int); /* * Function to set up the display. */ void init_display() { initscr(); cbreak(); noecho(); nl(); } /* * Function to close out the display. */ void close_display() { endwin(); } /* * Function to update the display with the given char array * Param: num_rows - the number of rows in the display * num_cols - the number of columns in the display */ void update_display(char grid[], int num_rows, int num_cols) { update_display_title(TITLE, grid, num_rows, num_cols); } void update_display_selected(char grid[], int num_rows, int num_cols, int selected_row, int selected_col) { update_display_title_selected(TITLE, grid, num_rows, num_cols, selected_row, selected_col); } void update_display_title(const char *title, char grid[], int num_rows, int num_cols) { update_display_selected_clear_title(title, grid, num_rows, num_cols, -1, -1, FALSE); } void update_display_title_selected(const char *title, char grid[], int num_rows, int num_cols, int selected_row, int selected_col) { update_display_selected_clear_title(title, grid, num_rows, num_cols, selected_row, selected_col, TRUE); } // Helper function void update_display_selected_clear_title(const char *title, char grid[], int num_rows, int num_cols, int selected_row, int selected_col, int clear) { int row, col, row_i, col_i; int max_row, max_col; getmaxyx(stdscr, max_row, max_col); if(clear) { clear(); } #ifdef DEBUG mvprintw(0,0, "max_row=%d, max_col=%d", max_row, max_col); #endif // Print Header mvprintw(max_row - (NUM_PRINT_LINES + num_rows + 2), (max_col - strlen(title))/2, title); row = max_row - (NUM_PRINT_LINES + num_rows + 1); col = (max_col - 3*num_cols)/2; for(row_i=0; row_i < num_rows; row_i++) { for(col_i=0; col_i < num_cols; col_i++) { if(grid[row_i*num_cols+col_i] != '\0') { if(row_i == selected_row && col_i == selected_col) { mvprintw(row + row_i, col + (3*col_i), "|%c|", grid[row_i*num_cols+col_i]); } else { mvprintw(row + row_i, col + (3*col_i), " %c ", grid[row_i*num_cols+col_i]); } } } } move(row + num_rows-1, col + 3*(num_cols)); refresh(); } /* * Function to print a message in the display area, similar to printf * Param: line_num - which line to write on. Ten lines available, 0-9 * format, ... - the rest of the arguments are exactly like printf */ int display_print(int line_num, const char *format, ...) { char string[MAX_PRINT_LINE_LENGTH]; int max_row, max_col; int ret_val; va_list argp; getmaxyx(stdscr, max_row, max_col); va_start(argp, format); ret_val = vsprintf(string, format, argp); va_end(argp); /* * Not sure if this will clear existing line... * Certain calls to update_display will clear, but maybe not anymore... */ mvprintw(max_row - NUM_PRINT_LINES + line_num, 0, "%s", string); refresh(); return ret_val; }
Griddisplay.h:
#include#include /* * Function to set up the display. */ void init_display(); /* * Function to close out the display. */ void close_display(); /* * Function to update the display with the given char array * Param: num_rows - the number of rows in the display * num_cols - the number of columns in the display */ void update_display(char grid[], int num_rows, int num_cols); void update_display_selected(char grid[], int num_rows, int num_cols, int selected_row, int selected_col); // And with a string title as the first argument void update_display_title(const char *title, char grid[], int num_rows, int num_cols); void update_display_title_selected(const char *title, char grid[], int num_rows, int num_cols, int selected_row, int selected_col); /* * Function to print a message in the display area, similar to printf * Param: line_num - which line to write on. Ten lines available, 0-9 * format, ... - the rest of the arguments are exactly like printf */ int display_print(int line_num, const char *format, ...);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started