Ahora está siguiendo esta pregunta
- Verá actualizaciones en las notificaciones de contenido en seguimiento.
- Podrá recibir correos electrónicos, en función de las preferencias de comunicación que haya establecido.
how can I plot a game board in a figure
Respuesta aceptada
30 comentarios
- if there is no "traditional" figure at all, that code would cause one to be created
- if there are traditional figures, but none of them are marked internally as the "current figure", then that line of code would result in a new traditional figure being opened. Usually it is not enough to delete the current figure in order to cause the "current figure" to be set empty: in such a case, the current figure is usually selected from the children of the graphics root. However, figures would not be eligible for automatic selection if the figure handlevisibility property is set "off" or (sometimes) "callback". Also, if the graphics root CurrentFigure property is deliberately set to empty, then no other figure will be substituted when a figure is closed.
- 0 -- not occupied by either player and neither player has fired at the other player there
- 1 -- occupied by the player only and neither player has fired at the other player there
- 2 -- occupied by the opponent only and neither player as fired at the other player there
- 3 -- occupied by the player and the opponent and neither player has fired at the other player there
- 4 -- not occupied by either player and the player has fired at the opponent there -- a miss for the player
- 5 -- occupied by the player only and the player has fired at the opponent there -- a miss for the player
- 6 - occupied by the opponent only and the player has fired at the opponent there -- a hit for the player
- 7 occupied by the player and the opponent and the player has fired at the opponent there -- a hit for the player
- 8 not occupied by either player, and the opponent has fired at the player here -- a miss for the opponent
- 9 occupied by the player only and the opponent has fired at the player here -- a hit for the opponent
- 10 occupied by the opponent only and the opponent has fired at the player here -- a miss for the opponent
- 11 occupied by the player and the opponent and the opponent has fired at the player here -- a hit for the opponent
- 12 not occupied by either player and the player has fired at the opponent here and the opponent has fired at the player here -- a miss for the player and a miss for the opponent
- 13 occupied by the player only and the player has fired at the opponent there and the opponent has fired at the player there -- a miss for the player but a hit for the opponent
- 14 occupied by the opponent only and the player has fired at the opponent there and the opponent has fired by the player there -- a hit for the player and a miss for the opponent
- 15 occupied by the player and the opponent and both have fired at each other there -- a hit for the player and a hit for the opponent
- pcolor() is the wrong thing to use. Use image() instead -- but make sure the data values are uint8() so that the data values can act like images into the color map (I already showed you an example of a color map)
- input() with only a prompt always executes the line that the user types as if it were code. So if you ask the user to enter h or v and they enter those, then MATLAB would attempt to execute the v or p, by searching for variables and functions with those names. If you want the user to enter text then add the 's' option to input()
- Use strcmp() to compare text. For example strcmp(orientation, 'v')
- You will find that it is easier to have the user enter positions in terms of grid coordinates. In classic Battleships game the rows are numbered 1 to 10 and the columns are labeled 'A' to 'J' . If you have the user enter the coordinates as text you could figure out whether they had entered number-letter or letter-number and extract appropriate parts.
- The reason it is easier with grid coordinates than with numbers like 1 to 36, besides being easier for the user to understand, is that when you want to place a ship, it is easiest to have row and column of the starting point so that you can use (row, column:column+length-1) or (row:row+length-1,column) like I showed in https://www.mathworks.com/matlabcentral/answers/1614260-how-can-i-plot-a-game-board-in-a-figure#comment_1899030
Más respuestas (0)
Ver también
Etiquetas
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Se ha producido un error
No se puede completar la acción debido a los cambios realizados en la página. Vuelva a cargar la página para ver el estado actualizado.
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia-Pacífico
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)