Пример #1
0
/*
** Decremente le nb de joueur de la case
** Annule incantation
** Supprime le pcli de l'ancienne case
** Bouge
** Incrementation du nb de joueur sur la nouvelle case
** Annule incantation
** Ajoute le pcli ds la nouvelle case
*/
void	ia_avance(t_world *world, t_cli *ia)
{
  putstr("\033[33mClient numero : ");
  print_nb(ia->numero);
  putstr(" avance\n\033[39m");
  world->map[ia->pos.y][ia->pos.x].nb_joueur -= 1;
  world->map[ia->pos.y][ia->pos.x].elevation = 0;
  remove_pcli(&(world->map[ia->pos.y][ia->pos.x].pcli), ia->pcli);
  if (ia->pos.direction % 2)
    ia->pos.y += (ia->pos.direction == NORD) ?
      (!ia->pos.y) ? world->height - 1 : -1 :
      (ia->pos.y == (world->height - 1)) ? -ia->pos.y : 1;
  else
    ia->pos.x += (ia->pos.direction == OUEST) ?
      (!ia->pos.x) ? world->width - 1 : -1 :
      (ia->pos.x == (world->width - 1)) ? -ia->pos.x : 1;
  if (world->map[ia->pos.y][ia->pos.x].elevation && world->pgui != NULL)
    gui_pie(world, ia->pos.y, ia->pos.x, '0');
  world->map[ia->pos.y][ia->pos.x].nb_joueur += 1;
  world->map[ia->pos.y][ia->pos.x].elevation = 0;
  add_pcli(&(world->map[ia->pos.y][ia->pos.x].pcli), ia->pcli);
  save_cmd(ia, MSG_OK, LEN_OK, 'W');
  if (world->pgui != NULL)
    gui_ppo_serv(world, ia);
}
Пример #2
0
void		ia_voir(t_world *world, t_cli *ia)
{
  int		i;
  t_card	pos;
  int		nb_case;

  putstr("\033[33mClient numero : ");
  print_nb(ia->numero);
  putstr(" voir\n\033[39m");
  pos.y = ia->pos.y;
  pos.x = ia->pos.x;
  pos.direction = ia->pos.direction;
  save_cmd(ia, MSG_DEB_VOIR, LEN_DEB_VOIR, 'W');
  i = 0;
  nb_case = 1;
  while (i <= ia->lvl)
    {
      look_rank(world, &pos, nb_case, ia);
      select_incr(world, &pos, nb_case + 1);
      nb_case += CASE_PER_LEVEL;
      i++;
    }
  save_cmd(ia, MSG_FIN_VOIR, LEN_FIN_VOIR, 'W');
}
Пример #3
0
/*
** Boucle sur une rangee
*/
static void	look_rank(t_world *world, t_card *pos, int nb_case, t_cli *ia)
{
  int		k;

  k = 0;
  while (k < nb_case)
    {
      if (nb_case != 1 || k)
	save_cmd(ia, MSG_INTER_VOIR, LEN_INTER_VOIR, 'W');
      check_position(world, &(pos->y), &(pos->x), pos->direction);
      ia_print_content_case(&(world->map[pos->y][pos->x]), ia);
      if (pos->direction % 2)
	pos->x += (pos->direction == NORD) ? 1 : -1;
      else
	pos->y += (pos->direction == OUEST) ? -1 : 1;
      k++;
    }
}
Пример #4
0
int main(int argc, char **argv)
{
	int index;
	int ret;

	if (parse_options(argc, argv, &index) < 0) {
		return EINVALID_OPTION;
	}

	save_cmd(argv);
	setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
	/* Reset optind to 0 (instead of the default value, 1) at this point,
	 * because option parsing is restarted for the given subcommand, and
	 * subcommand optstrings are not prefixed with "-", which is a GNU
	 * extension. See the getopt_long(3) NOTES section.
	 */
	optind = 0;

	ret = commands[index].mainfunc(argc - 1, argv + 1);

	return ret;
}
Пример #5
0
static void	welcome_ia(t_world *world, t_team *team, t_cli *ia)
{
  char		nb[INT_LEN];
  int		len_nb;

  len_nb = atio(team->nb_client, nb);
  save_cmd(ia, nb, len_nb, 'W');
  save_cmd(ia, MSG_END, LEN_END, 'W');
  len_nb = atio(world->width, nb);
  save_cmd(ia, nb, len_nb, 'W');
  save_cmd(ia, MSG_SEP, LEN_SEP, 'W');
  len_nb = atio(world->height, nb);
  save_cmd(ia, nb, len_nb, 'W');
  save_cmd(ia, MSG_END, LEN_END, 'W');
  putstr("\033[35mNew ia connected on socket :");
  print_nb(ia->sock);
  putstr("\033[39m\n");
}