Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Game {
- function __construct () {
- $this->players = array();
- }
- /* deal 2 cards to each player in the game */
- public function deal () {
- foreach($this->players as $player_name => $player) {
- $card_values = rand(2, 21);
- $player->score_hand($card_values);
- }
- }
- /* deal one card to player */
- public function hit($player) {
- if (array_key_exists($player, $this->players) == FALSE) {
- throw new Exception('Wrong table');
- }
- $current_player = $this->players[$player];
- $card_value = rand(2, 11);
- $current_player->score_hand($card_value);
- return $current_player;
- }
- /* add a player to the game */
- public function add_player($name) {
- include_once('player.php');
- $player = new Player();
- $player->init($name);
- if (isset($this->players[$player->name])) {
- throw new Exception('This player is already in the game');
- }
- $this->players[$player->name] = $player;
- echo 'Adding ' . $player->name . ' to game' . "\n";
- return $player;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment