[ create a new paste ] login | about

Project: php
Link: http://php.codepad.org/KNxcc4nc    [ raw code | output | fork ]

PHP, pasted on Apr 25:
class Card {

    private $suit;
    private $val;
    private $rank;
    private $face;
    
    public function __construct($suit, $val, $rank) {
        $this->suit = $suit;
        $this->val = $val;
        $this->rank = $rank;
        $this->face = $this->val.$this->suit;
    }
    
    public function getSuit() {
       return $this->suit; 
    }
        public function getVal() {
        return $this->val;
    }
    
    public function getRank() {
        return $this->rank;
    }
    public function getFace() {
        return $this->face;
    }
}
class Deck {
        
        private $deck = [];
        
        public function __construct() {
            $this->deck = $this->createDeck();
        }
    
    
        public function createSuit($suit) {
            return array(
                new Card($suit, '2', 2),
                new Card($suit, '3', 3),
                new Card($suit, '4', 4),
                new Card($suit, '5', 5),
                new Card($suit, '6', 6),
                new Card($suit, '7', 7),
                new Card($suit, '8', 8),
                new Card($suit, '9', 9),
                new Card($suit, '10', 10),
                new Card($suit, 'J',  11),
                new Card($suit, 'Q',  12),
                new Card($suit, 'K',  13),
                new Card($suit, 'A',  14),
            );
        }
        
        public function createDeck() {
            return array_merge(
                $this->createSuit('D'), 
                $this->createSuit('H'), 
                $this->createSuit('C'), 
                $this->createSuit('S'));
        }
       
    }
<?php

    class Hand {
        
        private $cards;
        
        public function __construct($hand) {
            $this->cards = explode(' ', $hand);
        }
        
        public function getCards(){
            return $this->cards;
        }
    }

    $d = new Deck();
    $h = new Hand('As Ks Qs Js 10s');

    var_dump($d);
    var_dump($h->getCards());

    // output: array(5) { [0]=> string(2) "As" [1]=> string(2) "Ks" [2]=> string(2) "Qs" [3]=> string(2) "Js" [4]=> string(3) "10s" }


Output:
class Card {

    private $suit;
    private $val;
    private $rank;
    private $face;
    
    public function __construct($suit, $val, $rank) {
        $this->suit = $suit;
        $this->val = $val;
        $this->rank = $rank;
        $this->face = $this->val.$this->suit;
    }
    
    public function getSuit() {
       return $this->suit; 
    }
        public function getVal() {
        return $this->val;
    }
    
    public function getRank() {
        return $this->rank;
    }
    public function getFace() {
        return $this->face;
    }
}
class Deck {
        
        private $deck = [];
        
        public function __construct() {
            $this->deck = $this->createDeck();
        }
    
    
        public function createSuit($suit) {
            return array(
                new Card($suit, '2', 2),
                new Card($suit, '3', 3),
                new Card($suit, '4', 4),
                new Card($suit, '5', 5),
                new Card($suit, '6', 6),
                new Card($suit, '7', 7),
                new Card($suit, '8', 8),
                new Card($suit, '9', 9),
                new Card($suit, '10', 10),
                new Card($suit, 'J',  11),
                new Card($suit, 'Q',  12),
                new Card($suit, 'K',  13),
                new Card($suit, 'A',  14),
            );
        }
        
        public function createDeck() {
            return array_merge(
                $this->createSuit('D'), 
                $this->createSuit('H'), 
                $this->createSuit('C'), 
                $this->createSuit('S'));
        }
       
    }

Fatal error: Class 'Deck' not found on line 80


Create a new paste based on this one


Comments: