예제 #1
0
void		regen_food(t_env *env, t_action *action)
{
  size_t	mapx;
  size_t	mapy;

  if (difftime(time(NULL), action->time) >= REGEN_FOOD /env->time)
    {
      mapy = rand() % env->map.height;
      mapx = rand() % env->map.width;
      env->map.map[mapy][mapx][0] =
	(env->map.map[mapy][mapx][0] + rand() % 2) % 20;
      env->map.map[mapy][mapx][1] =
	(env->map.map[mapy][mapx][1] + rand() % 5) % 20;
      env->map.map[mapy][mapx][2] =
	(env->map.map[mapy][mapx][2] + rand() % 5) % 20;
      env->map.map[mapy][mapx][3] =
	(env->map.map[mapy][mapx][3] + rand() % 5) % 20;
      env->map.map[mapy][mapx][4] =
	(env->map.map[mapy][mapx][4] + rand() % 5) % 20;
      env->map.map[mapy][mapx][5] =
	(env->map.map[mapy][mapx][5] + rand() % 5) % 20;
      env->map.map[mapy][mapx][6] =
	(env->map.map[mapy][mapx][6] + rand() % 5) % 20;
      bct(env, mapy, mapx);
      action->time = time(NULL);
    }
}
예제 #2
0
파일: bct.c 프로젝트: Nyrii/-EPITECH-Zappy
int		bct_on_tile(t_server *server, t_client *graphic)
{
  char		*parameters[2];
  int		pos[2];
  char		*answ;
  char		buf[4096];

  if (!server || !server->params || !graphic
      || !(parameters[0] = strtok(server->params, " \t"))
      || !(parameters[1] = strtok(NULL, " \t")))
    return (sbp(graphic));
  pos[0] = atoi(parameters[1]);
  pos[1] = atoi(parameters[0]);
  if (pos[0] >= 0 && pos[0] < server->data.world_y
      && pos[1] >= 0 && pos[1] < server->data.world_x)
    {
      if ((answ = bct(server->data.map, pos[0], pos[1])) == NULL)
	return (-1);
      if (memset(buf, 0, 4096) == NULL || snprintf(buf, 4096, MSG, answ) == -1)
        return (fprintf(stderr, ERR_PRINTF), -1);
      free(answ);
      if (store_answer_c(graphic, strdup(buf), 0) == -1)
	return (fprintf(stderr, ERR_BUFFER), -1);
      return (0);
    }
  return (sbp(graphic));
}
예제 #3
0
파일: mct.c 프로젝트: elominp/zappy
bool
mct(t_cli *c, t_msg *msg)
{
  int64_t	x;
  int64_t	y;
  int64_t	xmax;
  int64_t	ymax;
  t_list	*params;

  (void)msg;
  x = 0;
  y = 0;
  xmax = c->servptr->map.width;
  ymax = c->servptr->map.height;
  if ((params = new_list()) == NULL || init_list(params) == false)
    return (ERR(RED"Omg malloc failed, BAIL OUT BAIL OUT\n"WHITE), false);
  while (y <= xmax)
    {
      while (x <= ymax)
	{
	  prepare_message(params, x, y);
	  bct(c, &(t_msg){NULL, "bct", params, 0});
	  x++;
	}
      x = 0;
      y++;
    }
  return (list_destruct(&params, &free), true);
}
예제 #4
0
파일: bct.c 프로젝트: Nyrii/-EPITECH-Zappy
int			bct_ia(t_server *server, int const y, int const x)
{
  char			*tmp;
  char			buffer[4096];

  if ((tmp = bct(server->data.map, y, x)) == NULL)
    return (-1);
  if (memset(buffer, 0, 4096) == NULL
      || snprintf(buffer, 4096, MSG, tmp) == -1)
    return (fprintf(stderr, ERR_MEMSET), -1);
  send_all_graphics(server, strdup(buffer));
  free(tmp);
  return (0);
}
예제 #5
0
파일: functions_1.c 프로젝트: jorge-d/zappy
void	mct(t_ctrl *c, t_jm_list *l)
{
  int	x;
  int	y;

  y = 0;
  while (y < getmapy(c))
    {
      x = 0;
      while (x < getmapx(c))
	{
	  bct(c, l, x, y);
	  x++;
	}
      y++;
    }
}
예제 #6
0
void	fptr_mct(t_env *env, t_action *action)
{
  bct(env, action->client->player.coor.y,
      action->client->player.coor.x++);

  if (action->client->player.coor.x >= (int)env->map.width)
    {
      action->client->player.coor.x = 0;
      action->client->player.coor.y++;
    }
  if (action->client->player.coor.y >= (int)env->map.height)
    {
      action->client->player.coor.y = 0;
      action->client->player.coor.x = 0;
      if (action->client->graphic_init == 1)
	init_graph_end(env, action);
      delete_action(action);
    }
}
예제 #7
0
void	fptr_bct(t_env *env, t_action *action)
{
  int	x;
  int	y;
  char	*err1;
  char	*err2;

  err1 = NULL;
  err2 = NULL;
  if (action->input == NULL || action->input[0] == NULL
      || action->input[1] == NULL || action->input[2] == NULL)
    sbp(env);
  else
    {
      x = strtol(action->input[1], &err1, 10);
      y = strtol(action->input[2], &err2, 10);
      if (x < (int)env->map.height && y < (int)env->map.width
	  && err1[0] == '\0' && err2[0] == '\0')
	bct(env, y, x);
      else
	sbp(env);
    }
  delete_action(action);
}