La classe PokerUI permet de produire les composants nécessaires pour interagir avec l'utilisateur
/**
* Classe PokerUI
*
* @author Dominique Fournier
* @date 2017-2022
* @version 1.3 compatible PHP7.4
*/
include_once "JeuCartes.php";
include_once "Main.php";
class PokerUI {
/**
* @access private
* @var JeuCartes
*/
private JeuCartes $paquetCartes;
/**
* @access private
* @var Main
*/
private $main;
/**
* @access public
*/
public function __construct(){
$this->paquetCartes = new JeuCartes();
$this->paquetCartes->melangePaquet();
$this->main = new Main();
$this->main->addCarte($this->paquetCartes->distribueCarte());
$this->main->addCarte($this->paquetCartes->distribueCarte());
$this->main->addCarte($this->paquetCartes->distribueCarte());
$this->main->addCarte($this->paquetCartes->distribueCarte());
$this->main->addCarte($this->paquetCartes->distribueCarte());
$this->main->triMain();
}
/**
* @access public
* @param array les indices des cartes à renouveler
* @return void
*/
public function renouvelleMain(array $indexes): void {
foreach ($indexes as $index) {
$c = $this->main->getCarte($index);
$this->main->setCarte($index,$this->paquetCartes->distribueCarte());
$this->paquetCartes->remiseCarte($c);
}
$this->main->triMain();
}
/**
* @access public
* @return void
*/
public function affichePaquetCarte():void {
$bjc = new BoiteJeuCartes($this->paquetCartes);
echo $bjc;
}
/**
* @access public
* @return void
*/
public function afficheMain(): void {
echo new BoiteMain($this->main);
}
/**
* @access public
* @return void
*/
public function afficheFormulaireMain(): void {
echo "<form action='".$_SERVER['PHP_SELF']."' method='get'>
<div class='main'><fieldset><legend>Formulaire de changement de cartes</legend>
<input type='checkbox' name='main[]' value='0' />";
echo new BoiteCarte($this->main->getCarte(0));
echo "<input type='checkbox' name='main[]' value='1' />\n";
echo new BoiteCarte($this->main->getCarte(1));
echo "<input type='checkbox' name='main[]' value='2' />\n";
echo new BoiteCarte($this->main->getCarte(2));
echo "<input type='checkbox' name='main[]' value='3' />\n";
echo new BoiteCarte($this->main->getCarte(3));
echo "<input type='checkbox' name='main[]' value='4' />\n";
echo new BoiteCarte($this->main->getCarte(4));
echo "<input type='submit' value='changer' name='action' />\n";
echo "<input type='submit' value='finir' name='action' />\n";
echo "<input type='submit' value='raz' name='action' />\n";
echo "</div></form>\n";
}
/**
* @static
* @access public
* @retrun void
*/
public static function afficheMessage($message): void {
echo "<h3>$message</h3>\n";
}
/**
* @access public
* @return void
*/
public static function afficheLienRecommencer(): void {
echo "<p><a href='".$_SERVER['PHP_SELF']."'>Recommencer ?</a></p>\n";
}
}