Vous suivez désormais cette question
- Les mises à jour seront visibles dans votre flux de contenu suivi.
- Selon vos préférences en matière de communication il est possible que vous receviez des e-mails.
how can I plot a game board in a figure
Réponse acceptée
30 commentaires
- 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
Plus de réponses (0)
Voir également
Catégories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Une erreur s'est produite
Impossible de terminer l’action en raison de modifications de la page. Rechargez la page pour voir sa mise à jour.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)
Asie-Pacifique
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)