爲什麼實例仍在處理卡?即使很清楚,$ isDealer標記默認爲false,除了經銷商?真/假....仍然處理卡?
$cards = array('Ace','2','3','4','5','6','7','8','9','10','Jack','Queen','King');
$suits = array('Hearts','Diamonds','Spades','Clubs');
class Person {
public $isDealer = false;
public $luck = 15;
public function dealCards() {
if ($isDealer) {
global $cards;
global $suits;
for ($i = 0; $i < 5; $i++) {
$pulledcard = rand(0,count($cards)-1);
$pulledsuit = rand(0,count($suits)-1);
echo $dealt = $cards[$pulledcard] .' of '. $suits[$pulledsuit] . '<br>';
}
}
else {
return 'You\'re not a dealer';
}
}
}
class Baller extends Person { public $luck = 50; }
class Dealer extends Person { public $isDealer = true; }
$dealer = new Dealer();
$theman = new Baller();
$random = new Person();
echo $theman->dealCards(); //this should return you're not a dealer but it deals cards instead
最後一部分應該返回一個「你不是經銷商!」而是交易卡。實際的「經銷商」也是如此。
這不是做這件事的方法。 'dealCards()'應該在Dealer類中。 –
你爲什麼使用'global'?這是一個非常糟糕的主意。 – Mike
來吧傢伙,isDealer是顯然不是一個類,它的定義和使用程序 –