is_player_char - 1Fr3aK2/Cub3d GitHub Wiki
๐ is_player_char
Checks whether a given character represents a valid player symbol in the game map.
โ๏ธ Parameters
| Parameter | Type | Description |
|---|---|---|
c |
char |
The character to be checked against the set of valid player characters defined in PLAYER. |
๐ Returns
| Return value | Description |
|---|---|
true |
The character c matches one of the valid player characters. |
false |
The character c does not match any valid player characters. |
๐ Description
The is_player_char function iterates through the predefined PLAYER character array to determine if the input character corresponds to a playerโs starting position on the map. It is typically used during map parsing to identify the playerโs initial location and orientation.
Step-by-step process:
- Initialize index โ Starts at
i = 0. - Iterate through
PLAYERarray โ Loops over each character in thePLAYERarray. - Check for match โ If
cequalsPLAYER[i], immediately returntrue. - Continue iteration โ If no match is found, increment
iand check the next character. - Return
falseif not found โ If the loop completes without finding a match, returnfalse.
This function is lightweight and ensures that only valid player characters are accepted during map validation.
๐ก Example Usage
char c = 'N';
if (is_player_char(c))
{
printf("%c is a valid player character.\n", c);
}
else
{
printf("%c is NOT a valid player character.\n", c);
}