Esempio n. 1
0
function ft_exec_travel($travel, $socket)
{
    foreach ($travel as $data) {
        socket_write($socket, $data . "\n");
        echo $data . "\n";
        get_next_line_socket($socket, $data);
    }
}
Esempio n. 2
0
function ft_call($socket, $current, $lvl)
{
    while (42) {
        socket_write($socket, "broadcast " . $GLOBALS['inventaire']["team"] . "\n");
        echo "broadcast " . $GLOBALS['inventaire']["team"] . "\n";
        get_next_line_socket($socket, "broadcast");
        $current = ft_see($socket);
        ft_search($socket, $current, $lvl, "nourriture");
        $lvl = ft_incantation($socket, $lvl, $current, FALSE);
    }
}
Esempio n. 3
0
function ft_search_up($socket, $current, $lvl)
{
    foreach ($current[0] as $data) {
        if (isset($GLOBALS['stack'][$data]) && $GLOBALS['stack'][$data] > $GLOBALS['inventaire'][$data]) {
            socket_write($socket, "prend " . $data . "\n");
            echo "prend " . $data . "\n";
            if (($tmp = get_next_line_socket($socket, "prend")) == "ok\n") {
                $GLOBALS['inventaire'][$data]++;
            } else {
                if ($tmp == "ko\n") {
                    return FALSE;
                }
            }
        }
    }
    foreach ($GLOBALS['leveling'][$lvl - 1] as $key => $value) {
        if ($key != "nb_joueur" && $GLOBALS['inventaire'][$key] <= $value) {
            return FALSE;
        }
    }
    return TRUE;
}
Esempio n. 4
0
function ft_move($socket, $current)
{
    $default_view = ft_create_dv();
    $i = 0;
    $destination = array();
    foreach ($current as $case) {
        $destination[$i] = 0;
        foreach ($case as $data) {
            if (isset($GLOBALS['stack'][$data]) && $GLOBALS['stack'][$data] > $GLOBALS['inventaire'][$data]) {
                $destination[$i]++;
            }
        }
        $i++;
    }
    if (max($destination) == 0) {
        socket_write($socket, "avance\n");
        echo "avance\n";
        get_next_line_socket($socket, "avance");
        return;
    }
    $dest = array_search(max($destination), $destination);
    $travel = array();
    foreach ($default_view as $y => $value) {
        foreach ($value as $x => $case) {
            if ($case == $dest) {
                $travel = ft_create_travel($x, $y);
                if (isset($travel[0])) {
                    ft_exec_travel($travel, $socket);
                }
                return;
            }
        }
    }
}