-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ArkadySK/main-menu
Added Main Menu
- Loading branch information
Showing
5 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include "menu.h" | ||
#include "utils.h" | ||
|
||
char display_menu(void) { | ||
clear_screen(); | ||
|
||
printf("\n"); | ||
printf("*********************************\n"); | ||
printf("* BATTLESHIP *\n"); | ||
printf("*********************************\n"); | ||
printf("\n"); | ||
printf("Welcome! Choose an activity:\n"); | ||
printf("\n"); | ||
printf("[1] Play against Computer\n"); | ||
printf("[2] Play against Human\n"); | ||
printf("[q] Quit\n"); | ||
printf("\n"); | ||
printf("Your choice: "); | ||
|
||
// Read single character | ||
char choice = getchar(); | ||
while (getchar() != '\n'); | ||
|
||
return choice; | ||
} | ||
|
||
int handle_menu(void) { | ||
char choice; | ||
int running = 1; | ||
|
||
while (running) { | ||
choice = display_menu(); | ||
switch (choice) { | ||
case '1': | ||
return 1; | ||
case '2': | ||
return 2; | ||
case 'q': | ||
case 'Q': | ||
return 0; | ||
} | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
char display_menu(void); | ||
int handle_menu(void); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
//TODO Adam: is it needed? | ||
#include <stdio.h> | ||
|
||
// Clears the screen using ANSI escape sequence | ||
void clear_screen() { | ||
// \033 - represents the ASCII escape character | ||
// \033[H - Moves the cursor to the "home" position (top-left corner of the terminal) | ||
printf("\033[2J\033[H"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Clears the screen using ANSI escape sequence | ||
void clear_screen(void); |