Skip to content

Instantly share code, notes, and snippets.

@DivinityArcane
Created September 23, 2013 03:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DivinityArcane/6666230 to your computer and use it in GitHub Desktop.
Save DivinityArcane/6666230 to your computer and use it in GitHub Desktop.
<?php
class Deck {
private $cards;
public function __construct() {
$this->Shuffle();
}
public function Shuffle () {
$this->cards = array(
'The Magician',
'The High Priestess',
'The Empress',
'The Emperor',
'The Hierophant',
'The Lovers',
'The Chariot',
'Strength',
'The Hermit',
'Wheel of Fortune',
'Justice',
'The Hanged Man',
'Death',
'Temperance',
'The Devil',
'The Tower',
'The Star',
'The Moon',
'The Sun',
'Judgement',
'The World',
'The Fool' // Arguably 0, but often 22.
);
shuffle($this->cards);
}
public function Draw () {
$index = mt_rand(0, count($this->cards) - 1);
$card = $this->cards[$index];
unset($this->cards[$index]);
$this->cards = array_values($this->cards);
return $card;
}
public function CardsLeft () {
return count($this->cards);
}
}
class Tarot extends extension {
public $name = 'Tarot';
public $version = 1;
public $about = 'Simple tarot card deck.';
public $status = true;
public $author = 'DivinityArcane';
private $deck;
function init() {
$this->deck = new Deck();
$this->addCmd('draw', 'c_draw');
$this->addCmd('shuffle', 'c_shuffle');
}
function c_draw($ns, $from, $message, $target) {
if ($this->deck->CardsLeft() <= 0) {
$this->dAmn->say($ns, $from.': There are no cards left! Shuffle the deck first!');
return;
}
$card = $this->deck->Draw();
$this->dAmn->say($ns, $from.': You drew <b>'. $card .'</b>!');
}
function c_shuffle($ns, $from, $message, $target) {
$this->deck->Shuffle();
$this->dAmn->say($ns, $from.': The deck has been shuffled!');
}
}
new Tarot($core);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment