-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer_loop.c
52 lines (47 loc) · 1.3 KB
/
player_loop.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
** EPITECH PROJECT, 2020
** game loop
** File description:
** game loop of the matchstick game
*/
#include "header.h"
int player_loop(game_t *game)
{
my_putstr("\nYour turn:\n");
while (game->match_input > game->pick || game->match_input == 0
|| game->match_input > game->match_nbr[game->line_input]) {
if (user_turn(game) == 1)
return (0);
get_matches_nbr(game);
if (game->match_input > game->pick)
match_max_display(game);
if (game->match_input <= game->pick &&
game->match_input > game->match_nbr[game->line_input])
not_enough_match_display(game);
}
matches_removed_by_player_display(game);
remove_match(game);
get_matches_nbr(game);
game->turn--;
if (game->end == 0)
return (0);
return (1);
}
int matches_removed_by_player_display(game_t *game)
{
my_putstr("Player removed ");
my_put_nbr(game->match_input);
my_putstr(" match(es) from line ");
my_put_nbr(game->line_input);
my_putchar('\n');
}
int not_enough_match_display(game_t *game)
{
my_putstr("Error: not enough matches on this line\n");
}
int match_max_display(game_t *game)
{
my_putstr("Error: you cannot remove more than ");
my_put_nbr(game->pick);
my_putstr(" matches per turn\n");
}