Beispiel #1
0
int			player(t_gboard *p4, char *cl, int player)
{
	int		move;
	int		win;

	move = -1;
	while (move == -1)
	{
		ft_putendl("Your turn you mud !");
		if ((move = ft_player()) == -1)
		{
			ft_putstr(cl);
			p4->error = COL_STR;
		}
		else
		{
			ft_putstr(cl);
			move = ft_play(p4, move, player);
		}
		print_board(p4);
		if (move != -1)
			win = check_win(p4, player);
	}
	return (win);
}
static int			st_get_choice(t_ctx *ctx)
{
	char			buf[BUF_LEN + 1];

	ft_raw_term();
	ft_place_cursor(ctx);
	while (1)
	{
		ft_bzero(buf, BUF_LEN + 1);
		if (-1 == read(STDIN_FILENO, buf, BUF_LEN))
			return (ERR);
		if (0 == ft_strcmp(buf, K_ENTER) && !ctx->grid[0][ctx->arrow])
		{
			ft_reset_term();
			ctx->player_last = ctx->arrow;
			return (ft_play(ctx, ctx->player_last));
		}
		if (0 == ft_strcmp(buf, K_QUIT))
		{
			tputs(tgetstr("cl", NULL), 1, ft_putput);
			ft_reset_term();
			return (ERR);
		}
		ft_treat_key(buf);
	}
	ft_reset_term();
	return (OK);
}