Browse Source
Merge branch 'nav' into 'main'
Merge branch 'nav' into 'main'
Nav See merge request fdai7361/projekt!17remotes/origin/fdai7372-main-patch-93194
fdai7361
2 years ago
18 changed files with 260 additions and 186 deletions
-
6src/c/commands.c
-
3src/c/helper.h
-
2src/c/items.c
-
23src/c/main.c
-
2src/c/map.h
-
43src/c/nav_helper.c
-
13src/c/nav_helper.h
-
61src/c/print_helper.c
-
4src/c/print_helper.h
-
223src/c/shop.c
-
38src/c/utils.c
-
8src/c/utils.h
-
1src/content/game_instructions.txt
-
5test/c/test_commands.c
-
3test/c/test_items.c
-
3test/c/test_map.c
-
3test/c/test_player.c
-
5test/c/test_utils.c
@ -1,43 +0,0 @@ |
|||||
//bibs |
|
||||
#include <stdio.h> |
|
||||
#include <stdlib.h> |
|
||||
#include <stdbool.h> |
|
||||
|
|
||||
//headers |
|
||||
#include "nav_helper.h" |
|
||||
|
|
||||
bool startsWith(const char *a, const char *b) |
|
||||
{ |
|
||||
if (strncmp(a, b, strlen(b)) == 0) |
|
||||
return 1; |
|
||||
return 0; |
|
||||
}; |
|
||||
|
|
||||
FILE *getStream(char *filePath) |
|
||||
{ |
|
||||
FILE *stream; |
|
||||
stream = fopen(filePath, "r"); |
|
||||
if (stream == NULL) |
|
||||
{ |
|
||||
printf("ERROR: couldn't open or find file: %s !\n", filePath); |
|
||||
exit(EXIT_FAILURE); // exit |
|
||||
} |
|
||||
|
|
||||
return stream; |
|
||||
} |
|
||||
|
|
||||
void printStreamLines(FILE *stream){ |
|
||||
|
|
||||
char *line = NULL; |
|
||||
size_t len = 0; |
|
||||
ssize_t read; |
|
||||
|
|
||||
/* print line by line from file */ |
|
||||
while ((read = getline(&line, &len, stream)) != -1) |
|
||||
{ |
|
||||
// printf("Retrieved line of length %u :\n", read); |
|
||||
printf("%s", line); |
|
||||
} |
|
||||
|
|
||||
free(line); /* Deallocate allocated memory */ |
|
||||
} |
|
@ -1,13 +0,0 @@ |
|||||
#ifndef NAV_HELPER_H |
|
||||
#define NAV_HELPER_H |
|
||||
|
|
||||
#include <stdio.h> |
|
||||
#include <stdlib.h> |
|
||||
#include <stdbool.h> |
|
||||
#include <string.h> |
|
||||
|
|
||||
bool startsWith(const char *a, const char *b); |
|
||||
FILE *getStream(char *filePath); |
|
||||
void printStreamLines(FILE *stream); |
|
||||
|
|
||||
#endif |
|
@ -1,7 +1,11 @@ |
|||||
#ifndef PRINT_HELPER_H |
#ifndef PRINT_HELPER_H |
||||
#define PRINT_HELPER_H |
#define PRINT_HELPER_H |
||||
|
|
||||
|
#include "map.h" |
||||
|
|
||||
void printHeader(char *header); |
void printHeader(char *header); |
||||
void printItem(char *header, char *item, int itemID, int itemPrice); |
void printItem(char *header, char *item, int itemID, int itemPrice); |
||||
|
|
||||
|
void printRoomStatus(char *moveMessage, Room currentRoom, int playerPosition); |
||||
|
|
||||
#endif |
#endif |
@ -1,7 +1,15 @@ |
|||||
#ifndef UTILS_H |
#ifndef UTILS_H |
||||
#define UTILS_H |
#define UTILS_H |
||||
|
|
||||
|
#include <stdio.h> |
||||
|
#include <stdlib.h> |
||||
|
#include <stdbool.h> |
||||
|
#include <string.h> |
||||
|
|
||||
int randomIntRange(int min, int max); |
int randomIntRange(int min, int max); |
||||
int map(int x, int in_min, int in_max, int out_min, int out_max); |
int map(int x, int in_min, int in_max, int out_min, int out_max); |
||||
|
bool startsWith(const char *a, const char *b); |
||||
|
FILE *getStream(char *filePath); |
||||
|
void printStreamLines(FILE *stream); |
||||
|
|
||||
#endif |
#endif |
Write
Preview
Loading…
Cancel
Save
Reference in new issue