How do i add a game board into matlab ?

 Respuesta aceptada

image([0.5 5.5], [0.5 5.5], ones(6,6,3));
xticks(0:6); xticklabels([]);
yticks(0:6); yticklabels([]);
grid on
text(0.5:5.5, 6.5*ones(1,6), string(1:6).')
text(-0.5*ones(1,6), 0.5:5.5, string(1:6).')

4 comentarios

Hisham Aziz
Hisham Aziz el 8 de En. de 2022
thank you and then how would i add the battleships
How fancy do you want to get?
Most people just turn some of the squares a different color, by changing the image data.
h = image([0.5 5.5], [0.5 5.5], ones(6,6,3));
xticks(0:6); xticklabels([]);
yticks(0:6); yticklabels([]);
grid on
text(0.5:5.5, 6.5*ones(1,6), string(1:6).')
text(-0.5*ones(1,6), 0.5:5.5, string(1:6).')
s = randi(4);
r = randi(6); c = randi(6-s+1);
h.CData(r, c:c+s-1, 1) = 1;
h.CData(r, c:c+s-1, 2) = 0;
h.CData(r, c:c+s-1, 3) = 0;
Aman Kumar
Aman Kumar el 9 de En. de 2022
Thank you, I think what you sent just changing the colour of the squares is the best. Do you know how to make it so that the player gets turns to shoot and each turn only has 3 hits
turn = 0;
while true
turn = turn + 1;
player1_active = mod(turn, 2) == 1;
for shot = 1 : 3
and so on
end
end

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Board games en Centro de ayuda y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by