-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsweeper.php
More file actions
35 lines (30 loc) · 894 Bytes
/
sweeper.php
File metadata and controls
35 lines (30 loc) · 894 Bytes
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
<?php
require_once("src/Cell.php");
require_once("src/Board.php");
require_once("src/Game.php");
function generateBoardData($boardSize) {
// bootstrap some data
$data = array();
for($column = 0; $column < $boardSize; $column++) {
$data[$column] = array();
for ($row = 0; $row < $boardSize; $row++) {
$data[$column][$row] = new \Cell(0);
}
}
return $data;
}
function generateMines($board) {
$maxMines = rand(2, count($board->getData())*2);
// randomly seed some mines
for($i = 0; $i < $maxMines; $i++) {
$cell = $board->getCell(rand(1, count($board->getData())), rand(1, count($board->getData()[0])));
$cell->value = -1;
}
}
$boardSize = 10;
$data = generateBoardData($boardSize);
$board = new \Board($data);
generateMines($board);
$board->calculateValues();
$game = new \Game($board);
$game->start();