Ejemplo n.º 1
0
    }
    public function sortear()
    {
        $minimo = $this->numero / 2;
        $maximo = $this->numero * 2;
        for ($i = 0; $i < $this->intentos; $i++) {
            $int = rand($minimo, $maximo);
            self::intentos($int);
        }
    }
    public function intentos($int)
    {
        if ($int == $this->numero) {
            echo "<b>" . $int . " == " . $this->numero . "</b><br>";
            $this->resultado = true;
        } else {
            echo $int . " != " . $this->numero . "<br>";
        }
    }
    public function __destruct()
    {
        if ($this->resultado) {
            echo "¡Felicidades, has acertado en " . $this->intentos . " intentos!";
        } else {
            echo "Que lastima, has perdido en " . $this->intentos . "intentos.";
        }
    }
}
$loteria = new Loteria(10, 5);
$loteria->sortear();
Ejemplo n.º 2
0
    public function sortear()
    {
        $minimo = $this->numero / 2;
        $maximo = $this->numero * 2;
        for ($i = 0; $i < $this->intentos; $i++) {
            $int = rand($minimo, $maximo);
            $this->intentos($int);
        }
    }
    public function intentos($int)
    {
        if ($int == $this->numero) {
            echo "<br>" . $int . " == " . $this->numero . "</br><br>";
            $this->contador++;
            $this->resultado = true;
        } else {
            echo $int . " != " . $this->numero . "<br>";
        }
    }
    public function __destruct()
    {
        if ($this->resultado) {
            echo "Felicitaciones, has ganado en " . $this->intentos . " intentos un total de resultados: " . $this->contador;
        } else {
            echo "Felicitaciones, has perdido en " . $this->intentos . " intentos con un total de resultados en: 0";
        }
    }
}
$jugandoloteria = new Loteria(6, 30);
$jugandoloteria->sortear();