Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
873 B
0
Indexable
Never
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>
Leave a Comment