Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Card {
- const HEARTS = 0;
- const DIAMONDS = 1;
- const CLUBS = 2;
- const SPADES = 3;
- private $value;
- private $seed;
- public function __construct($v, $s) {
- $this->value = $v;
- $this->seed = $s;
- }
- public function getValue() { return $this->value; }
- public function getSeed() { return $this->seed; }
- public function setValue($v) {
- if ($v < 1 || $v > 13) die("Valore $v non ammesso.");
- $this->value = $v;
- }
- public function setSeed($v) {
- if ($v < 0 || $v > 3) die("Valore $v non ammesso.");
- $this->seed = $v;
- }
- public function printme() {
- $s = "";
- switch($this->getValue()) {
- case 1:
- $s = "A";
- break;
- case 11:
- $s = "J";
- break;
- case 12:
- $s = "Q";
- break;
- case 13:
- $s = "K";
- break;
- default:
- $s .= $this->getValue();
- break;
- }
- $seeds = array("Hearts", "Diamonds", "Clubs", "Spades");
- return $s." of ".$seeds[$this->getSeed()];
- }
- }
- $c = new Card(10, Card::DIAMONDS);
- echo $c->printme()."<br/>";
- echo "Un mazzo di carte francesi:<br/>";
- for($s = Card::HEARTS; $s <= Card::SPADES; ++$s)
- for($v = 1; $v < 14; ++$v)
- {
- $c = new Card($v, $s);
- echo $c->printme()."<br/>";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement