Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from ryamate/feature-step3-solid
Feature step3 solid
- Loading branch information
Showing
12 changed files
with
275 additions
and
243 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Blackjack; | ||
|
||
require_once('Player.php'); | ||
|
||
use Blackjack\Player; | ||
|
||
/** | ||
* ノンプレイヤーキャラクタークラス | ||
*/ | ||
class AutoPlayer extends Player | ||
{ | ||
/** | ||
* 選択したアクション(ヒットかスタンド)により進行する | ||
* | ||
* @param Deck $deck | ||
* @param Dealer $dealer | ||
* @return void | ||
*/ | ||
public function action(Deck $deck, Dealer $dealer): void | ||
{ | ||
$message = ''; | ||
while ($this->getStatus() === 'hit') { | ||
echo Message::getProgressMessage($this); | ||
echo Message::getProgressQuestionMessage(); | ||
$inputYesOrNo = $this->selectHitOrStand(); | ||
|
||
if ($inputYesOrNo === 'Y') { | ||
$dealer->dealOneCard($deck, $this); | ||
$dealer->checkBurst($this); | ||
$message = Message::getCardDrawnMessage($this); | ||
} elseif ($inputYesOrNo === 'N') { | ||
$this->changeStatus('stand'); | ||
$message = PHP_EOL; | ||
} | ||
echo $message; | ||
} | ||
} | ||
|
||
/** | ||
* ヒットかスタンドを Y/N で選択する(カードの合計値が17以上になるまで引き続ける) | ||
* | ||
* @return string $inputYesOrNo | ||
*/ | ||
public function selectHitOrStand(): string | ||
{ | ||
if ($this->getScoreTotal() < 17) { | ||
$inputYesOrNo = 'Y'; | ||
echo 'Y' . PHP_EOL; | ||
} else { | ||
$inputYesOrNo = 'N'; | ||
echo 'N' . PHP_EOL; | ||
} | ||
return $inputYesOrNo; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.