Untitled
unknown
plain_text
2 years ago
873 B
6
Indexable
class Battleships {
player.placeShip()
// Do other stuff here
}
class Player {
placeShip() {
const { y, x } = getCoordinatesFromUIInSomeWayButHow;
gameboard.receiveShip(y, x)
}
}
class gameBoard {
board = [
['', '', ''],
['', '', ''],
['', '', '']
]
receiveShip(y, x) {
board[y][x] = 'thisIsAShip'
}
}
// index.html
<ul class="board">
<li class="square"></li>
<li class="square"></li>
<li class="square"></li>
<li class="square"></li>
<li class="square"></li>
<li class="square"></li>
<li class="square"></li>
<li class="square"></li>
<li class="square"></li>
</ul>
<script>
const squares = document.querySelectorAll('.square')
squares.forEeach(square => {
square.addEventListener('click', getCoordinateOfSquare);
})
</script>Editor is loading...
Leave a Comment