예제 #1
0
void		ft_get_options(t_args *args, char *av)
{
	if (args->options->f == 1)
		args->options->color = 0;
	else if (is_legal(av) == 1)
		find_options(args->options, av);
	else
		invalid_option(args, av);
}
예제 #2
0
void	ft_get_options(t_args *args, char *av)
{
	if (ft_strcmp(av, "--color") == 0)
	{
		if (args->options->f == 0)
			args->options->color = 1;
	}
	else if (is_legal(av) == 1)
		find_options(args->options, av);
	else
		invalid_option(args, av);
}
예제 #3
0
int		main(int ac, char **av)
{
  char		*options;
  t_list	*f_list;
  t_list	*ptr;

  f_list = NULL;
  ptr = malloc(sizeof(*ptr));
  options = malloc(sizeof(*options) * 4);
  options = "ldr1";
  options = find_options(av, options, 0, 1);
  f_list = create_list(f_list, av, 0, 1);
  ptr = f_list;
  if (my_list_size(f_list) == 1)
    {
      my_ls(".", options);
      if (find_in_tab(options, 'd') == 0)
	my_putchar('\n');
    }
  else
    launch_ls(f_list, ptr, options, 1);
  //  free(options);
  return (0);
}
예제 #4
0
파일: inky.cpp 프로젝트: deipfei/MacPan
void inky::update(level l, pacman p, blinky b, int stage){
    //std::cout << "here's pnky's update" << std::endl;
    if (vulnerable){
        vulnerable_method();
    } else {
        sprite.setColor(col);
    }
    if (jailed && can_leave && !vuln_in_jail && gate_clock.getElapsedTime().asSeconds() > 1){
        //std::cout << "jailed" << std::endl;
        leave_jail();
    } else if (!jailed){
        //x or y priority to prevent infinite turning/bounce loops
        int dir_priority = 0;
        if (std::abs(ypos - goal_y) > std::abs(xpos - goal_x)){
            dir_priority = 1;
        }

        if (stage == 0 || stage == 2 || stage == 4 || stage == 6){
            //std::cout << "scatter! pinky!" << std::endl;
            bool sel = false;
            if (search_for_intersection(l) && turn_timer.getElapsedTime().asMilliseconds() > 500){
                //std::cout << "found an intersection" << std::endl;
                dirs = find_options(l);
                //for (unsigned i = 0; i < dirs.size(); i++){
                //    std::cout << dirs.at(i) << std::endl;
                //}

                //x priority
                if (dir_priority == 0){
                    if (xpos <= home_x && !sel && dir != 3){
                        for (unsigned i = 0; i < dirs.size(); i++){
                            if (dirs.at(i) == 2){
                                //std::cout << "selecting dir 2" << std::endl;
                                select_direction(2);
                                sel = true;
                            }
                        }
                    }

                    if (ypos <= home_y && !sel && dir != 0){
                        for (unsigned i = 0; i < dirs.size(); i++){
                            if (dirs.at(i) == 1){
                                //std::cout << "selecting dir 1" << std::endl;
                                select_direction(1);
                                sel = true;
                            }
                        }
                    }

                    if (!sel){
                        select_direction(random_direction(dirs));
                    }
                }

                //y priority
                if (dir_priority == 1){
                    if (ypos <= home_y && !sel && dir != 0){
                        for (unsigned i = 0; i < dirs.size(); i++){
                            if (dirs.at(i) == 1){
                                //std::cout << "selecting dir 1" << std::endl;
                                select_direction(1);
                                sel = true;
                            }
                        }
                    }

                    if (xpos <= home_x && !sel && dir != 3){
                        for (unsigned i = 0; i < dirs.size(); i++){
                            if (dirs.at(i) == 2){
                                //std::cout << "selecting dir 2" << std::endl;
                                select_direction(2);
                                sel = true;
                            }
                        }
                    }
                }

                if (!sel){
                    select_direction(random_direction(dirs));
                }
            }

//            if (stage == 4 || stage == 6){
//                if (chase_pacman.getElapsedTime().asSeconds() >= 5){
//                    stage++;
//                    scatter.restart();
//                }
//            } else {
//                if (chase_pacman.getElapsedTime().asSeconds() >= 7){
//                    stage++;
//                    scatter.restart();
//                }
//            }
        }
        //chasing pacman
        else {
            //std::cout << "chase! pinky!" << std::endl;

            if (vulnerable){
                goal_x = home_x;
                goal_y = home_y;
            } else {
                if (p.get_dir() == 0){
                    goal_x = p.get_xpos() - 50;
                    goal_y = p.get_ypos() - 50;
                    goal_x = goal_x + (goal_x - b.get_xpos());
                    goal_y = goal_y + (goal_y - b.get_ypos());
                    if (goal_x < 25){
                        goal_x = 25;
                    }
                    if (goal_y < 25){
                        goal_y = 25;
                    }
                }
                else if (p.get_dir() == 1){
                    goal_x = p.get_xpos();
                    goal_y = p.get_ypos() + 50;
                    goal_x = goal_x + (goal_x - b.get_xpos());
                    goal_y = goal_y + (goal_y - b.get_ypos());
                    if (goal_y > 650){
                        goal_y = 650;
                    }
                }
                else if (p.get_dir() == 2){
                    goal_x = p.get_xpos() + 50;
                    goal_y = p.get_ypos();
                    goal_x = goal_x + (goal_x - b.get_xpos());
                    goal_y = goal_y + (goal_y - b.get_ypos());
                    if (goal_x > 500){
                        goal_x = 500;
                    }
                } else {
                    goal_x = p.get_xpos() - 50;
                    goal_y = p.get_ypos();
                    goal_x = goal_x + (goal_x - b.get_xpos());
                    goal_y = goal_y + (goal_y - b.get_ypos());
                    if (goal_x < 25){
                        goal_x = 25;
                    }
                }
            }



            bool sel = false;
            if (search_for_intersection(l) && turn_timer.getElapsedTime().asMilliseconds() > 500){
                //std::cout << "found an intersection" << std::endl;
                dirs = find_options(l);
                //for (unsigned i = 0; i < dirs.size(); i++){
                    //std::cout << dirs.at(i) << std::endl;
                //}

                if (dir_priority == 0){
                    if (xpos >= goal_x && !sel && dir != 2){
                        for (unsigned i = 0; i < dirs.size(); i++){
                            if (dirs.at(i) == 3){
                                //std::cout << "selecting dir 3" << std::endl;
                                select_direction(3);
                                sel = true;
                            }
                        }
                    }

                    else if (xpos < goal_x && !sel && dir != 3) {
                        for (unsigned i = 0; i < dirs.size(); i++){
                            if (dirs.at(i) == 2){
                                //std::cout << "selecting dir 2" << std::endl;
                                select_direction(2);
                                sel = true;
                            }
                        }
                    }

                    if (ypos >= goal_y && !sel && dir != 1){
                        for (unsigned i = 0; i < dirs.size(); i++){
                            if (dirs.at(i) == 0){
                                //std::cout << "selecting dir 0" << std::endl;
                                select_direction(0);
                                sel = true;
                            }
                        }
                    }

                    else if (ypos < goal_y && !sel && dir != 0){
                        for (unsigned i = 0; i < dirs.size(); i++){
                            if (dirs.at(i) == 1){
                                //std::cout << "selecting dir 1" << std::endl;
                                select_direction(1);
                                sel = true;
                            }
                        }
                    }
                }

                if (dir_priority == 1){
                    if (ypos >= goal_y && !sel && dir != 1){
                        for (unsigned i = 0; i < dirs.size(); i++){
                            if (dirs.at(i) == 0){
                                //std::cout << "selecting dir 0" << std::endl;
                                select_direction(0);
                                sel = true;
                            }
                        }
                    }

                    else if (ypos < goal_y && !sel && dir != 0){
                        for (unsigned i = 0; i < dirs.size(); i++){
                            if (dirs.at(i) == 1){
                                //std::cout << "selecting dir 1" << std::endl;
                                select_direction(1);
                                sel = true;
                            }
                        }
                    }

                    if (xpos >= goal_x && !sel && dir != 2){
                        for (unsigned i = 0; i < dirs.size(); i++){
                            if (dirs.at(i) == 3){
                                //std::cout << "selecting dir 3" << std::endl;
                                select_direction(3);
                                sel = true;
                            }
                        }
                    }

                    else if (xpos < goal_x && !sel && dir != 3) {
                        for (unsigned i = 0; i < dirs.size(); i++){
                            if (dirs.at(i) == 2){
                                //std::cout << "selecting dir 2" << std::endl;
                                select_direction(2);
                                sel = true;
                            }
                        }
                    }
                }

                if (!sel){
                    select_direction(random_direction(dirs));
                }
            }


//            if (stage == 1 || stage == 3 || stage == 5){
//                if (scatter.getElapsedTime().asSeconds() >= 20){
//                    stage++;
//                    chase_pacman.restart();
//                }
//            }
        }

    }

    update_position(l);
}