-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.php
38 lines (30 loc) · 816 Bytes
/
start.php
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
<?php
session_start();
$_SESSION['score'] = [0, 0];
$_SESSION['current'] = 1;
unset($_SESSION['first']);
$letters = json_decode(file_get_contents('letters.json'), 1)['letters'];
/* Creating array with tiles of all letters in the bag */
foreach ($letters as $letter => $val) {
for ($i = 0; $i < $val['tiles']; $i++) {
$bag[] = $letter;
}
}
/* Shaking the bag with tiles */
shuffle($bag);
/* Players are given tiles that gets removed from the bag */
for ($user = 0; $user < 2; $user++) {
for ($i = 0; $i < 7; $i++) {
$users[$user][] = $bag[$user * 7 + $i];
unset($bag[$user * 7 + $i]);
}
}
/* Creating the board */
for ($row = 0; $row < 15; $row++) {
for ($col = 0; $col < 15; $col++) {
$board[$row][$col]++;
}
}
$_SESSION['board'] = $board;
$_SESSION['users'] = $users;
$_SESSION['bag'] = $bag;