diff options
author | scratko <m@scratko.xyz> | 2024-04-16 02:37:12 +0300 |
---|---|---|
committer | scratko <m@scratko.xyz> | 2024-04-16 02:37:12 +0300 |
commit | 194f71c150eb9ee696acca17176092e8b0ce6e4f (patch) | |
tree | feff177d5ffca319a71db4848f653b7ea7ae17c6 /field.c | |
parent | e42ac35110b1819bf9762fbb4504ab920a17e207 (diff) | |
download | pacman-194f71c150eb9ee696acca17176092e8b0ce6e4f.tar.gz pacman-194f71c150eb9ee696acca17176092e8b0ce6e4f.tar.bz2 pacman-194f71c150eb9ee696acca17176092e8b0ce6e4f.zip |
Scoring system
Pacman's starting position doesn't contain a coin.
Fixed an error in field_has_energizer().
The field prints the number of pacman lives and the score.
All coin checks are moved to the field.c file.
Restart is replaced by initialization of starting parameters.
The final stage contains the game results screens.
Queue clearing is combined with field clearing.
Get_out_stage moved to struct mode_type.
Diffstat (limited to 'field.c')
-rw-r--r-- | field.c | 85 |
1 files changed, 66 insertions, 19 deletions
@@ -27,13 +27,14 @@ static const char field_sample[field_height][field_width] = { {"/1....3..2..1//1..2..3....1/"}, {"/.////./////.//./////.////./"}, {"/*////./////.//./////.////*/"}, - {"/1.1//2..2..y..y..2..2//1.1/"}, + {"/1.1//2..2..y. y..2..2//1.1/"}, {"///.//.//.////////.//.//.///"}, {"///.//.//.////////.//.//.///"}, {"/1.2..1//1..1//1..1//1..2.1/"}, {"/.//////////.//.//////////./"}, {"/1..........2..2..........1/"}, {"////////////////////////////"}, + {" C C C Score: "} }; static void copy_field(game_space field) @@ -59,7 +60,7 @@ void clear_field(game_space field) field = NULL; } -int field_has_coin(int x, int y) +static int field_has_coin(int x, int y) { return !((x == 9 && y == 12)|| (x == 18 && y == 12) || (x == 18 && y == 14) || (x == 9 && y == 15) || @@ -67,14 +68,33 @@ int field_has_coin(int x, int y) (x == 13 && y == 12) || (x == 14 && y == 12)); } -int field_has_energizer(const game_space field, int x, int y) +static int yellow_block_contains_coin(int x, int y) { - return field[y][x] = energizer; + return (x == 12 && y == 22) || (x == 15 && y == 22); } -static int yellow_block_contains_coin(int x, int y) +static int is_coin_symbol(int symbol, int x, int y) { - return (x == 12 && y == 22) || (x == 15 && y == 22); + return + symbol == coin || symbol == energizer || symbol == one_path || + symbol == two_paths || symbol == three_paths || + (symbol == yellow_block && yellow_block_contains_coin(x, y)); +} + +int check_coin_for_pac(game_space field, struct coordinates position, + struct queue *eaten_coins) +{ + int x, y; + x = position.x; + y = position.y; + return + is_coin_symbol(field[y][x], x, y) && field_has_coin(x, y) && + !queue_consists_point(eaten_coins, position); +} + +int field_has_energizer(const game_space field, int x, int y) +{ + return field[y][x] == energizer; } void print_field(game_space field) @@ -86,27 +106,19 @@ void print_field(game_space field) for(j = 0; j < field_width; ++j) { symbol = field[i][j]; move(i, j); + if(is_coin_symbol(symbol, j, i) && field_has_coin(j, i)) { + symbol == energizer ? addch('*') : addch('.'); + continue; + } switch(symbol) { case one_path: case two_paths: - case three_paths: - if(field_has_coin(j, i)) - addch('.'); - else - addch(' '); - break; case yellow_block: - if(yellow_block_contains_coin(j, i)) - addch('.'); - else - addch(' '); + addch(' '); break; case block: addch('/'); break; - case coin: - addch('.'); - break; case energizer: addch('*'); break; @@ -117,6 +129,8 @@ void print_field(game_space field) addch(' '); break; } + if(i == field_height-1) + addch(symbol); refresh(); } } @@ -143,6 +157,13 @@ void display_ghosts_on_field(struct ghost_type *red_ghost, ghost_char); } +void display_score(int value) +{ + move(field_height-1, 25); + printw("%d", value); + refresh(); +} + void clear_or_revert_symbol(const game_space field, struct coordinates position, enum select_character character, struct queue *eaten_coins) @@ -263,3 +284,29 @@ int is_equal_points(struct coordinates first_point, struct coordinates y2 = second_point.y; return x1 == x2 && y1 == y2; } + +void erase_life(int value) +{ + enum { + two_lives_left = 2, + one_life_left = 1, + no_lives_left = 0, + gap = 2, + three_lives_x = 5 + }; + int x, y; + y = field_height - 1; + switch(value) { + case two_lives_left: + x = three_lives_x; + break; + case one_life_left: + x = three_lives_x - gap; + break; + case no_lives_left: + x = three_lives_x - gap * 2; + } + move(y, x); + addch(' '); + refresh(); +} |