-
Notifications
You must be signed in to change notification settings - Fork 0
/
placeBombs.m
84 lines (63 loc) · 2.63 KB
/
placeBombs.m
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
function board = placeBombs(board, difficulty, rowClicked, columnClicked, numBombs)
%PLACEBOMB places the bombs on the board
% places the bombs on the background board based on the difficulty. 99
% for hard, 40 for medium, 10 for easy. There is a check to make sure
% that bombs are not placed on teh first intital click tile, or any
% adjacent tiles
rng("shuffle");
bombsPlaced = 0;
bombTile = 14;
[rows,columns] = size(board);
%advanced board has 99 bombs
if difficulty == 3
while bombsPlaced < numBombs
%get the random location of bomb placement
randomRow = randi(rows);
randomColumn = randi(columns);
location = [randomRow, randomColumn];
%check to make sure that the bomb is not being placed on or near
%the first click
isBombable = bombableCheck(rowClicked,columnClicked, location);
%places bomb if there is not already a bomb and it is not one of
%the tiles attatched to the first click
if (board(randomRow, randomColumn) ~= bombTile) && isBombable
board(randomRow, randomColumn) = bombTile;
bombsPlaced = bombsPlaced + 1;
end
end
%intermediate board has 40 bombs
elseif difficulty == 2
while bombsPlaced < numBombs
%get the random location of bomb placement
randomRow = randi(rows);
randomColumn = randi(columns);
location = [randomRow, randomColumn];
%check to make sure that the bomb is not being placed on or near
%the first click
isBombable = bombableCheck(rowClicked,columnClicked, location);
%places bomb if there is not already a bomb and it is not one of
%the tiles attatched to the first click
if (board(randomRow, randomColumn) ~= bombTile) && isBombable
board(randomRow, randomColumn) = bombTile;
bombsPlaced = bombsPlaced + 1;
end
end
%beginner board has 10 bombs
elseif difficulty == 1
while bombsPlaced < numBombs
%get the random location of bomb placement
randomRow = randi(rows);
randomColumn = randi(columns);
location = [randomRow, randomColumn];
%check to make sure that the bomb is not being placed on or near
%the first click
isBombable = bombableCheck(rowClicked,columnClicked, location);
%places bomb if there is not already a bomb and it is not one of
%the tiles attatched to the first click
if (board(randomRow, randomColumn) ~= bombTile) && isBombable
board(randomRow, randomColumn) = bombTile;
bombsPlaced = bombsPlaced + 1;
end
end
end
end