How to convert the mouse position in pixels into the row and column on the grid?

I am basically making a battleship guessing game where you have to the position of a ship by the click of your mouse. When a position of the ship is guessed correctly it deletes that ship cell from the array and when every cell is guessed correctly, the game is over.

What I am now struggling on is to

  1. keep the ship cells within the canvas
  2. convert the mouse position in pixels into the row and column on the grid
  3. if the guess is correct, add the guess to the hit array and if missed adding it to the miss array.
  4. when a guess is made, in addition to colouring the cell, print either “Hit!” or “Miss!” on the cell
  5. sinking the ship when all cells have been hit
Answer:1

Estoy tratando de instalar el marco de extracción DBPedia siguiendo el http://wiki.dbpedia.org/Documentation He descargado la versión binaria de Maven. $ mvn --version Apache Maven 3.0.4 (r1232337; ...

Tengo un problema al convertir el byte al archivo de sonido .mp3. En mi caso, lo hago usando FileOutputStream usando su método de escritura (bytes) pero solo crea un archivo de datos con extensión mp3 pero no puedo reproducirlo en ...

Hola, estoy haciendo esto en el método public void update (Table table, String tableName) {ArrayList <Name> firstRowInDslFormat = new ArrayList <> (); para (Valor del objeto: tabla ...

Recibo este error al analizar json. Alguien puede ayudarme a resolver esto. {"sitio web": ["http://www.example.com", "https://buy.example.com"], "número": ["4546", "54256456"], "...