Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions pacman_windows/pacman_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ int collision_with_obstacle(int x_obj, int y_obj);
void collect_eat_pellets(int x, int y);
bool game_over(game_object_t pacman, game_object_t ghost);
long getMillis_sinceMidnight();
void reset_cli();
void hide_cursor();

int main(void) {
hide_cursor();

// struct for the position of the pacman
game_object_t pacman;
Expand Down Expand Up @@ -142,9 +145,7 @@ int main(void) {
}

void print_screen_memory_to_cli() {
// system("@cls||clear");
system("cls"); // use this in windows
// printf("\e[1;1H\e[2J"); // for linux use the regex
reset_cli();

for (int y_i = 0; y_i < Y_DIM; y_i++) {
for (int x_i = 0; x_i < X_DIM; x_i++) {
Expand Down Expand Up @@ -367,3 +368,22 @@ long getMillis_sinceMidnight() {
return time_ms;
}

// clear functions
void reset_cli() {
#ifdef _WIN32
COORD cursorPosition = { 0,0 };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), cursorPosition);
#elif __linux__
printf("\e[1;1H\e[2J"); // for linux use the regex
#endif
}

// hide cli cursor
void hide_cursor() {
#ifdef _WIN32
CONSOLE_CURSOR_INFO info;
info.dwSize = 100;
info.bVisible = false;
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
#endif
}