-
Notifications
You must be signed in to change notification settings - Fork 0
/
notes.txt
68 lines (43 loc) · 1.31 KB
/
notes.txt
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
craeteGame () {
initBoard('player')
initBoard('ai')
creates two variables with empty 2-dimensional arrays filled with 0
setBoard('player')
drawBoard('player')
addEvents('player')
onHover: (mouseover, mouseout)
checkAvailable(location)
hover(location, true) || hover(location, false)
onClick:
placeShip(location) // only on array
setBoard('ai')
randomShipAll('ai')
randomShipAll(target)
getRandomLocation
getRandomRotation
}
startGame() {
drawBoard('player')
drawBoard('score')
addEvents('score')
while (win = false)
Set currentPlayer to 'player'
Listen to click on score board
Than fireTorpedo(location)
checkIfWin() // checks if any of the arrays still has value 1 (use of some() array method)
Set currentPlayer to 'ai'
pick random location at player's board
}
drawBoard(type)
player:
select div #playerOneBoard
draw content of playerOneBoard array to selected div with each cell attr @data-location=${type}-X-Y
score:
select div #targetBoard
draw empty board with each cell attr @data-location=${score}-X-Y
fireTorpedo(location)
if value at location === 0
update(location, 'miss')
if value at location === 1
update(location, 'hit')
update(location, type)