returning to the start of the game
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
James Webber
el 6 de En. de 2022
Respondida: Harikrishnan Balachandran Nair
el 24 de En. de 2022
i am writting the code for battleships and there is a section that if yuo answer no then it should take you back to the beginging however this does not work for me and it finishes the progam.
the whole code is withing a while loop which works, but for some reasson when i hit no it does not go back to the start.
this is what it looks like
s=input ('would you like to see the game stastics 1,yes 2,no:')
switch s
case 1
num_player = 20;
WLT = zeros(num_player,3);
%disp stastics
if have_a_winner
WLT(winner_index,1) = WLT(winner_index,1) + 1;
WLT(loser_index,2) = WLT(loser_index,2) + 1;
else
WLT(player1_index,3) = WLT(player1_index,3) + 1;
WLT(player2_index,3) = WLT(player2_index,3) + 1;
end
case 2
disp('main menu')
playOn = false;
break
end
case 1 works however case 2 chould go back to the beginging but it does not, any ideas on how to fix this
1 comentario
Respuestas (1)
Harikrishnan Balachandran Nair
el 24 de En. de 2022
Hi,
It is my understanding that you have a switch case inside a while loop , and the loop is being terminated on executing the 'break' statement.
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!