-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBingoCard.php
More file actions
60 lines (50 loc) · 1.1 KB
/
BingoCard.php
File metadata and controls
60 lines (50 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* © 2020 n8blake
* SantA Bingo Card
* Generate a new SantA bingo card...
* each letter will have an array of 5 numbers from a given range
* S: 1-15
* a: 16-30
* n: 31-45
* t: 46-60
* A: 61-75
*/
class BingoCard {
//['S':[1, 2, 3, 4, 5], 'a':[16],
public $card;
public $id;
function __construct()
{
$this->card = array(
"S"=> $this->fiveRandomValues(1, 15),
"a"=> $this->fiveRandomValues(16, 30),
"n"=> $this->fiveRandomValues(31, 45),
"t"=> $this->fiveRandomValues(46, 60),
"A"=> $this->fiveRandomValues(61, 75),
);
$this->card["n"][2] = 0;
$this->id = uniqid();
}
// return an array of 5 random, unique integers
// between the min and max
private function fiveRandomValues($min, $max){
$arr = array();
while(count($arr) < 5){
$number = rand($min, $max);
if(!in_array($number, $arr)){
// add number
array_push($arr, $number);
}
}
return $arr;
}
// take a json string and turn it into a card
public function setCard($json){
$object = json_decode($json);
if(isset($object->card)){
$this->card = $object->card;
}
}
}
?>