为什么实例仍在处理卡?即使很清楚,$ 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是显然不是一个类,它的定义和使用程序 –