Al momento, stai seguendo questa domanda
- Vedrai gli aggiornamenti nel tuofeed del contenuto seguito.
- Potresti ricevere delle e-mail a seconda delle tuepreferenze per le comunicazioni.
how can I plot a game board in a figure
Risposta accettata
30 Commenti
- 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
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Si è verificato un errore
Impossibile completare l'azione a causa delle modifiche apportate alla pagina. Ricarica la pagina per vedere lo stato aggiornato.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.
Americhe
- 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-Pacifico
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)