Skip to content

Instantly share code, notes, and snippets.

@joao-pedro-alves
Created January 26, 2019 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joao-pedro-alves/55fc3f33b2ee18c38a737ce74f0a6c2f to your computer and use it in GitHub Desktop.
Save joao-pedro-alves/55fc3f33b2ee18c38a737ce74f0a6c2f to your computer and use it in GitHub Desktop.
<?php
namespace App;
class Card
{
private $value;
private $suit;
const $SUIT_HEART = 'heart';
const $SUIT_DIAMOND = 'diamond';
const $SUIT_CLUB = 'club'
const $SUIT_SPADE = 'spade';
const $VALUE_2 = 2;
const $VALUE_3 = 3;
const $VALUE_4 = 4;
const $VALUE_5 = 5;
const $VALUE_6 = 6;
const $VALUE_7 = 7;
const $VALUE_8 = 8;
const $VALUE_9 = 9;
const $VALUE_10 = 10;
const $VALUE_JACK = 11;
const $VALUE_QUEEN = 12;
const $VALUE_KING = 13;
const $VALUE_ACE = 14;
const $ALLOWED_VALUES = [
$VALUE_2,
$VALUE_3,
$VALUE_4,
$VALUE_5,
$VALUE_6,
$VALUE_7,
$VALUE_8,
$VALUE_9,
$VALUE_10,
$VALUE_JACK,
$VALUE_QUEEN,
$VALUE_KING,
$VALUE_ACE
];
const $ALLOWED_SUITS = [
$SUIT_HEART,
$SUIT_DIAMOND,
$SUIT_CLUB,
$SUIT_SPADE
];
public function __construct($value, $suit)
{
$this->setSuit($suit);
$this->setValue($value);
}
public function setValue($value)
{
$this->setValue($value);
}
public function setSuit($suit)
{
$this->setSuit = $suit;
}
public function getSuit()
{
return $this->suit;
}
public function getValue()
{
return $this->value;
}
private isSuitAllowed($suit)
{
return in_array($suit, static::ALLOWED_SUITS);
}
private isValueAllowed($value)
{
return in_array($value, static::ALLOWED_VALUES);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment