daily pastebin goal
34%
SHARE
TWEET

Untitled

a guest Feb 14th, 2018 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. class Game {
  3.     function __construct () {
  4.         $this->players = array();
  5.     }
  6.  
  7.     /* deal 2 cards to each player in the game */
  8.     public function deal () {
  9.         foreach($this->players as $player_name => $player) {
  10.             $card_values = rand(2, 21);
  11.             $player->score_hand($card_values);
  12.         }
  13.     }
  14.    
  15.     /* deal one card to player */
  16.     public function hit($player) {
  17.         if (array_key_exists($player, $this->players) == FALSE) {
  18.             throw new Exception('Wrong table');
  19.         }
  20.  
  21.         $current_player = $this->players[$player];
  22.  
  23.         $card_value = rand(2, 11);
  24.         $current_player->score_hand($card_value);
  25.         return $current_player;
  26.     }
  27.  
  28.     /* add a player to the game */
  29.     public function add_player($name) {
  30.         include_once('player.php');
  31.  
  32.         $player = new Player();
  33.         $player->init($name);
  34.  
  35.         if (isset($this->players[$player->name])) {
  36.             throw new Exception('This player is already in the game');
  37.         }
  38.  
  39.         $this->players[$player->name] = $player;    
  40.  
  41.         echo 'Adding ' . $player->name . ' to game' . "\n";
  42.         return $player;
  43.     }
  44. }
  45. ?>
RAW Paste Data
Top