Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

How can I create a battleship game board with a variable size as a char array so that I can edit certain elements of it?

1 Ansicht (letzte 30 Tage)
So I have the user input the size of the board they want to play on and I figured out how to do it using for loops and fprintf statements, but I need what this code produces but in an array of type char, can anyone help me out? I need a board that will look exactly like the one that my code produces below, but as a char array.
if true
%Create the visible board
%for loop creating first row of the board
fprintf ('\n- ')
for i = 1:Size
fprintf (' %d ', i);
end
fprintf ('\n')
%for loop creating the rest of the rows of the board
for j = 1:Size
fprintf ('%d', j)
for j = 1:Size
fprintf (' .')
end
fprintf ('\n')
end
end

Antworten (0)

Diese Frage ist geschlossen.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by